diff options
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; |