diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-04 10:33:29 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-04 10:33:29 +0200 |
commit | 38a986995a82c6484d677f56ffd68bafcc5398c3 (patch) | |
tree | c70e698a8fbd76f01b84d1163e17329833d6d14e /lib/output/website/prepareResources.js | |
parent | 5d11641a5f4ff607068d871f48a842ecc1d65bf1 (diff) | |
parent | ee8d35df7a26a130a48cdbddd55a26b354378682 (diff) | |
download | gitbook-38a986995a82c6484d677f56ffd68bafcc5398c3.zip gitbook-38a986995a82c6484d677f56ffd68bafcc5398c3.tar.gz gitbook-38a986995a82c6484d677f56ffd68bafcc5398c3.tar.bz2 |
Merge pull request #1264 from GitbookIO/fix/plugin-resources
Fix Loading plugin resources
Diffstat (limited to 'lib/output/website/prepareResources.js')
-rw-r--r-- | lib/output/website/prepareResources.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/output/website/prepareResources.js b/lib/output/website/prepareResources.js new file mode 100644 index 0000000..4e6835d --- /dev/null +++ b/lib/output/website/prepareResources.js @@ -0,0 +1,54 @@ +var is = require('is'); +var Immutable = require('immutable'); +var Promise = require('../../utils/promise'); + +var Api = require('../../api'); + +/** + Prepare plugins resources, add all output corresponding type resources + + @param {Output} + @return {Promise<Output>} +*/ +function prepareResources(output) { + var plugins = output.getPlugins(); + var options = output.getOptions(); + var type = options.get('prefix'); + var state = output.getState(); + var context = Api.encodeGlobal(output); + + var result = Immutable.Map(); + + return Promise.forEach(plugins, function(plugin) { + var pluginResources = plugin.getResources(type); + + return Promise() + .then(function() { + // Apply resources if is a function + if (is.fn(pluginResources)) { + return Promise() + .then(pluginResources.bind(context)); + } + else { + return pluginResources; + } + }) + .then(function(resources) { + result = result.set(plugin.getName(), Immutable.Map(resources)); + }); + }) + .then(function() { + // Set output resources + state = state.merge({ + resources: result + }); + + output = output.merge({ + state: state + }); + + return output; + }); +} + +module.exports = prepareResources;
\ No newline at end of file |