Files
less.js/lib/less/plugin-manager.js
2014-09-17 15:09:04 +01:00

40 lines
1.3 KiB
JavaScript

/**
* Plugin Manager
*/
var PluginManager = function(less) {
this.less = less;
this.visitors = [];
this.postProcessors = [];
};
PluginManager.prototype.addPlugin = function(plugin, options) {
plugin.install(this.less, this, options);
};
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});
};
PluginManager.prototype.getPostProcessors = function() {
var postProcessors = [];
for(var i = 0; i < this.postProcessors.length; i++) {
postProcessors.push(this.postProcessors[i].postProcessor);
}
return postProcessors;
};
PluginManager.prototype.getVisitors = function() {
return this.visitors;
};
module.exports = PluginManager;