summaryrefslogtreecommitdiffstats
path: root/lib/generators/website.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators/website.js')
-rw-r--r--lib/generators/website.js66
1 files changed, 35 insertions, 31 deletions
diff --git a/lib/generators/website.js b/lib/generators/website.js
index 6db2fa4..c54380e 100644
--- a/lib/generators/website.js
+++ b/lib/generators/website.js
@@ -20,25 +20,24 @@ var Generator = function() {
// Style to integrates in the output
this.styles = ["website"];
+
+ // Templates
+ this.templates = {};
};
util.inherits(Generator, BaseGenerator);
// Prepare the genertor
Generator.prototype.prepare = function() {
- var that = this;
-
return BaseGenerator.prototype.prepare.apply(this)
- .then(function() {
- return that.prepareStyles();
- })
- .then(function() {
- return that.prepareTemplates();
- });
+ .then(this.prepareStyles)
+ .then(this.prepareTemplates)
+ .then(this.prepareTemplateEngine);
};
// Prepare all styles
Generator.prototype.prepareStyles = function() {
var that = this;
+
this.styles = _.chain(this.styles)
.map(function(style) {
var stylePath = that.options.styles[style];
@@ -49,28 +48,33 @@ Generator.prototype.prepareStyles = function() {
})
.compact()
.value();
+
+ return Q();
};
-// Prepare template engine
+// Prepare templates
Generator.prototype.prepareTemplates = function() {
- 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(
- [
- this.pageTemplate, this.langsTemplate, this.glossaryTemplate
- ])
- .map(path.dirname)
- .uniq()
- .value();
-
- this.env = new nunjucks.Environment(
- new nunjucks.FileSystemLoader(folders),
- {
- autoescape: true
- }
- );
+ this.templates["page"] = this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/website/page.html');
+ this.templates["langs"] = this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/website/langs.html');
+ this.templates["glossary"] = this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/website/glossary.html');
+
+ return Q();
+};
+
+// Prepare template engine
+Generator.prototype.prepareTemplateEngine = function() {
+ var folders = _.chain(this.templates)
+ .values()
+ .map(path.dirname)
+ .uniq()
+ .value();
+
+ this.env = new nunjucks.Environment(
+ new nunjucks.FileSystemLoader(folders),
+ {
+ autoescape: true
+ }
+ );
// Add filter
this.env.addFilter("contentLink", this.book.contentLink.bind(this.book));
@@ -82,7 +86,7 @@ Generator.prototype.prepareTemplates = function() {
this.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(this.env));
this.env.addExtension('FilterExtension', new FilterExtension(this.env));
- return Q();
+ return Q();
};
// Finis generation
@@ -105,7 +109,7 @@ Generator.prototype.writeParsedFile = function(page) {
return that.normalizePage(page)
.then(function() {
- return that._writeTemplate(that.pageTemplate, {
+ return that._writeTemplate(that.templates["page"], {
progress: page.progress,
_input: page.path,
@@ -121,7 +125,7 @@ Generator.prototype.writeParsedFile = function(page) {
Generator.prototype.langsIndex = function(langs) {
var that = this;
- return this._writeTemplate(this.langsTemplate, {
+ return this._writeTemplate(this.templates["langs"], {
langs: langs
}, path.join(this.options.output, "index.html"));
};
@@ -133,7 +137,7 @@ Generator.prototype.writeGlossary = function() {
// No glossary
if (this.book.glossary.length == 0) return Q();
- return this._writeTemplate(this.glossaryTemplate, {}, path.join(this.options.output, "GLOSSARY.html"));
+ return this._writeTemplate(this.templates["glossary"], {}, path.join(this.options.output, "GLOSSARY.html"));
};
// Write the search index