summaryrefslogtreecommitdiffstats
path: root/lib/generators/site.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-21 11:33:33 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-21 11:33:33 +0100
commitbe2da0fab1c467f84c33517950d67da3c9b5768d (patch)
treed5840c8c1cb97bd8f8a8a192c545ffb4577a8e3b /lib/generators/site.js
parent0da50819d663b94bb85ffcaae4231a635921431c (diff)
downloadgitbook-be2da0fab1c467f84c33517950d67da3c9b5768d.zip
gitbook-be2da0fab1c467f84c33517950d67da3c9b5768d.tar.gz
gitbook-be2da0fab1c467f84c33517950d67da3c9b5768d.tar.bz2
Fix json template preparation
Diffstat (limited to 'lib/generators/site.js')
-rw-r--r--lib/generators/site.js85
1 files changed, 82 insertions, 3 deletions
diff --git a/lib/generators/site.js b/lib/generators/site.js
index 6caf372..4ce34e2 100644
--- a/lib/generators/site.js
+++ b/lib/generators/site.js
@@ -26,6 +26,9 @@ BaseGenerator.prototype.load = function() {
return BaseGenerator.prototype.load.apply(this)
.then(function() {
+ return that.loadStyles();
+ })
+ .then(function() {
return that.loadTemplates();
});
};
@@ -47,8 +50,22 @@ Generator.prototype.loadStyles = function() {
// Load template engine
Generator.prototype.loadTemplates = function() {
+ this.pageTemplate = this.plugins.template("site:page") || path.resolve(this.templatesRoot, 'page.html');
+ this.langsTemplate = this.plugins.template("site:langs") || path.resolve(this.templatesRoot, 'langs.html');
+ this.glossaryTemplate = this.plugins.template("site:glossary") || path.resolve(this.templatesRoot, 'templates/website/glossary.html');
+
+ var folders = _.chain(
+ [
+ this.pageTemplate, this.langsTemplate, this.glossaryTemplate
+ ])
+ .map(path.dirname)
+ .uniq()
+ .value();
+
+ console.log("templates folders", folders)
+
this.env = new nunjucks.Environment(
- new nunjucks.FileSystemLoader(this.templatesRoot),
+ new nunjucks.FileSystemLoader(folders),
{
autoescape: true
}
@@ -68,13 +85,75 @@ Generator.prototype.finish = function() {
};
// Convert an input file
-Generator.prototype.writeParsedFile = function(page, input) {
+Generator.prototype.writeParsedFile = function(page) {
+ var output = links.changeExtension(page.path, ".json");
+ output = path.join(that.options.output, output);
+};
+
+// Write the index for langs
+Generator.prototype.langsIndex = function(langs) {
};
-Generator.prototype.langsIndex = function(langs) {
+// Convert a page into a normalized data set
+Generator.prototype.normalizePage = function(page) {
+ var that = this;
+ var _callHook = function(name) {
+ return that.callHook(name, page)
+ .then(function(_page) {
+ page = _page;
+ return page;
+ });
+ };
+
+ return Q()
+ .then(function() {
+ return _callHook("page");
+ })
+ .then(function() {
+ return page;
+ });
+};
+
+// Generate a template
+Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) {
+ var that = this;
+
+ interpolate = interpolate || _.identity;
+ return Q()
+ .then(function(sections) {
+ return that.env.render(
+ tpl,
+ _.extend({
+ styles: that.styles,
+
+ revision: that.revision,
+
+ title: that.options.title,
+ description: that.options.description,
+
+ glossary: that.options.glossary,
+
+ summary: that.options.summary,
+ allNavigation: that.options.navigation,
+
+ plugins: that.plugins,
+ pluginsConfig: JSON.stringify(that.options.pluginsConfig),
+ htmlSnippet: _.partialRight(that.plugins.html, that, options),
+
+ options: that.options
+ }, options)
+ );
+ })
+ .then(interpolate)
+ .then(function(html) {
+ return fs.writeFile(
+ output,
+ html
+ );
+ });
};
module.exports = Generator;