diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-07-29 23:45:54 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-07-29 23:45:54 -0700 |
commit | 9f241457bb359af4768e5dbc0c1166b5c92942fe (patch) | |
tree | f912a5ead2b4cda71a1645e050991a8c15780f19 | |
parent | 60a7c28e66c77cd93fd5c60fdea5d0bb07b92b52 (diff) | |
download | gitbook-9f241457bb359af4768e5dbc0c1166b5c92942fe.zip gitbook-9f241457bb359af4768e5dbc0c1166b5c92942fe.tar.gz gitbook-9f241457bb359af4768e5dbc0c1166b5c92942fe.tar.bz2 |
Fix minor issues with new plugin additions
-rw-r--r-- | lib/generate/plugin.js | 46 | ||||
-rw-r--r-- | lib/generate/site/index.js | 6 |
2 files changed, 32 insertions, 20 deletions
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js index cf24bc0..ff94483 100644 --- a/lib/generate/plugin.js +++ b/lib/generate/plugin.js @@ -115,18 +115,20 @@ Plugin.prototype.callHook = function(name, data) { }); }; -// Has assets -Plugin.prototype.hasAssets = function(out) { - return (this.infos.book && this.infos.book.assets); -}; - // Copy plugin assets fodler Plugin.prototype.copyAssets = function(out) { - if (!this.hasAssets()) return Q(); - return fs.copy( - this.resolveFile(this.infos.book.assets), - out - ); + var that = this; + + return this.getResources().get('assets') + .then(function(assets) { + // Assets are undefined + if(!assets) return false; + + return fs.copy( + that.resolveFile(assets), + out + ).then(_.constant(true)); + }, _.constant(false)); }; @@ -163,6 +165,7 @@ Plugin.normalizeNames = function(names) { // Extract data from a list of plugin Plugin.fromList = function(names, root, generator) { + var that = this; var failed = []; // Load plugins @@ -174,6 +177,9 @@ Plugin.fromList = function(names, root, generator) { if (_.size(failed) > 0) return Q.reject(new Error("Error loading plugins: "+failed.join(","))); + // The raw resources extracted from each plugin + var pluginResources; + // Get resources of plugins return Q.all(_.map(plugins, function(plugin) { return plugin.getResources(); @@ -181,15 +187,21 @@ Plugin.fromList = function(names, root, generator) { // Extract resources out // css, js, etc ... .then(function(resources) { + pluginResources = resources; // Group by resource types return _.chain(RESOURCES) .map(function(resourceType) { // Get resources from all the plugins for this current type - return _.chain(resources) - .pluck(resourceType) - .compact() - .flatten() - .value(); + return [ + // Key + resourceType, + // Value + _.chain(resources) + .pluck(resourceType) + .compact() + .flatten() + .value() + ]; }) .object() .value(); @@ -197,8 +209,8 @@ Plugin.fromList = function(names, root, generator) { // Extract html snippets .then(function(resources) { // Map of html resources by name added by each plugin - resources.html = plugins.reduce(function(accu, plugin) { - var html = plugin.infos.book.html || {}; + 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); diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index dcc48d7..bd1da53 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -198,11 +198,11 @@ Generator.prototype.copyAssets = function() { .then(function() { return Q.all( _.map(that.plugins.list, function(plugin) { - if (!plugin.hasAssets()) return Q(); - var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name); return plugin.copyAssets(pluginAssets) - .then(function() { + .then(function(copiedStuff) { + // Nothing was copied + if(!copiedStuff) return; return that.manifest.addFolder(pluginAssets, "gitbook/plugins/"+plugin.name); }); }) |