|
|
// Generated by CoffeeScript 1.6.3
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.bindListeners(); 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.addListeners(); 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); if (!this.isEnabled()) { this.removeListeners(); } return this; };
BasePlugin.prototype.getConfig = function() { return this.config; };
BasePlugin.prototype.bindEvents = function() { return this.addListeners(); };
BasePlugin.prototype.bindListeners = function() { var docpad, events, pluginInstance; pluginInstance = this; docpad = this.docpad; events = docpad.getEvents(); eachr(events, function(eventName) { var eventHandler; eventHandler = pluginInstance[eventName]; if (typeChecker.isFunction(eventHandler)) { return pluginInstance[eventName] = eventHandler.bind(pluginInstance); } }); return this; };
BasePlugin.prototype.addListeners = function() { var docpad, events, pluginInstance; pluginInstance = this; docpad = this.docpad; events = docpad.getEvents(); eachr(events, function(eventName) { var eventHandler, eventHandlerPriority; eventHandler = pluginInstance[eventName]; if (typeChecker.isFunction(eventHandler)) { eventHandlerPriority = pluginInstance[eventName + 'Priority'] || pluginInstance.priority || null; eventHandler.priority = eventHandlerPriority; return docpad.off(eventName, eventHandler).on(eventName, eventHandler); } }); return this; };
BasePlugin.prototype.removeListeners = function() { var docpad, events, pluginInstance; pluginInstance = this; docpad = this.docpad; events = docpad.getEvents(); eachr(events, function(eventName) { var eventHandler; eventHandler = pluginInstance[eventName]; if (typeChecker.isFunction(eventHandler)) { return docpad.off(eventName, eventHandler); } }); return this; };
BasePlugin.prototype.isEnabled = function() { return this.config.enabled !== false; };
return BasePlugin;
})();
module.exports = BasePlugin;
|