mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
seperate sheet and env
This commit is contained in:
@@ -248,7 +248,12 @@ function extractUrlParts(url, baseUrl) {
|
||||
}
|
||||
|
||||
function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
loadFile(sheet, function(e, data, sheet, webInfo, path, env) {
|
||||
|
||||
var env = new less.tree.parseEnv(less);
|
||||
env.mime = sheet.type;
|
||||
env.currentFileInfo = null;
|
||||
|
||||
loadFile(sheet, env, function(e, data, sheet, webInfo, path, env) {
|
||||
if (webInfo) {
|
||||
webInfo.remaining = remaining;
|
||||
}
|
||||
@@ -268,7 +273,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
}, reload);
|
||||
}
|
||||
|
||||
function loadFile(sheet, callback, reload) {
|
||||
function loadFile(sheet, env, callback, reload) {
|
||||
|
||||
// sheet may be set to the stylesheet for the initial load or a collection of properties including
|
||||
// some env variables for imports
|
||||
@@ -277,21 +282,18 @@ function loadFile(sheet, callback, reload) {
|
||||
var css = cache && cache.getItem(href);
|
||||
var timestamp = cache && cache.getItem(href + ':timestamp');
|
||||
var styles = { css: css, timestamp: timestamp };
|
||||
var env;
|
||||
var newFileInfo = {
|
||||
relativeUrls: less.relativeUrls,
|
||||
currentDirectory: hrefParts.path,
|
||||
filename: href
|
||||
};
|
||||
|
||||
if (sheet instanceof less.tree.parseEnv) {
|
||||
env = new less.tree.parseEnv(sheet);
|
||||
if (env.currentFileInfo) {
|
||||
env = new less.tree.parseEnv(env);
|
||||
newFileInfo.entryPath = env.currentFileInfo.entryPath;
|
||||
newFileInfo.rootpath = env.currentFileInfo.rootpath;
|
||||
newFileInfo.rootFilename = env.currentFileInfo.rootFilename;
|
||||
} else {
|
||||
env = new less.tree.parseEnv(less);
|
||||
env.mime = sheet.type;
|
||||
newFileInfo.entryPath = hrefParts.path;
|
||||
newFileInfo.rootpath = less.rootpath || hrefParts.path;
|
||||
newFileInfo.rootFilename = href;
|
||||
|
||||
@@ -46,14 +46,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
tree.parseEnv.prototype.toSheet = function (path) {
|
||||
var env = new tree.parseEnv(this);
|
||||
env.href = path;
|
||||
//env.title = path;
|
||||
env.type = this.mime;
|
||||
return env;
|
||||
};
|
||||
|
||||
var evalCopyProperties = [
|
||||
'silent', // whether to swallow errors and warnings
|
||||
'verbose', // whether to log more activity
|
||||
|
||||
@@ -113,8 +113,7 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
|
||||
|
||||
function handleDataAndCallCallback(data) {
|
||||
env = new less.tree.parseEnv(env);
|
||||
env.processImports = false;
|
||||
|
||||
|
||||
var j = file.lastIndexOf('/');
|
||||
|
||||
// Pass on an updated rootpath if path of imported file is relative and file
|
||||
|
||||
@@ -100,6 +100,8 @@ less.Parser = function Parser(env) {
|
||||
less.Parser.fileLoader(path, currentFileInfo, function(e, contents, fullPath, env) {
|
||||
if (e) {fileParsedFunc(e); return;}
|
||||
|
||||
env.processImports = false;
|
||||
|
||||
new(less.Parser)(env).parse(contents, function (e, root) {
|
||||
fileParsedFunc(e, root, fullPath);
|
||||
});
|
||||
@@ -1604,14 +1606,11 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
|
||||
if (!/^([a-z-]+:)?\//.test(path) && currentFileInfo.currentDirectory) {
|
||||
path = currentFileInfo.currentDirectory + path;
|
||||
}
|
||||
var sheetEnv = env.toSheet(path);
|
||||
sheetEnv.processImports = false;
|
||||
sheetEnv.currentFileInfo = currentFileInfo;
|
||||
|
||||
// We pass `true` as 3rd argument, to force the reload of the import.
|
||||
// This is so we can get the syntax tree as opposed to just the CSS output,
|
||||
// as we need this to evaluate the current stylesheet.
|
||||
loadFile(sheetEnv,
|
||||
loadFile({href: path, type: env.mime }, env,
|
||||
function (e, data, sheet, webInfo, path, env) {
|
||||
callback(e, data, path, env);
|
||||
}, true);
|
||||
|
||||
Reference in New Issue
Block a user