refactoring - add a env type to better organise its properties

This commit is contained in:
Luke Page
2013-01-23 19:07:05 +00:00
parent 26d35c98fe
commit e45ec8a31e
6 changed files with 110 additions and 87 deletions

View File

@@ -103,10 +103,11 @@ less.Parser.importer = function (file, paths, callback, env) {
var pathname, dirname, data;
function parseFile(e, data) {
if (e) return callback(e);
if (e) { return callback(e); }
env = new less.tree.parseEnv(env);
var rootpath = env.rootpath,
j = file.lastIndexOf('/');
var j = file.lastIndexOf('/');
// Pass on an updated rootpath if path of imported file is relative and file
// is in a (sub|sup) directory
@@ -117,20 +118,13 @@ less.Parser.importer = function (file, paths, callback, env) {
// - If path of imported file is '../mixins.less' and rootpath is 'less/',
// then rootpath should become 'less/../'
if(env.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
rootpath = rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
env.rootpath = env.rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
}
env.contents[pathname] = data; // Updating top importing parser content cache.
new(less.Parser)({
paths: [dirname].concat(paths),
filename: pathname,
contents: env.contents,
files: env.files,
syncImport: env.syncImport,
relativeUrls: env.relativeUrls,
rootpath: rootpath,
dumpLineNumbers: env.dumpLineNumbers
}).parse(data, function (e, root) {
env.paths = [dirname].concat(paths);
env.filename = pathname;
new(less.Parser)(env).parse(data, function (e, root) {
callback(e, root, pathname);
});
};
@@ -213,6 +207,7 @@ less.Parser.importer = function (file, paths, callback, env) {
}
}
require('./env');
require('./functions');
require('./colors');