summaryrefslogtreecommitdiffstats
path: root/lib/pluginslist.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-10-13 15:14:26 +0200
committerSamy Pessé <samypesse@gmail.com>2015-10-13 15:14:26 +0200
commit8ba18cd587de8f073c9818acbdeaeaafe9a478c1 (patch)
treee83f6a9b6e4a37d2058d11653db73123a799aef0 /lib/pluginslist.js
parent4ae5b2e05001df9bdf8c5b64f8a82725e14d6414 (diff)
parent54c12fea89198ad6582529cf7bfd6c7ff6f92ed2 (diff)
downloadgitbook-8ba18cd587de8f073c9818acbdeaeaafe9a478c1.zip
gitbook-8ba18cd587de8f073c9818acbdeaeaafe9a478c1.tar.gz
gitbook-8ba18cd587de8f073c9818acbdeaeaafe9a478c1.tar.bz2
Merge pull request #979 from GitbookIO/feature/plugins_config
Improvements for plugin configurations
Diffstat (limited to 'lib/pluginslist.js')
-rw-r--r--lib/pluginslist.js56
1 files changed, 34 insertions, 22 deletions
diff --git a/lib/pluginslist.js b/lib/pluginslist.js
index e4594d6..8830950 100644
--- a/lib/pluginslist.js
+++ b/lib/pluginslist.js
@@ -78,34 +78,46 @@ PluginsList.prototype.load = function(plugin) {
that.list.push(plugin);
}
- // Extract filters
- that.book.template.addFilters(plugin.getFilters());
+ return Q()
- // Extract blocks
- that.book.template.addBlocks(plugin.getBlocks());
+ // Validate and normalize configuration
+ .then(function() {
+ var config = plugin.getConfig();
+ return plugin.validateConfig(config);
+ })
+ .then(function(config) {
+ // Update configuration
+ plugin.setConfig(config);
- return _.reduce(_.keys(that.namespaces), function(prev, namespaceName) {
- return prev.then(function() {
- return plugin.getResources(namespaceName)
- .then(function(plResources) {
- var namespace = that.namespaces[namespaceName];
-
- // Extract js and css
- _.each(Plugin.RESOURCES, function(resourceType) {
- namespace.resources[resourceType] = (namespace.resources[resourceType] || []).concat(plResources[resourceType] || []);
- });
+ // Extract filters
+ that.book.template.addFilters(plugin.getFilters());
- // Map of html resources by name added by each plugin
- _.each(plResources.html || {}, function(value, tag) {
- // Turn into function if not one already
- if (!_.isFunction(value)) value = _.constant(value);
+ // Extract blocks
+ that.book.template.addBlocks(plugin.getBlocks());
- namespace.html[tag] = namespace.html[tag] || [];
- namespace.html[tag].push(value);
+ return _.reduce(_.keys(that.namespaces), function(prev, namespaceName) {
+ return prev.then(function() {
+ return plugin.getResources(namespaceName)
+ .then(function(plResources) {
+ var namespace = that.namespaces[namespaceName];
+
+ // Extract js and css
+ _.each(Plugin.RESOURCES, function(resourceType) {
+ namespace.resources[resourceType] = (namespace.resources[resourceType] || []).concat(plResources[resourceType] || []);
+ });
+
+ // Map of html resources by name added by each plugin
+ _.each(plResources.html || {}, function(value, tag) {
+ // Turn into function if not one already
+ if (!_.isFunction(value)) value = _.constant(value);
+
+ namespace.html[tag] = namespace.html[tag] || [];
+ namespace.html[tag].push(value);
+ });
});
});
- });
- }, Q());
+ }, Q());
+ });
};
// Call a hook