diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-22 14:50:55 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-22 14:50:55 +0100 |
commit | 642ba72a1d0680107357083a79560c2ccc931457 (patch) | |
tree | 34be30a7b84da734703093391483a727d4f19964 /lib/plugins/plugin.js | |
parent | 71144db09c150f6499d977863dbccf12ce05638b (diff) | |
download | gitbook-642ba72a1d0680107357083a79560c2ccc931457.zip gitbook-642ba72a1d0680107357083a79560c2ccc931457.tar.gz gitbook-642ba72a1d0680107357083a79560c2ccc931457.tar.bz2 |
Load all filters and blocks from plugins in output's template
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; |