diff options
Diffstat (limited to 'lib/generators')
-rw-r--r-- | lib/generators/ebook.js | 20 | ||||
-rw-r--r-- | lib/generators/json.js | 4 | ||||
-rw-r--r-- | lib/generators/website.js | 35 |
3 files changed, 27 insertions, 32 deletions
diff --git a/lib/generators/ebook.js b/lib/generators/ebook.js index cdb667c..e6a33d3 100644 --- a/lib/generators/ebook.js +++ b/lib/generators/ebook.js @@ -2,7 +2,7 @@ var util = require("util"); var path = require("path"); var Q = require("q"); var _ = require("lodash"); -var exec = require('child_process').exec; +var exec = require("child_process").exec; var fs = require("../utils/fs"); var stringUtils = require("../utils/string"); @@ -26,9 +26,9 @@ var Generator = function(book, format) { util.inherits(Generator, BaseGenerator); Generator.prototype.prepareTemplates = function() { - this.templates["page"] = this.book.plugins.template("ebook:page") || path.resolve(this.options.theme, 'templates/ebook/page.html'); - this.templates["summary"] = this.book.plugins.template("ebook:summary") || path.resolve(this.options.theme, 'templates/ebook/summary.html'); - this.templates["glossary"] = this.book.plugins.template("ebook:glossary") || path.resolve(this.options.theme, 'templates/ebook/glossary.html'); + this.templates.page = this.book.plugins.template("ebook:page") || path.resolve(this.options.theme, "templates/ebook/page.html"); + this.templates.summary = this.book.plugins.template("ebook:summary") || path.resolve(this.options.theme, "templates/ebook/summary.html"); + this.templates.glossary = this.book.plugins.template("ebook:glossary") || path.resolve(this.options.theme, "templates/ebook/glossary.html"); return Q(); }; @@ -38,7 +38,7 @@ Generator.prototype.writeSummary = function() { var that = this; that.book.log.info.ln("write SUMMARY.html"); - return this._writeTemplate(this.templates["summary"], {}, path.join(this.options.output, "SUMMARY.html")); + return this._writeTemplate(this.templates.summary, {}, path.join(this.options.output, "SUMMARY.html")); }; Generator.prototype.finish = function() { @@ -52,12 +52,12 @@ Generator.prototype.finish = function() { .then(function() { if (!that.ebookFormat) return Q(); - var d = Q.defer(); - if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) { that.options.cover = path.join(that.options.output, "cover.jpg"); } + var d = Q.defer(); + var _options = { "--cover": that.options.cover, "--title": that.options.title, @@ -108,7 +108,7 @@ Generator.prototype.finish = function() { that.book.log.info("start conversion to", that.ebookFormat, "...."); - var child = exec(command, function (error, stdout, stderr) { + var child = exec(command, function (error, stdout) { if (error) { that.book.log.info.fail(); @@ -124,11 +124,11 @@ Generator.prototype.finish = function() { d.resolve(); }); - child.stdout.on('data', function (data) { + child.stdout.on("data", function (data) { that.book.log.debug(data); }); - child.stderr.on('data', function (data) { + child.stderr.on("data", function (data) { that.book.log.debug(data); }); diff --git a/lib/generators/json.js b/lib/generators/json.js index 6c9439d..446ef0d 100644 --- a/lib/generators/json.js +++ b/lib/generators/json.js @@ -13,7 +13,7 @@ var Generator = function() { util.inherits(Generator, BaseGenerator); // Ignore some methods -Generator.prototype.transferFile = function(input) { }; +Generator.prototype.transferFile = function() { }; // Convert an input file Generator.prototype.convertFile = function(input) { @@ -44,7 +44,7 @@ Generator.prototype.finish = function() { // Write README.json Generator.prototype.writeReadme = function() { var that = this; - var mainlang, langs; + var mainLang, langs, readme; return Q() .then(function() { diff --git a/lib/generators/website.js b/lib/generators/website.js index 675092f..4bde473 100644 --- a/lib/generators/website.js +++ b/lib/generators/website.js @@ -10,7 +10,6 @@ var FilterExtension = require("nunjucks-filter")(nunjucks); var fs = require("../utils/fs"); var BaseGenerator = require("../generator"); var links = require("../utils/links"); -var pageUtil = require("../utils/page"); var i18n = require("../utils/i18n"); var pkg = require("../../package.json"); @@ -64,9 +63,9 @@ Generator.prototype.prepareStyles = function() { // Prepare templates Generator.prototype.prepareTemplates = function() { - this.templates["page"] = this.book.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/website/page.html'); - this.templates["langs"] = this.book.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/website/langs.html'); - this.templates["glossary"] = this.book.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/website/glossary.html'); + this.templates.page = this.book.plugins.template("site:page") || path.resolve(this.options.theme, "templates/website/page.html"); + this.templates.langs = this.book.plugins.template("site:langs") || path.resolve(this.options.theme, "templates/website/langs.html"); + this.templates.glossary = this.book.plugins.template("site:glossary") || path.resolve(this.options.theme, "templates/website/glossary.html"); return Q(); }; @@ -98,13 +97,13 @@ Generator.prototype.prepareTemplateEngine = function() { // Add filter that.env.addFilter("contentLink", that.book.contentLink.bind(that.book)); - that.env.addFilter('lvl', function(lvl) { + that.env.addFilter("lvl", function(lvl) { return lvl.split(".").length; }); // Add extension - that.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(that.env)); - that.env.addExtension('FilterExtension', new FilterExtension(that.env)); + that.env.addExtension("AutoEscapeExtension", new AutoEscapeExtension(that.env)); + that.env.addExtension("FilterExtension", new FilterExtension(that.env)); }); }; @@ -114,7 +113,7 @@ Generator.prototype.finish = function() { .then(this.copyCover) .then(this.writeGlossary) .then(this.writeSearchIndex) - .then(this.writeLangsIndex) + .then(this.writeLangsIndex); }; // Convert an input file @@ -135,11 +134,11 @@ Generator.prototype.convertFile = function(input) { var output = path.join(that.options.output, relativeOutput); var basePath = path.relative(path.dirname(output), that.options.output) || "."; - if (process.platform === 'win32') basePath = basePath.replace(/\\/g, '/'); + if (process.platform === "win32") basePath = basePath.replace(/\\/g, "/"); that.book.log.debug.ln("write parsed file", page.path, "to", relativeOutput); - return that._writeTemplate(that.templates["page"], { + return that._writeTemplate(that.templates.page, { progress: page.progress, _input: page.path, @@ -153,27 +152,23 @@ Generator.prototype.convertFile = function(input) { // Write the index for langs Generator.prototype.writeLangsIndex = function() { - var that = this; if (!this.book.langs.length) return Q(); - return this._writeTemplate(this.templates["langs"], { + + return this._writeTemplate(this.templates.langs, { langs: this.book.langs }, path.join(this.options.output, "index.html")); }; // Write glossary Generator.prototype.writeGlossary = function() { - var that = this; - // No glossary - if (this.book.glossary.length == 0) return Q(); + if (this.book.glossary.length === 0) return Q(); - return this._writeTemplate(this.templates["glossary"], {}, path.join(this.options.output, "GLOSSARY.html")); + return this._writeTemplate(this.templates.glossary, {}, path.join(this.options.output, "GLOSSARY.html")); }; // Write the search index Generator.prototype.writeSearchIndex = function() { - var that = this; - return fs.writeFile( path.join(this.options.output, "search_index.json"), JSON.stringify(this.book.searchIndex) @@ -207,7 +202,7 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) interpolate = interpolate || _.identity; return Q() - .then(function(sections) { + .then(function() { return that.env.render( tpl, _.extend({ @@ -239,7 +234,7 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) basePath: ".", staticBase: path.join(".", "gitbook"), - '__': that.book.i18n.bind(that.book) + "__": that.book.i18n.bind(that.book) }, options) ); }) |