[Pkg-javascript-commits] [less.js] 01/38: Expose Less parsing as a top level feature of the less package Converting a Less stylesheet into an AST is a valuable piece of functionality, and worthy of being easily accessible to consumers of less.js.
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:27:23 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.2.0
in repository less.js.
commit cf54e01743a92ec05767edcd2dd5352ec5a0d9c6
Author: jackwanders <jack at webs.com>
Date: Mon Dec 1 19:37:13 2014 -0500
Expose Less parsing as a top level feature of the less package
Converting a Less stylesheet into an AST is a valuable piece of
functionality, and worthy of being easily accessible to consumers
of less.js.
---
lib/less/index.js | 1 +
lib/less/{render.js => parse.js} | 14 ++++---------
lib/less/render.js | 43 ++++++++--------------------------------
3 files changed, 13 insertions(+), 45 deletions(-)
diff --git a/lib/less/index.js b/lib/less/index.js
index 51fd54c..226831d 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -17,6 +17,7 @@ module.exports = function(environment, fileManagers) {
ParseTree: (ParseTree = require('./parse-tree')(SourceMapBuilder)),
ImportManager: (ImportManager = require('./import-manager')(environment)),
render: require("./render")(environment, ParseTree, ImportManager),
+ parse: require("./parse")(environment, ParseTree, ImportManager),
LessError: require('./less-error'),
transformTree: require('./transform-tree'),
utils: require('./utils'),
diff --git a/lib/less/render.js b/lib/less/parse.js
similarity index 81%
copy from lib/less/render.js
copy to lib/less/parse.js
index 843ddc4..0991824 100644
--- a/lib/less/render.js
+++ b/lib/less/parse.js
@@ -4,7 +4,7 @@ var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : P
PluginManager = require('./plugin-manager');
module.exports = function(environment, ParseTree, ImportManager) {
- var render = function (input, options, callback) {
+ var parse = function (input, options, callback) {
options = options || {};
if (typeof(options) === 'function') {
@@ -15,7 +15,7 @@ module.exports = function(environment, ParseTree, ImportManager) {
if (!callback) {
var self = this;
return new PromiseConstructor(function (resolve, reject) {
- render.call(self, input, options, function(err, output) {
+ parse.call(self, input, options, function(err, output) {
if (err) {
reject(err);
} else {
@@ -53,15 +53,9 @@ module.exports = function(environment, ParseTree, ImportManager) {
new Parser(context, imports, rootFileInfo)
.parse(input, function (e, root) {
if (e) { return callback(e); }
- var result;
- try {
- var parseTree = new ParseTree(root, imports);
- result = parseTree.toCSS(options);
- }
- catch (err) { return callback( err); }
- callback(null, result);
+ callback(null, root, imports, options);
}, options);
}
};
- return render;
+ return parse;
};
diff --git a/lib/less/render.js b/lib/less/render.js
index 843ddc4..b4565a5 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -1,11 +1,8 @@
-var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
- contexts = require("./contexts"),
- Parser = require('./parser/parser'),
- PluginManager = require('./plugin-manager');
+var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
module.exports = function(environment, ParseTree, ImportManager) {
var render = function (input, options, callback) {
- options = options || {};
+ var parse = require('./parse')(environment, ParseTree, ImportManager);
if (typeof(options) === 'function') {
callback = options;
@@ -24,44 +21,20 @@ module.exports = function(environment, ParseTree, ImportManager) {
});
});
} else {
- var context,
- rootFileInfo,
- pluginManager = new PluginManager(this);
+ parse(input, options, function(err, root, imports, options) {
+ if (err) { return callback(err); }
- pluginManager.addPlugins(options.plugins);
- options.pluginManager = pluginManager;
-
- context = new contexts.Parse(options);
-
- if (options.rootFileInfo) {
- rootFileInfo = options.rootFileInfo;
- } else {
- var filename = options.filename || "input";
- var entryPath = filename.replace(/[^\/\\]*$/, "");
- rootFileInfo = {
- filename: filename,
- relativeUrls: context.relativeUrls,
- rootpath: context.rootpath || "",
- currentDirectory: entryPath,
- entryPath: entryPath,
- rootFilename: filename
- };
- }
-
- var imports = new ImportManager(context, rootFileInfo);
-
- new Parser(context, imports, rootFileInfo)
- .parse(input, function (e, root) {
- if (e) { return callback(e); }
var result;
try {
var parseTree = new ParseTree(root, imports);
result = parseTree.toCSS(options);
}
- catch (err) { return callback( err); }
+ catch (err) { return callback(err); }
+
callback(null, result);
- }, options);
+ });
}
};
+
return render;
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list