summaryrefslogtreecommitdiffstats
path: root/lib/plugin.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-27 15:22:42 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-27 15:22:42 +0100
commit131c19dee6db956d758ed4a63ee24dbf087a8c7f (patch)
tree9b31f135fb12a105f395f298b7468962559778df /lib/plugin.js
parent870ca4da0c9fa750acba609aff8d129d5a753466 (diff)
downloadgitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.zip
gitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.tar.gz
gitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.tar.bz2
Move plugin helper methods to a specific class
Diffstat (limited to 'lib/plugin.js')
-rw-r--r--lib/plugin.js109
1 files changed, 0 insertions, 109 deletions
diff --git a/lib/plugin.js b/lib/plugin.js
index ec55513..fa38e20 100644
--- a/lib/plugin.js
+++ b/lib/plugin.js
@@ -196,113 +196,4 @@ Plugin.prototype.copyAssets = function(out, options) {
}, _.constant(false));
};
-
-// Extract data from a list of plugin
-Plugin.normalize = function(plugins, options) {
- options = _.defaults(options || {}, {
- assetsBase: "book"
- });
-
- // The raw resources extracted from each plugin
- var pluginResources;
-
- // Map of resources
- var resources = {};
-
- // Map of all filters
- var filters = {};
-
- // Get resources of plugins
- return Q.all(_.map(plugins, function(plugin) {
- return plugin.getResources(options.assetsBase);
- }))
-
- // Extract resources out
- // css, js, etc ...
- .then(function(_resources) {
- pluginResources = _resources;
- })
- .then(function() {
- // Group by resource types
- resources = _.chain(Plugin.RESOURCES)
- .map(function(resourceType) {
- // Get resources from all the plugins for this current type
- return [
- // Key
- resourceType,
-
- // Value
- _.chain(pluginResources)
- .pluck(resourceType)
- .compact()
- .flatten()
- .value()
- ];
- })
- .object()
- .value();
- })
-
- // Extract html snippets
- .then(function() {
- // Map of html resources by name added by each plugin
- resources.html = pluginResources.reduce(function(accu, resource) {
- var html = (resource && resource.html) || {};
- _.each(html, function(code, key) {
- // Turn into function if not one already
- if (!_.isFunction(code)) code = _.constant(code);
- // Append
- accu[key] = (accu[key] || []).concat([code]);
- });
-
- return accu;
- }, {});
- })
-
- // Extract filters
- .then(function() {
- _.each(plugins, function(plugin) {
- _.each(plugin.getFilters(), function(filterFunc, filterName) {
- if (filters[filterName]) {
- plugin.book.log.warn.ln("Conflict in filters, '"+filterName+"' is already set");
- } else {
- filters[filterName] = filterFunc;
- }
- });
- });
- })
-
- // Return big multi-plugins object
- .then(function() {
- return {
- 'list': plugins,
- 'resources': resources,
- 'filters': filters,
- 'hook': function(name, data) {
- return _.reduce(plugins, function(prev, plugin) {
- return prev.then(function(ret) {
- return plugin.callHook(name, ret);
- });
- }, Q(data));
- },
- 'template': function(name) {
- var withTpl = _.find(plugins, function(plugin) {
- return (
- plugin.infos.templates &&
- plugin.infos.templates[name]
- );
- });
-
- if (!withTpl) return null;
- return withTpl.resolveFile(withTpl.infos.templates[name]);
- },
- 'html': function(tag, context, options) {
- return _.map(resources.html[tag] || [], function(code) {
- return code.call(context, options);
- }).join("\n");
- }
- };
- });
-};
-
module.exports = Plugin;