summaryrefslogtreecommitdiffstats
path: root/lib/generate
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generate')
-rw-r--r--lib/generate/config.js8
-rw-r--r--lib/generate/ebook/index.js11
-rw-r--r--lib/generate/fs.js1
-rw-r--r--lib/generate/page/index.js5
-rw-r--r--lib/generate/site/index.js31
5 files changed, 47 insertions, 9 deletions
diff --git a/lib/generate/config.js b/lib/generate/config.js
index fb232a6..e198c91 100644
--- a/lib/generate/config.js
+++ b/lib/generate/config.js
@@ -65,6 +65,14 @@ var CONFIG = {
}
},
+ // CSS Styles
+ "styles": {
+ "website": "styles/website.css",
+ "ebook": "styles/ebook.css",
+ "pdf": "styles/pdf.css",
+ "mobi": "styles/mobi.css",
+ "epub": "styles/epub.css"
+ },
// Options for PDF generation
"pdf": {
diff --git a/lib/generate/ebook/index.js b/lib/generate/ebook/index.js
index 4ecccec..c74ffcd 100644
--- a/lib/generate/ebook/index.js
+++ b/lib/generate/ebook/index.js
@@ -11,6 +11,12 @@ var stringUtils = require("../../utils/string");
var Generator = function() {
BaseGenerator.apply(this, arguments);
+
+ // eBook format
+ this.ebookFormat = this.options.extension || path.extname(this.options.output).replace("\.", "") || "pdf";
+
+ // Styles to use
+ this.styles = ["ebook", this.ebookFormat];
};
util.inherits(Generator, BaseGenerator);
@@ -20,7 +26,6 @@ Generator.prototype.finish = function() {
return BaseGenerator.prototype.finish.apply(this)
.then(function() {
var d = Q.defer();
- var format = that.options.extension || path.extname(that.options.output).replace("\.", "") || "pdf";
if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) {
that.options.cover = path.join(that.options.output, "cover.jpg");
@@ -44,7 +49,7 @@ Generator.prototype.finish = function() {
"--breadth-first": true
};
- if (format == "pdf") {
+ if (that.ebookFormat == "pdf") {
var pdfOptions = that.options.pdf;
_.extend(_options, {
@@ -64,7 +69,7 @@ Generator.prototype.finish = function() {
var command = [
"ebook-convert",
path.join(that.options.output, "SUMMARY.html"),
- path.join(that.options.output, "index."+format),
+ path.join(that.options.output, "index."+that.ebookFormat),
stringUtils.optionsToShellArgs(_options)
].join(" ");
diff --git a/lib/generate/fs.js b/lib/generate/fs.js
index 50219eb..371051c 100644
--- a/lib/generate/fs.js
+++ b/lib/generate/fs.js
@@ -87,5 +87,6 @@ module.exports = {
fs.exists(path, d.resolve);
return d.promise;
},
+ existsSync: fs.existsSync,
readFileSync: fs.readFileSync.bind(fs)
};
diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js
index a926d13..8054fe6 100644
--- a/lib/generate/page/index.js
+++ b/lib/generate/page/index.js
@@ -11,6 +11,9 @@ var BaseGenerator = require("../site");
var Generator = function() {
BaseGenerator.apply(this, arguments);
+ // Styles to use
+ this.styles = ["ebook"];
+
// Base for assets in plugins
this.pluginAssetsBase = "ebook";
@@ -49,7 +52,7 @@ Generator.prototype.finish = function() {
var output = path.join(this.options.output, "index.html");
var progress = parse.progress(this.options.navigation, "README.md");
-
+
return Q()
// Write table of contents
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index 4d8803e..dfdbf68 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -18,6 +18,7 @@ var Generator = function() {
// Attach methods to instance
_.bindAll(this);
+ this.styles = ["website"];
this.revision = Date.now();
this.indexer = indexer();
};
@@ -29,20 +30,38 @@ Generator.prototype.load = function() {
return BaseGenerator.prototype.load.apply(this)
.then(function() {
+ return that.loadStyles();
+ })
+ .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.options.input, stylePath))) {
+ return stylePath;
+ }
+ return null;
+ })
+ .compact()
+ .value();
+};
+
// Load all templates
Generator.prototype.loadTemplates = function() {
this.template = swig.compileFile(
- this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/book/page.html')
+ this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/website/page.html')
);
this.langsTemplate = swig.compileFile(
- this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/book/langs.html')
+ this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/website/langs.html')
);
this.glossaryTemplate = swig.compileFile(
- this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/book/glossary.html')
+ this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/website/glossary.html')
);
};
@@ -54,6 +73,8 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate)
return Q()
.then(function(sections) {
return tpl(_.extend({
+ styles: that.styles,
+
revision: that.revision,
title: that.options.title,
@@ -154,12 +175,12 @@ Generator.prototype.convertFile = function(content, _input) {
if (_output == "README.html") _output = "index.html";
var output = path.join(this.options.output, _output);
var basePath = path.relative(path.dirname(output), this.options.output) || ".";
-
+
// Bug fix for issue #493 which would occur when relative-links are 2-level or more deep in win32
if (process.platform === 'win32') {
basePath = basePath.replace(/\\/g, '/');
}
-
+
return this.prepareFile(content, _input)
.then(function(page) {
// Index page in search