summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-19 16:23:44 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-19 16:23:44 +0100
commit7f01f4b048faf5ce5e1815c3676916ac7859279f (patch)
tree98a58abd2c18b3c46fea9987eb3316c1f2c80236 /lib/book.js
parent5ed584449007d9c6c816e765ce3e999e14abbf97 (diff)
downloadgitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.zip
gitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.tar.gz
gitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.tar.bz2
Add plugin object
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js32
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/book.js b/lib/book.js
index 8fbac81..1a8643f 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -5,7 +5,8 @@ var path = require("path");
var fs = require("./utils/fs");
var Configuration = require("./configuration");
var TemplateEngine = require("./template");
-var parser = require("./parser");
+var Plugin = require("./plugin");
+var parsers = require("./parsers");
var Book = function(root, options, parent) {
// Root folder of the book
@@ -39,6 +40,9 @@ var Book = function(root, options, parent) {
// Files in the book
this.files = [];
+
+ // List of plugins
+ this.plugins = {};
};
// Initialize and parse the book: config, summary, glossary
@@ -49,6 +53,10 @@ Book.prototype.parse = function() {
return this.config.load()
.then(function() {
+ return that.parsePlugins();
+ })
+
+ .then(function() {
return that.parseLangs()
.then(function() {
multilingal = that.langs.length > 0;
@@ -124,6 +132,24 @@ Book.prototype.generateMultiLingual = function() {
});
};
+// Parse list of plugins
+Book.prototype.parsePlugins = function() {
+ var that = this;
+ var names = Plugin.normalizeNames(this.options.plugins);
+
+ var failed = [];
+
+ // Load plugins
+ that.plugins = _.map(names, function(name) {
+ var plugin = new Plugin(that, name);
+ if (!plugin.isValid()) failed.push(name);
+ return plugin;
+ });
+
+ if (_.size(failed) > 0) return Q.reject(new Error("Error loading plugins: "+failed.join(",")+". Run 'gitbook install' to install plugins from NPM."));
+ return Q();
+};
+
// Parse readme to extract defaults title and description
Book.prototype.parseReadme = function() {
var that = this;
@@ -205,7 +231,7 @@ Book.prototype.parseGlossary = function() {
Book.prototype.findFile = function(filename) {
var that = this;
- return _.reduce(parser.extensions, function(prev, ext) {
+ return _.reduce(parsers.extensions, function(prev, ext) {
return prev.then(function(output) {
// Stop if already find a parser
if (output) return output;
@@ -216,7 +242,7 @@ Book.prototype.findFile = function(filename) {
.then(function(exists) {
if (!exists) return null;
return {
- parser: parser.get(ext).parser,
+ parser: parsers.get(ext).parser,
path: filepath
};
})