mirror of
https://github.com/less/less.js.git
synced 2026-01-22 05:37:56 -05:00
- Limited @import (plugin) support to add/addMultiple of functions - Altered @import (plugin) loading to support browser - Support proper closure scoping of @import (plugin) loaded functions
36 lines
1004 B
JavaScript
36 lines
1004 B
JavaScript
var LessError = require('../less-error'),
|
|
tree = require("../tree");
|
|
|
|
var FunctionImporter = module.exports = function FunctionImporter(context, fileInfo) {
|
|
this.fileInfo = fileInfo;
|
|
};
|
|
|
|
FunctionImporter.prototype.eval = function(contents, callback) {
|
|
var loaded = {},
|
|
loader,
|
|
registry;
|
|
|
|
registry = {
|
|
add: function(name, func) {
|
|
loaded[name] = func;
|
|
},
|
|
addMultiple: function(functions) {
|
|
Object.keys(functions).forEach(function(name) {
|
|
loaded[name] = functions[name];
|
|
});
|
|
}
|
|
};
|
|
|
|
try {
|
|
loader = new Function("functions", "tree", "fileInfo", contents);
|
|
loader(registry, tree, this.fileInfo);
|
|
} catch(e) {
|
|
callback(new LessError({
|
|
message: "Plugin evaluation error: '" + e.name + ': ' + e.message.replace(/["]/g, "'") + "'" ,
|
|
filename: this.fileInfo.filename
|
|
}), null );
|
|
}
|
|
|
|
callback(null, { functions: loaded });
|
|
};
|