Files
less.js/lib/less/plugin-manager.js
2014-10-09 17:11:47 +01:00

64 lines
1.7 KiB
JavaScript

/**
* Plugin Manager
*/
var PluginManager = function(less) {
this.less = less;
this.visitors = [];
this.postProcessors = [];
this.installedPlugins = [];
};
PluginManager.prototype.addPlugin = function(plugin, options) {
this.installedPlugins.push(plugin);
plugin.install(this.less, this, options);
};
/**
* Adds a visitor. The visitor object has options on itself to determine
* when it should run.
* @param visitor
*/
PluginManager.prototype.addVisitor = function(visitor) {
this.visitors.push(visitor);
};
/**
* Adds a post processor object
* @param {object} postProcessor
* @param {number} priority - guidelines 1 = before compression, 1000 = compression, 2000 = after compression
*/
PluginManager.prototype.addPostProcessor = function(postProcessor, priority) {
var indexToInsertAt;
for(indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
if (this.postProcessors[indexToInsertAt].priority >= priority) {
break;
}
}
this.postProcessors.splice(indexToInsertAt, 0, {postProcessor: postProcessor, priority: priority});
};
/**
* Adds a file manager
* @param manager
*/
PluginManager.prototype.addFileManager = function(manager) {
// TODO
};
/**
* Gets all post processors
* @returns {Array}
* @private
*/
PluginManager.prototype.getPostProcessors = function() {
var postProcessors = [];
for(var i = 0; i < this.postProcessors.length; i++) {
postProcessors.push(this.postProcessors[i].postProcessor);
}
return postProcessors;
};
/**
* Get all visitors
* @returns {Array}
* @private
*/
PluginManager.prototype.getVisitors = function() {
return this.visitors;
};
module.exports = PluginManager;