summaryrefslogtreecommitdiffstats
path: root/lib/generators/json.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-02-12 12:18:52 +0100
committerSamy Pessé <samypesse@gmail.com>2015-02-12 12:18:52 +0100
commit4ad2b040b462ae2f94922e9ad01d7804eb6d79dc (patch)
treef4703abaf76543d7f484560a5d66e1ee59acf6eb /lib/generators/json.js
parentf5916b5c595cc507bee2a56ccfdfc7eb9ecc4281 (diff)
downloadgitbook-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)
Diffstat (limited to 'lib/generators/json.js')
-rw-r--r--lib/generators/json.js24
1 files changed, 14 insertions, 10 deletions
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) {