diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-21 14:26:09 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-21 14:26:09 -0700 |
commit | 4c90fdb7b27fdf6527b59097d489a9df0a929264 (patch) | |
tree | b00f3196f58ed712dea40dd69a261fc43129a651 /lib/generate/site/index.js | |
parent | d1c1d7b75b6e4a304d031c4313cf54ae8aa3a11d (diff) | |
parent | 98c133df3c9077c1b06748c3206bea3ff011ed3a (diff) | |
download | gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.zip gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.tar.gz gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.tar.bz2 |
Merge pull request #123 from GitbookIO/feature/plugins
Fix #65: Plugins Architecture
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 4bea547..68328e7 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -30,13 +30,28 @@ var Generator = function() { this.revision = Date.now(); this.indexer = indexer(); - - // Load base template - this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/site.html')); - this.langsTemplate = swig.compileFile(path.resolve(this.options.theme, 'templates/langs.html')); }; util.inherits(Generator, BaseGenerator); +// Load all templates +Generator.prototype.loadTemplates = function() { + this.template = swig.compileFile( + this.plugins.template("site") || path.resolve(this.options.theme, 'templates/site.html') + ); + this.langsTemplate = swig.compileFile( + this.plugins.template("langs") || path.resolve(this.options.theme, 'templates/langs.html') + ); +}; + +// Load plugins +Generator.prototype.loadPlugins = function() { + var that = this; + + return BaseGenerator.prototype.loadPlugins.apply(this) + .then(function() { + return that.loadTemplates(); + }); +}; // Generate a template Generator.prototype._writeTemplate = function(tpl, options, output) { @@ -54,7 +69,10 @@ Generator.prototype._writeTemplate = function(tpl, options, output) { githubHost: that.options.githubHost, summary: that.options.summary, - allNavigation: that.options.navigation + allNavigation: that.options.navigation, + + plugins: that.plugins, + pluginsConfig: JSON.stringify(that.options.pluginsConfig) }, options)); }) .then(function(html) { @@ -134,10 +152,19 @@ Generator.prototype.langsIndex = function(langs) { 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) { + return plugin.copyAssets(path.join(that.options.output, "gitbook/plugins/", plugin.name)) + }) + ); + }) }; // Dump search index to disk |