diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 17:32:59 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-19 17:32:59 +0100 |
commit | 2dbf9b0d4a88a6461ca60f49f3d66ccd42143be3 (patch) | |
tree | 136b4674ef40a301a3c39cb23297cf969086d425 /lib/book.js | |
parent | be4d2679a4daf885a470b5f89e8e6488b0c7a820 (diff) | |
download | gitbook-2dbf9b0d4a88a6461ca60f49f3d66ccd42143be3.zip gitbook-2dbf9b0d4a88a6461ca60f49f3d66ccd42143be3.tar.gz gitbook-2dbf9b0d4a88a6461ca60f49f3d66ccd42143be3.tar.bz2 |
Start adapting json generator
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/book.js b/lib/book.js index 73f3847..435e05c 100644 --- a/lib/book.js +++ b/lib/book.js @@ -107,27 +107,34 @@ Book.prototype.parse = function() { }; // Generate the output -Book.prototype.generate = function() { +Book.prototype.generate = function(generator) { var that = this, generator; - if (that.isMultilingual()) return that.generateMultiLingual(); - return Q() // Clean output folder .then(function() { return fs.remove(that.options.output); }) + .then(function() { + return fs.mkdirp(that.options.output); + }) // Create generator .then(function() { - Generator = generators[that.options.generator]; - if (!Generator) throw "Generator '"+that.options.generator+"' doesn't exist"; + generator = generator || that.options.generator; + var Generator = generators[generator]; + if (!Generator) throw "Generator '"+generator+"' doesn't exist"; + generator = new Generator(that); + }) + + .then(function() { + if (that.isMultilingual()) return that.generateMultiLingual(generator); }); }; // Generate the output for a multilingual book -Book.prototype.generateMultiLingual = function() { +Book.prototype.generateMultiLingual = function(generator) { var that = this; return Q() @@ -287,9 +294,15 @@ Book.prototype.listAllFiles = function() { }); }; -// Retrun true if the book is a multilingual book +// Return true if the book is a multilingual book Book.prototype.isMultilingual = function(filename) { return this.books.length > 0; }; +// Return root of the parent +Book.prototype.parentRoot = function() { + if (this.parent) return this.parent.parentRoot(); + return this.root; +}; + module.exports= Book; |