summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-21 19:51:35 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-21 19:51:35 +0100
commit3d8db17bc35d22ae514805ded1a4dd12ae968b60 (patch)
treeb35bdd95dc73824e00838d64aaea8c96cafbd2b4 /lib
parent3c605ea8099bcba58d8eeb0435d87c563d434e46 (diff)
downloadgitbook-3d8db17bc35d22ae514805ded1a4dd12ae968b60.zip
gitbook-3d8db17bc35d22ae514805ded1a4dd12ae968b60.tar.gz
gitbook-3d8db17bc35d22ae514805ded1a4dd12ae968b60.tar.bz2
Copy theme assets to output
Diffstat (limited to 'lib')
-rw-r--r--lib/configuration.js2
-rw-r--r--lib/generator.js6
-rw-r--r--lib/generators/site.js40
3 files changed, 36 insertions, 12 deletions
diff --git a/lib/configuration.js b/lib/configuration.js
index b69cff3..708797d 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -176,7 +176,7 @@ Configuration.DEFAULT = {
// Set another theme with your own layout
// It's recommended to use plugins or add more options for default theme, though
// See https://github.com/GitbookIO/gitbook/issues/209
- "theme": path.resolve(__dirname, '../../theme'),
+ "theme": path.resolve(__dirname, '../theme'),
// Links in template (null: default, false: remove, string: new value)
"links": {
diff --git a/lib/generator.js b/lib/generator.js
index f495d8d..a16af16 100644
--- a/lib/generator.js
+++ b/lib/generator.js
@@ -16,6 +16,8 @@ var BaseGenerator = function(book) {
// Base for assets in plugins
this.pluginAssetsBase = "book";
+
+ _.bindAll(this);
};
BaseGenerator.prototype.callHook = function(name, data) {
@@ -61,8 +63,8 @@ BaseGenerator.prototype.copyCover = function() {
var that = this;
return Q.all([
- fs.copy(path.join(this.book.root, "cover.jpg"), path.join(this.options.output, "cover.jpg")),
- fs.copy(path.join(this.book.root, "cover_small.jpg"), path.join(this.options.output, "cover_small.jpg"))
+ fs.copy(path.join(that.book.root, "cover.jpg"), path.join(that.options.output, "cover.jpg")),
+ fs.copy(path.join(that.book.root, "cover_small.jpg"), path.join(that.options.output, "cover_small.jpg"))
])
.fail(function() {
// If orignaly from multi-lang, try copy from parent
diff --git a/lib/generators/site.js b/lib/generators/site.js
index cd63bbe..4999de9 100644
--- a/lib/generators/site.js
+++ b/lib/generators/site.js
@@ -19,11 +19,8 @@ var Generator = function() {
// revision
this.revision = new Date();
- // Style to integrates i nthe output
+ // Style to integrates in the output
this.styles = ["website"];
-
- // base folder for templates
- this.templatesRoot = path.resolve(__dirname, "../../theme/templates/website")
};
util.inherits(Generator, BaseGenerator);
@@ -57,9 +54,9 @@ Generator.prototype.prepareStyles = function() {
// Prepare template engine
Generator.prototype.prepareTemplates = function() {
- this.pageTemplate = this.plugins.template("site:page") || path.resolve(this.templatesRoot, 'page.html');
- this.langsTemplate = this.plugins.template("site:langs") || path.resolve(this.templatesRoot, 'langs.html');
- this.glossaryTemplate = this.plugins.template("site:glossary") || path.resolve(this.templatesRoot, 'glossary.html');
+ this.pageTemplate = this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/website/page.html');
+ this.langsTemplate = this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/website/langs.html');
+ this.glossaryTemplate = this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/website/glossary.html');
var folders = _.chain(
[
@@ -92,9 +89,10 @@ Generator.prototype.transferFile = function(input) {
};
-
+// Finis generation
Generator.prototype.finish = function() {
-
+ return this.copyAssets()
+ .then(this.copyCover)
};
// Normalize a link to .html and convert README -> index
@@ -191,4 +189,28 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate)
});
};
+
+// Copy assets
+Generator.prototype.copyAssets = function() {
+ var that = this;
+
+ // Copy gitbook assets
+ return fs.copy(
+ path.join(that.options.theme, "assets"),
+ path.join(that.options.output, "gitbook")
+ )
+
+ // Copy plugins assets
+ .then(function() {
+ return Q.all(
+ _.map(that.plugins.list, function(plugin) {
+ var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name);
+ return plugin.copyAssets(pluginAssets, {
+ base: that.pluginAssetsBase
+ });
+ })
+ );
+ });
+};
+
module.exports = Generator;