You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
2.8 KiB

// Generated by CoffeeScript 1.6.2
var BasePlugin, ambi, eachr, extendr, typeChecker,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
extendr = require('extendr');
typeChecker = require('typechecker');
ambi = require('ambi');
eachr = require('eachr');
BasePlugin = (function() {
BasePlugin.prototype.docpad = null;
BasePlugin.prototype.name = null;
BasePlugin.prototype.config = {};
BasePlugin.prototype.instanceConfig = {};
BasePlugin.prototype.priority = 500;
function BasePlugin(opts) {
this.getConfig = __bind(this.getConfig, this);
this.setConfig = __bind(this.setConfig, this);
var config, docpad, me;
me = this;
docpad = opts.docpad, config = opts.config;
this.docpad = docpad;
this.config = extendr.deepClone(this.config);
this.instanceConfig = extendr.deepClone(this.instanceConfig);
this.initialConfig = this.config;
this.setConfig(config);
if (this.isEnabled() === false) {
return this;
}
this.bindEvents();
this;
}
BasePlugin.prototype.setInstanceConfig = function(instanceConfig) {
if (instanceConfig) {
extendr.safeDeepExtendPlainObjects(this.instanceConfig, instanceConfig);
if (this.config) {
extendr.safeDeepExtendPlainObjects(this.config, instanceConfig);
}
}
return this;
};
BasePlugin.prototype.setConfig = function(instanceConfig) {
var configPackages, configsToMerge, docpad, userConfig;
if (instanceConfig == null) {
instanceConfig = null;
}
docpad = this.docpad;
userConfig = this.docpad.config.plugins[this.name];
this.config = this.docpad.config.plugins[this.name] = {};
if (instanceConfig) {
this.setInstanceConfig(instanceConfig);
}
configPackages = [this.initialConfig, userConfig, this.instanceConfig];
configsToMerge = [this.config];
docpad.mergeConfigurations(configPackages, configsToMerge);
return this;
};
BasePlugin.prototype.getConfig = function() {
return this.config;
};
BasePlugin.prototype.bindEvents = function() {
var docpad, events, pluginInstance;
pluginInstance = this;
docpad = this.docpad;
events = docpad.getEvents();
eachr(events, function(eventName) {
var eventHandler;
if (typeChecker.isFunction(pluginInstance[eventName])) {
eventHandler = pluginInstance[eventName];
return docpad.on(eventName, function(opts, next) {
if (pluginInstance.isEnabled() === false) {
return next();
}
return ambi(eventHandler.bind(pluginInstance), opts, next);
});
}
});
return this;
};
BasePlugin.prototype.isEnabled = function() {
return this.config.enabled !== false;
};
return BasePlugin;
})();
module.exports = BasePlugin;