mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
var environment = function(externalEnvironment, fileManagers) {
|
|
this.fileManagers = fileManagers || [];
|
|
externalEnvironment = externalEnvironment || {};
|
|
|
|
var optionalFunctions = ["encodeBase64", "mimeLookup", "charsetLookup", "getSourceMapGenerator"],
|
|
requiredFunctions = [],
|
|
functions = requiredFunctions.concat(optionalFunctions);
|
|
|
|
for(var i = 0; i < functions.length; i++) {
|
|
var propName = functions[i],
|
|
environmentFunc = externalEnvironment[propName];
|
|
if (environmentFunc) {
|
|
this[propName] = environmentFunc.bind(externalEnvironment);
|
|
} else if (i < requiredFunctions.length) {
|
|
this.warn("missing required function in environment - " + propName);
|
|
}
|
|
}
|
|
};
|
|
|
|
environment.prototype.getFileManager = function (filename, currentDirectory, options, environment, isSync) {
|
|
var fileManagers = this.fileManagers;
|
|
if (options.pluginManager) {
|
|
fileManagers = [].concat(fileManagers).concat(options.pluginManager.getFileManagers());
|
|
}
|
|
for(var i = fileManagers.length - 1; i >= 0 ; i--) {
|
|
var fileManager = fileManagers[i];
|
|
if (fileManager[isSync ? "supportsSync" : "supports"](filename, currentDirectory, options, environment)) {
|
|
return fileManager;
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
|
|
environment.prototype.addFileManager = function (fileManager) {
|
|
this.fileManagers.push(fileManager);
|
|
};
|
|
|
|
environment.prototype.clearFileManagers = function () {
|
|
this.fileManagers = [];
|
|
};
|
|
|
|
module.exports = environment;
|