[Pkg-javascript-commits] [less.js] 119/285: Add first draft post-processors, fix render function when using callback. remove regex compression (not compatible with sourcemaps)
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.0.0
in repository less.js.
commit 4927bf1665f2ae71cb06e11d5995e1e71befef28
Author: Luke Page <luke.a.page at gmail.com>
Date: Fri Sep 12 14:54:30 2014 +0100
Add first draft post-processors, fix render function when using callback. remove regex compression (not compatible with sourcemaps)
---
lib/less/parse-tree.js | 12 ++++++++----
lib/less/plugin-manager.js | 22 ++++++++++++++++++++++
lib/less/render.js | 11 ++++++-----
3 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/lib/less/parse-tree.js b/lib/less/parse-tree.js
index 1ae303f..b7531b8 100644
--- a/lib/less/parse-tree.js
+++ b/lib/less/parse-tree.js
@@ -45,11 +45,15 @@ ParseTree.prototype.toCSS = function(options) {
throw new LessError(e, this.imports);
}
- if (options.compress) {
- return css.replace(/(^(\s)+)|((\s)+$)/g, "");
- } else {
- return css;
+ if (options.plugins) {
+ var postProcessors = options.plugins.getPostProcessors();
+ for(var i = 0; i < postProcessors.length; i++) {
+ // TODO - pass source maps
+ // TODO - async
+ css = postProcessors.process(css);
+ }
}
+ return css;
};
return ParseTree;
};
diff --git a/lib/less/plugin-manager.js b/lib/less/plugin-manager.js
index c4be752..38bdb96 100644
--- a/lib/less/plugin-manager.js
+++ b/lib/less/plugin-manager.js
@@ -4,6 +4,7 @@
var PluginManager = function(less) {
this.less = less;
this.visitors = [];
+ this.postProcessors = [];
};
PluginManager.prototype.addPlugin = function(plugin) {
plugin.install(this.less, this);
@@ -11,6 +12,27 @@ PluginManager.prototype.addPlugin = function(plugin) {
PluginManager.prototype.addVisitor = function(visitor) {
this.visitors.push(visitor);
};
+/**
+ * Adds a post processor object
+ * @param {object} postProcessor
+ * @param {number} priority - guidelines 1 = before compression, 1000 = compression, 2000 = after compression
+ */
+PluginManager.prototype.addPostProcessor = function(postProcessor, priority) {
+ var indexToInsertAt;
+ for(indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
+ if (this.postProcessors[indexToInsertAt].priority >= priority) {
+ break;
+ }
+ }
+ this.postProcessors.splice(indexToInsertAt, 0, {postProcessor: postProcessor, priority: priority});
+};
+PluginManager.prototype.getPostProcessors = function() {
+ var postProcessors = [];
+ for(var i = 0; i < this.postProcessors.length; i++) {
+ postProcessors.push(this.postProcessors[i].postProcessor);
+ }
+ return postProcessors;
+};
PluginManager.prototype.getVisitors = function() {
return this.visitors;
};
diff --git a/lib/less/render.js b/lib/less/render.js
index 1691207..dde6eb8 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -3,9 +3,9 @@ var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : P
getImportManager = require("./imports"),
Parser = require('./parser/parser');
-var render = function(environment) {
+module.exports = function(environment) {
var ParseTree = require("./parse-tree")(environment);
- return function (input, options, callback) {
+ var render = function (input, options, callback) {
options = options || {};
if (typeof(options) === 'function') {
@@ -14,7 +14,7 @@ var render = function(environment) {
}
if (callback) {
- render(input.options)
+ render(input, options)
.then(function(css) {
callback(null, css);
},
@@ -32,12 +32,13 @@ var render = function(environment) {
if (e) { return reject(e); }
try {
var parseTree = new ParseTree(root, imports);
- resolve(parseTree.toCSS(options));
+ var css = parseTree.toCSS(options);
+ resolve(css);
}
catch (err) { reject( err); }
}, options);
});
}
};
+ return render;
};
-module.exports = 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