summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-03-09 16:45:27 +0100
committerSamy Pessé <samypesse@gmail.com>2016-03-09 16:45:27 +0100
commit0d367da776a396d635c02a412bd4b980e9b15a12 (patch)
treec8f13b4b69301590fd47d5f9cab23306a92dbf0b /lib
parentc499a8a13a3059e3953727866beb7c986e46dd78 (diff)
downloadgitbook-0d367da776a396d635c02a412bd4b980e9b15a12.zip
gitbook-0d367da776a396d635c02a412bd4b980e9b15a12.tar.gz
gitbook-0d367da776a396d635c02a412bd4b980e9b15a12.tar.bz2
Use complete list of plugins for templates resolution / i18n / assets
Diffstat (limited to 'lib')
-rw-r--r--lib/output/json.js1
-rw-r--r--lib/output/website.js47
-rw-r--r--lib/plugins/index.js5
3 files changed, 13 insertions, 40 deletions
diff --git a/lib/output/json.js b/lib/output/json.js
index b66e593..7061141 100644
--- a/lib/output/json.js
+++ b/lib/output/json.js
@@ -1,4 +1,3 @@
-var _ = require('lodash');
var conrefsLoader = require('./conrefs');
var JSONOutput = conrefsLoader();
diff --git a/lib/output/website.js b/lib/output/website.js
index e298b69..9c20670 100644
--- a/lib/output/website.js
+++ b/lib/output/website.js
@@ -57,32 +57,11 @@ WebsiteOutput.prototype.prepare = function() {
})
.then(function() {
- var themeName = that.book.config.get('theme');
- that.theme = that.plugins.get(themeID(themeName));
- that.themeDefault = that.plugins.get(themeID('default'));
-
- if (!that.theme) {
- throw new Error('Theme "' + themeName + '" is not installed, add "' + themeID(themeName) + '" to your "book.json"');
- }
-
- if (that.themeDefault.root != that.theme.root) {
- that.log.info.ln('build using theme "' + themeName + '"');
- }
-
// This list is ordered to give priority to templates in the book
- var searchPaths = _.chain([
- // The book itself can contains a "_layouts" folder
- that.book.root,
-
- // Installed plugin (it can be identical to themeDefault.root)
- that.theme.root,
+ var searchPaths = _.pluck(this.plugins.list(), 'root');
- // Is default theme still installed
- that.themeDefault? that.themeDefault.root : null
- ])
- .compact()
- .uniq()
- .value();
+ // The book itself can contains a "_layouts" folder
+ searchPaths.unshift(that.book.root);
// Load i18n
_.each(searchPaths.concat().reverse(), function(searchPath) {
@@ -142,21 +121,11 @@ WebsiteOutput.prototype.prepare = function() {
.then(function() {
if (that.book.isLanguageBook()) return;
- return Promise.serie([
- // Assets from the book are already copied
- // The order is reversed from the template's one
-
- // Is default theme still installed
- that.themeDefault && that.themeDefault.root != that.theme.root?
- that.themeDefault.root : null,
-
- // Installed plugin (it can be identical to themeDefault.root)
- that.theme.root
- ], function(folder) {
- if (!folder) return;
-
+ // Assets from the book are already copied
+ // Copy assets from plugins
+ return Promise.serie(that.plugins.list(), function(plugin) {
// Copy assets only if exists (don't fail otherwise)
- var assetFolder = path.join(folder, '_assets', that.name);
+ var assetFolder = path.join(plugin.root, '_assets', that.name);
if (!fs.existsSync(assetFolder)) return;
that.log.debug.ln('copy assets from theme', assetFolder);
@@ -164,7 +133,7 @@ WebsiteOutput.prototype.prepare = function() {
assetFolder,
that.resolve('gitbook'),
{
- deleteFirst: false, // Delete "to" before
+ deleteFirst: false,
overwrite: true,
confirm: true
}
diff --git a/lib/plugins/index.js b/lib/plugins/index.js
index 8280542..88762c6 100644
--- a/lib/plugins/index.js
+++ b/lib/plugins/index.js
@@ -21,6 +21,11 @@ function PluginsManager(book) {
_.bindAll(this);
}
+// Returns the list of plugins
+PluginsManager.prototype.list = function() {
+ return this.plugins;
+};
+
// Return count of plugins loaded
PluginsManager.prototype.count = function() {
return _.size(this.plugins);