diff options
Diffstat (limited to 'lib/plugins/plugin.js')
-rw-r--r-- | lib/plugins/plugin.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index c262887..0fbbab1 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -266,12 +266,39 @@ BookPlugin.prototype.getResources = function(base) { // Normalize filters and return them BookPlugin.prototype.getFilters = function() { - return this.content.filters || {}; + var that = this; + + return _.mapValues(this.content.filters || {}, function(fn, filter) { + return function() { + var ctx = _.extend( + this, + pluginCtx(that) + ); + + return fn.apply(ctx, arguments); + }; + }); }; // Normalize blocks and return them BookPlugin.prototype.getBlocks = function() { - return this.content.blocks || {}; + var that = this; + + return _.mapValues(this.content.blocks || {}, function(block, blockName) { + block = _.isFunction(block)? { exec: block } : block; + + var fn = block.exec; + block.exec = function() { + var ctx = _.extend( + this, + pluginCtx(that) + ); + + return fn.apply(ctx, arguments); + }; + + return block; + }); }; module.exports = BookPlugin; |