Sha256: 2e2400407dccb04b0d64484b0536ac75eb677191d8453a7e655e4e89475cc0c6

Contents?: true

Size: 1004 Bytes

Versions: 5

Compression:

Stored size: 1004 Bytes

Contents

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 });
};

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ilog-0.4.1 node_modules/less/lib/less/plugins/function-importer.js
ilog-0.4.0 node_modules/less/lib/less/plugins/function-importer.js
ilog-0.3.3 node_modules/less/lib/less/plugins/function-importer.js
less-execjs-2.6.0.4 lib/less/js/less/lib/less/plugins/function-importer.js
less-execjs-2.6.0.3 lib/less/js/less/lib/less/plugins/function-importer.js