diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-20 13:30:22 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-20 13:30:22 +0100 |
commit | a5ebbc34c7333880b5a194cbe26041029e2cdbfb (patch) | |
tree | a627166ebafc9af50af7cf948bf67a977144b775 | |
parent | 33e32b20d997d688ebb231b92b4e7e1423c2aeec (diff) | |
download | gitbook-a5ebbc34c7333880b5a194cbe26041029e2cdbfb.zip gitbook-a5ebbc34c7333880b5a194cbe26041029e2cdbfb.tar.gz gitbook-a5ebbc34c7333880b5a194cbe26041029e2cdbfb.tar.bz2 |
Add styles configuration in book.json
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | lib/configuration.js | 9 | ||||
-rw-r--r-- | lib/generators/site.js | 42 |
3 files changed, 50 insertions, 4 deletions
@@ -1,11 +1,12 @@ GitBook ======= -:warning: This branch contains some test for a version 2.0. +:warning: This branch contains some tests for a version 2.0. ChangeLog with 1.0.0: - Hooks `summary` and `glossary` (after and before) have been removed - Exercises and Quizzes are no longer parsed in the markdown parser - You can now also use the `.markdown` extension for markdown files +- Plugins can't replace `site:page`, `site:langs` and `site:glossary` diff --git a/lib/configuration.js b/lib/configuration.js index 69e21db..b69cff3 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -149,6 +149,15 @@ Configuration.DEFAULT = { "summary": "SUMMARY.md" }, + // CSS Styles + "styles": { + "website": "styles/website.css", + "ebook": "styles/ebook.css", + "pdf": "styles/pdf.css", + "mobi": "styles/mobi.css", + "epub": "styles/epub.css" + }, + // Plugins list, can contain "-name" for removing default plugins "plugins": [], diff --git a/lib/generators/site.js b/lib/generators/site.js index 7a2a3aa..6caf372 100644 --- a/lib/generators/site.js +++ b/lib/generators/site.js @@ -12,14 +12,50 @@ var pageUtil = require("../utils/page"); var Generator = function() { BaseGenerator.apply(this, arguments); - this.env = new nunjucks.Environment( - new nunjucks.FileSystemLoader(book.root), + // Style to integrates i nthe output + this.styles = ["website"]; + + // base folder for templates + this.templatesRoot = path.resolve(__dirname, "../../theme/templates/website") +}; +util.inherits(Generator, BaseGenerator); + +// Prepare the genertor +BaseGenerator.prototype.load = function() { + var that = this; + + return BaseGenerator.prototype.load.apply(this) + .then(function() { + return that.loadTemplates(); + }); +}; + +// Load all styles +Generator.prototype.loadStyles = function() { + var that = this; + this.styles = _.chain(this.styles) + .map(function(style) { + var stylePath = that.options.styles[style]; + if (fs.existsSync(path.resolve(that.book.root, stylePath))) { + return stylePath; + } + return null; + }) + .compact() + .value(); +}; + +// Load template engine +Generator.prototype.loadTemplates = function() { + this.env = new nunjucks.Environment( + new nunjucks.FileSystemLoader(this.templatesRoot), { autoescape: true } ); + + return Q(); }; -util.inherits(Generator, BaseGenerator); // Ignore some methods Generator.prototype.transferFile = function(input) { |