diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-10-13 13:56:46 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-10-13 13:56:46 +0200 |
commit | df5d27ab6103389294795a7fada76d46f36fc00f (patch) | |
tree | b5ce91ae52573db8574a5aa7a2bb9780a7c4d0a0 /lib/pluginslist.js | |
parent | 2870155c0b3b91efc2a4d3fe2e1edd5a1be9ae8a (diff) | |
download | gitbook-df5d27ab6103389294795a7fada76d46f36fc00f.zip gitbook-df5d27ab6103389294795a7fada76d46f36fc00f.tar.gz gitbook-df5d27ab6103389294795a7fada76d46f36fc00f.tar.bz2 |
Use jsonschema to valid and default plugins config
Diffstat (limited to 'lib/pluginslist.js')
-rw-r--r-- | lib/pluginslist.js | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/lib/pluginslist.js b/lib/pluginslist.js index e4594d6..636eddc 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 = that.book.config.getForPlugin(plugin.name); + return plugin.validateConfig(config); + }) + .then(function(config) { + // Update configuration + that.book.config.getForPlugin(plugin.name, 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 |