summaryrefslogtreecommitdiffstats
path: root/lib/generate
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generate')
-rw-r--r--lib/generate/generator.js23
-rw-r--r--lib/generate/index.js2
-rw-r--r--lib/generate/site/index.js40
3 files changed, 46 insertions, 19 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;
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 4fc78a7..2118c46 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -40,7 +40,7 @@ var loadGenerator = function(options) {
.then(function() {
var generator = new generators[options.generator](options);
- return generator.loadPlugins()
+ return generator.load()
.then(_.constant(generator));
});
};
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) {