summaryrefslogtreecommitdiffstats
path: root/lib/generate/generator.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2014-10-15 21:29:23 +0200
committerAaron O'Mullan <aaron.omullan@gmail.com>2014-10-15 21:29:23 +0200
commitce50b893e926fed8905419efc8bce4a64ab2d5dc (patch)
tree83cf19e47f26fd77072ac63aeaf2152a4b30ffa6 /lib/generate/generator.js
parent49e3bbc3d6e9e128df721494e9a10eaf15b7ddc8 (diff)
parent225ff27dd15b904d6a4a784c219522a28f316a5b (diff)
downloadgitbook-ce50b893e926fed8905419efc8bce4a64ab2d5dc.zip
gitbook-ce50b893e926fed8905419efc8bce4a64ab2d5dc.tar.gz
gitbook-ce50b893e926fed8905419efc8bce4a64ab2d5dc.tar.bz2
Merge pull request #482 from GitbookIO/feature/includes
Add include support, with variables and the whole shebang
Diffstat (limited to 'lib/generate/generator.js')
-rw-r--r--lib/generate/generator.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/generate/generator.js b/lib/generate/generator.js
index 8724a4f..84c65d7 100644
--- a/lib/generate/generator.js
+++ b/lib/generate/generator.js
@@ -14,12 +14,35 @@ var BaseGenerator = function(options) {
this.options.plugins = Plugin.normalizeNames(this.options.plugins);
this.options.plugins = _.union(this.options.plugins, this.options.defaultsPlugins);
this.plugins = [];
+
+ // Include variables (not yet loaded)
+ this.variables = {};
};
BaseGenerator.prototype.callHook = function(name, data) {
return this.plugins.hook(name, data);
};
+// Sets up generator
+BaseGenerator.prototype.load = function() {
+ return this.loadVariables()
+ .then(this.loadPlugins.bind(this));
+};
+
+BaseGenerator.prototype.loadVariables = function() {
+ var that = this;
+
+ return fs.readFile(path.join(this.options.input, 'variables.json'), 'utf8')
+ .then(function(content) {
+ try {
+ that.variables = JSON.parse(content);
+ } catch(err) {
+ console.log('No variables.json');
+ }
+ })
+ .fail(function() {});
+};
+
BaseGenerator.prototype.loadPlugins = function() {
var that = this;