added render() convenience method. Returns an EventEmitter if no callback was passed.
This commit is contained in:
parent
259a4ad451
commit
a349b9b3fb
28
lib/less.js
28
lib/less.js
@ -7,7 +7,33 @@ var less = {
|
||||
version: [2, 0, 0],
|
||||
Parser: require('less/parser').Parser,
|
||||
importer: require('less/parser').importer,
|
||||
tree: require('less/tree')
|
||||
tree: require('less/tree'),
|
||||
render: function (input, options, callback) {
|
||||
options = options || {};
|
||||
|
||||
if (typeof(options) === 'function') {
|
||||
callback = options, options = {};
|
||||
}
|
||||
|
||||
var parser = new(this.Parser)(options),
|
||||
ee;
|
||||
|
||||
if (callback) {
|
||||
parser.parse(input, function (e, root) {
|
||||
callback(e, root.toCSS());
|
||||
});
|
||||
} else {
|
||||
ee = new(require('events').EventEmitter);
|
||||
|
||||
process.nextTick(function () {
|
||||
parser.parse(input, function (e, root) {
|
||||
if (e) { ee.emit('error', e) }
|
||||
else { ee.emit('success', root.toCSS()) }
|
||||
});
|
||||
});
|
||||
return ee;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
['color', 'directive', 'operation', 'dimension',
|
||||
|
Loading…
Reference in New Issue
Block a user