diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 14:51:35 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-19 14:51:35 +0100 |
commit | b314972195b18df43ad3eba6266ae1ba1b1873e3 (patch) | |
tree | 0765b59d5d270f89e93e78dc653f93630fb572e4 | |
parent | 52179163dda6f52e0d64dc516c5612ac1e17be8f (diff) | |
download | gitbook-b314972195b18df43ad3eba6266ae1ba1b1873e3.zip gitbook-b314972195b18df43ad3eba6266ae1ba1b1873e3.tar.gz gitbook-b314972195b18df43ad3eba6266ae1ba1b1873e3.tar.bz2 |
Add configuration to send structures files
-rw-r--r-- | lib/book.js | 10 | ||||
-rw-r--r-- | lib/configuration.js | 12 | ||||
-rw-r--r-- | lib/template.js | 18 | ||||
-rw-r--r-- | package.json | 3 |
4 files changed, 39 insertions, 4 deletions
diff --git a/lib/book.js b/lib/book.js index bfe0a17..8c3561a 100644 --- a/lib/book.js +++ b/lib/book.js @@ -4,6 +4,7 @@ var path = require("path"); var fs = require("./utils/fs"); var Configuration = require("./configuration"); +var TemplateEngine = require("./template"); var parser = require("./parser"); var Book = function(root, options, parent) { @@ -21,6 +22,9 @@ var Book = function(root, options, parent) { } }); + // Template + this.template = new TemplateEngine(this); + // Summary this.summary = {}; @@ -82,7 +86,7 @@ Book.prototype.generate = function() { Book.prototype.parseLangs = function() { var that = this; - return that.findFile("LANGS") + return that.findFile(that.config.getStructure("langs")) .then(function(langs) { if (!langs) return []; @@ -100,7 +104,7 @@ Book.prototype.parseLangs = function() { Book.prototype.parseSummary = function() { var that = this; - return that.findFile("SUMMARY") + return that.findFile(that.config.getStructure("summary")) .then(function(summary) { if (!summary) throw "No SUMMARY file"; @@ -118,7 +122,7 @@ Book.prototype.parseSummary = function() { Book.prototype.parseGlossary = function() { var that = this; - return that.findFile("GLOSSARY") + return that.findFile(that.config.getStructure("glossary")) .then(function(glossary) { if (!glossary) return {}; diff --git a/lib/configuration.js b/lib/configuration.js index 2b470c4..47485af 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -28,6 +28,11 @@ Configuration.prototype.load = function() { }); }; +// Get structure file +Configuration.prototype.getStructure = function(name) { + return this.options.structure[name].split(".").slice(0, -1).join("."); +}; + // Default configuration Configuration.DEFAULT = { // Options that can't be extend @@ -41,6 +46,13 @@ Configuration.DEFAULT = { "isbn": null, "lang": "en", + // Structure + "structure": { + "readme": "README.md", + "glossary": "GLOSSARY.md", + "summary": "SUMMARY.md" + }, + // Plugins list, can contain "-name" for removing default plugins "plugins": [], diff --git a/lib/template.js b/lib/template.js new file mode 100644 index 0000000..9576fe9 --- /dev/null +++ b/lib/template.js @@ -0,0 +1,18 @@ +var _ = require("lodash"); +var nunjucks = require("nunjucks"); + +var TemplateEngine = function(book) { + this.book = book; +}; + +// Render a file from the book +TemplateEngine.prototype.renderFile = function(filename) { + var that = this; + + return this.book.readFile(filename) + .then(function(content) { + + }); +}; + +module.exports = TemplateEngine; diff --git a/package.json b/package.json index 5d034e8..dd4a540 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "graceful-fs": "3.0.5", "fs-extra": "0.14.0", "fstream-ignore": "1.0.2", - "gitbook-markdown": "1.0.0" + "gitbook-markdown": "1.0.0", + "nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747" }, "devDependencies": { "mocha": "1.18.2" |