diff options
-rw-r--r-- | lib/book.js | 12 | ||||
-rw-r--r-- | lib/generators/json.js | 13 | ||||
-rw-r--r-- | test/generation.js | 12 |
3 files changed, 25 insertions, 12 deletions
diff --git a/lib/book.js b/lib/book.js index 3ad302a..19b5f43 100644 --- a/lib/book.js +++ b/lib/book.js @@ -108,7 +108,8 @@ Book.prototype.parse = function() { // Generate the output Book.prototype.generate = function(generator) { - var that = this, generator; + var that = this; + that.options.generator = generator || that.options.generator; return Q() @@ -122,14 +123,14 @@ Book.prototype.generate = function(generator) { // Create generator .then(function() { - generator = generator || that.options.generator; var Generator = generators[generator]; - if (!Generator) throw "Generator '"+generator+"' doesn't exist"; + if (!Generator) throw "Generator '"+that.options.generator+"' doesn't exist"; generator = new Generator(that); return generator.load(); }) + // Generate content .then(function() { if (that.isMultilingual()) { return that.generateMultiLingual(generator); @@ -177,9 +178,12 @@ Book.prototype.generateMultiLingual = function(generator) { // Generate sub-books return _.reduce(that.books, function(prev, book) { return prev.then(function() { - return book.generate(); + return book.generate(that.options.generator); }); }, Q()); + }) + .then(function() { + return generator.langsIndex(that.langs); }); }; diff --git a/lib/generators/json.js b/lib/generators/json.js index 3023b42..02a0536 100644 --- a/lib/generators/json.js +++ b/lib/generators/json.js @@ -12,7 +12,7 @@ var Generator = function() { }; util.inherits(Generator, BaseGenerator); -// Ignore soem methods +// Ignore some methods Generator.prototype.transferFile = function(input) { }; Generator.prototype.finish = function() { }; @@ -35,13 +35,12 @@ Generator.prototype.writeParsedFile = function(page, input) { // Generate languages index // Contains the first languages readme and langs infos -/*Generator.prototype.langsIndex = function(langs) { +Generator.prototype.langsIndex = function(langs) { var that = this; - if (langs.list.length == 0) return Q.reject("Need at least one language"); + if (langs.length == 0) return Q.reject("Need at least one language"); - var mainLang = _.first(langs.list).lang; - console.log("Main language is", mainLang); + var mainLang = _.first(langs).lang; return Q() .then(function() { @@ -52,7 +51,7 @@ Generator.prototype.writeParsedFile = function(page, input) { .then(function(content) { var json = JSON.parse(content); _.extend(json, { - langs: langs.list + langs: langs }); return fs.writeFile( @@ -60,6 +59,6 @@ Generator.prototype.writeParsedFile = function(page, input) { JSON.stringify(json, null, 4) ); }); -};*/ +}; module.exports = Generator; diff --git a/test/generation.js b/test/generation.js index 4176c8a..6bfb095 100644 --- a/test/generation.js +++ b/test/generation.js @@ -5,7 +5,7 @@ var assert = require('assert'); var fs = require('../lib/utils/fs'); describe('Book generation', function () { - it('should correctly generate a book with json', function(done) { + it('should correctly generate a book to json', function(done) { var OUTPUT_PATH = book1.options.output; qdone( @@ -14,4 +14,14 @@ describe('Book generation', function () { return fs.remove(OUTPUT_PATH); }), done); }); + + it('should correctly generate a multilingual book to json', function(done) { + var OUTPUT_PATH = book2.options.output; + + qdone( + book2.generate("json") + .fin(function() { + return fs.remove(OUTPUT_PATH); + }), done); + }); }); |