added render() convenience method. Returns an EventEmitter if no callback was passed.

This commit is contained in:
cloudhead 2010-03-22 21:34:05 -04:00
parent 259a4ad451
commit a349b9b3fb

View File

@ -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',