summaryrefslogtreecommitdiffstats
path: root/lib/generate/site/index.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-10-15 21:20:10 +0200
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-10-15 21:20:10 +0200
commit52e83618467a238f6b20f5fb77f6f6a2e1450c8c (patch)
tree96b43d8396fedea81409677f1e10698a0b36265c /lib/generate/site/index.js
parent49e3bbc3d6e9e128df721494e9a10eaf15b7ddc8 (diff)
downloadgitbook-52e83618467a238f6b20f5fb77f6f6a2e1450c8c.zip
gitbook-52e83618467a238f6b20f5fb77f6f6a2e1450c8c.tar.gz
gitbook-52e83618467a238f6b20f5fb77f6f6a2e1450c8c.tar.bz2
Add include support, with variables and the whole shebang
Fixes #462
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r--lib/generate/site/index.js40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index a694f39..99f5fb3 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -23,6 +23,16 @@ var Generator = function() {
};
util.inherits(Generator, BaseGenerator);
+// Add template loading to load
+Generator.prototype.load = function() {
+ var that = this;
+
+ return BaseGenerator.prototype.load.apply(this)
+ .then(function() {
+ return that.loadTemplates();
+ });
+};
+
// Load all templates
Generator.prototype.loadTemplates = function() {
this.template = swig.compileFile(
@@ -36,16 +46,6 @@ Generator.prototype.loadTemplates = function() {
);
};
-// 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, interpolate) {
var that = this;
@@ -118,16 +118,20 @@ Generator.prototype.prepareFile = function(content, _input) {
return _callHook("page:before");
})
.then(function() {
- // Lex page
- return parse.lex(page.content);
- })
- .then(function(lexed) {
- page.lexed = lexed;
-
+ // Lex, parse includes and get
// Get HTML generated sections
- return parse.page(lexed, {
- dir: path.dirname(_input) || '/',
+ return parse.page(page.content, {
+ // Directories to search for includes
+ dir: [
+ // Local files path
+ path.dirname(_input) || '/',
+ // Project's include folder
+ path.join(that.options.input, '_includes'),
+ ],
+ // Output directory
outdir: path.dirname(_input) || '/',
+ // Templating variables
+ variables: that.variables,
});
})
.then(function(sections) {