Copy theme assets to output

This commit is contained in:
Samy Pessé
2015-01-21 19:51:35 +01:00
parent 3c605ea809
commit 3d8db17bc3
3 changed files with 36 additions and 12 deletions
+1 -1
View File
@@ -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": {
+4 -2
View File
@@ -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
+31 -9
View File
@@ -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;