diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-02-12 12:18:52 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-02-12 12:18:52 +0100 |
commit | 4ad2b040b462ae2f94922e9ad01d7804eb6d79dc (patch) | |
tree | f4703abaf76543d7f484560a5d66e1ee59acf6eb | |
parent | f5916b5c595cc507bee2a56ccfdfc7eb9ecc4281 (diff) | |
download | gitbook-4ad2b040b462ae2f94922e9ad01d7804eb6d79dc.zip gitbook-4ad2b040b462ae2f94922e9ad01d7804eb6d79dc.tar.gz gitbook-4ad2b040b462ae2f94922e9ad01d7804eb6d79dc.tar.bz2 |
Always generate README.json with langs index
remove method langsIndex form generators (moved to finish)
-rw-r--r-- | lib/book.js | 8 | ||||
-rw-r--r-- | lib/generator.js | 5 | ||||
-rw-r--r-- | lib/generators/ebook.js | 5 | ||||
-rw-r--r-- | lib/generators/json.js | 24 | ||||
-rw-r--r-- | lib/generators/website.js | 9 | ||||
-rw-r--r-- | test/json.js | 2 |
6 files changed, 25 insertions, 28 deletions
diff --git a/lib/book.js b/lib/book.js index f5d52e9..650931f 100644 --- a/lib/book.js +++ b/lib/book.js @@ -261,9 +261,6 @@ Book.prototype.generateMultiLingual = function(generator) { return book.generate(that.options.generator); }); }, Q()); - }) - .then(function() { - return generator.langsIndex(that.langs); }); }; @@ -651,6 +648,11 @@ Book.prototype.isSubBook = function() { return !!this.parent; }; +// Test if the file is the entry point +Book.prototype.isEntryPoint = function(fp) { + return fp == this.readmeFile; +}; + // Resolve a path in book Book.prototype.resolve = function(p) { return path.resolve(this.root, p); diff --git a/lib/generator.js b/lib/generator.js index f7f319d..c809de2 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -70,11 +70,6 @@ BaseGenerator.prototype.copyCover = function() { }); }; -// Generate the langs index -BaseGenerator.prototype.langsIndex = function(langs) { - return Q.reject(new Error("Langs index is not supported in this generator")); -}; - // At teh end of the generation BaseGenerator.prototype.finish = function() { return Q.reject(new Error("Could not finish generation")); diff --git a/lib/generators/ebook.js b/lib/generators/ebook.js index eb84df8..ebffa79 100644 --- a/lib/generators/ebook.js +++ b/lib/generators/ebook.js @@ -41,11 +41,6 @@ Generator.prototype.writeSummary = function() { return this._writeTemplate(this.templates["summary"], {}, path.join(this.options.output, "SUMMARY.html")); }; - -Generator.prototype.langsIndex = function(langs) { - return Q(); -}; - Generator.prototype.finish = function() { var that = this; diff --git a/lib/generators/json.js b/lib/generators/json.js index f1af395..6c9439d 100644 --- a/lib/generators/json.js +++ b/lib/generators/json.js @@ -14,7 +14,6 @@ util.inherits(Generator, BaseGenerator); // Ignore some methods Generator.prototype.transferFile = function(input) { }; -Generator.prototype.finish = function() { }; // Convert an input file Generator.prototype.convertFile = function(input) { @@ -37,21 +36,26 @@ Generator.prototype.convertFile = function(input) { }); }; -// Generate languages index -// Contains the first languages readme and langs infos -Generator.prototype.langsIndex = function(langs) { - var that = this; - - if (langs.length == 0) return Q.reject("Need at least one language"); +// Finish generation +Generator.prototype.finish = function() { + return this.writeReadme(); +}; - var mainLang = _.first(langs).lang; - var readme = links.changeExtension(that.book.readmeFile, ".json"); +// Write README.json +Generator.prototype.writeReadme = function() { + var that = this; + var mainlang, langs; return Q() .then(function() { + langs = that.book.langs; + mainLang = langs.length > 0? _.first(langs).lang : null; + + readme = links.changeExtension(that.book.readmeFile, ".json"); + // Read readme from main language return fs.readFile( - path.join(that.options.output, mainLang, readme) + mainLang? path.join(that.options.output, mainLang, readme) : path.join(that.options.output, readme) ); }) .then(function(content) { diff --git a/lib/generators/website.js b/lib/generators/website.js index 01df98c..d40ffa8 100644 --- a/lib/generators/website.js +++ b/lib/generators/website.js @@ -118,7 +118,8 @@ Generator.prototype.finish = function() { return this.copyAssets() .then(this.copyCover) .then(this.writeGlossary) - .then(this.writeSearchIndex); + .then(this.writeSearchIndex) + .then(this.writeLangsIndex) }; // Convert an input file @@ -156,11 +157,11 @@ Generator.prototype.convertFile = function(input) { }; // Write the index for langs -Generator.prototype.langsIndex = function(langs) { +Generator.prototype.writeLangsIndex = function() { var that = this; - + if (!this.book.langs.length) return Q(); return this._writeTemplate(this.templates["langs"], { - langs: langs + langs: this.book.langs }, path.join(this.options.output, "index.html")); }; diff --git a/test/json.js b/test/json.js index b7cdefa..e0ad14f 100644 --- a/test/json.js +++ b/test/json.js @@ -16,7 +16,7 @@ describe('JSON generator', function () { it('should correctly generate a book to json with sub folders', function(done) { testGeneration(books[1], "json", function(output) { - assert(!fs.existsSync(path.join(output, "README.json"))); + assert(fs.existsSync(path.join(output, "README.json"))); assert(fs.existsSync(path.join(output, "intro.json"))); assert(fs.existsSync(path.join(output, "sub/test1.json"))); |