summaryrefslogtreecommitdiffstats
path: root/lib/generators
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/json.js11
-rw-r--r--lib/generators/site.js85
2 files changed, 85 insertions, 11 deletions
diff --git a/lib/generators/json.js b/lib/generators/json.js
index 65197e0..a1202ad 100644
--- a/lib/generators/json.js
+++ b/lib/generators/json.js
@@ -6,7 +6,6 @@ var _ = require("lodash");
var fs = require("../utils/fs");
var BaseGenerator = require("../generator");
var links = require("../utils/links");
-var pageUtil = require("../utils/page");
var Generator = function() {
BaseGenerator.apply(this, arguments);
@@ -18,18 +17,14 @@ Generator.prototype.transferFile = function(input) { };
Generator.prototype.finish = function() { };
// Convert an input file
-Generator.prototype.writeParsedFile = function(page, input) {
+Generator.prototype.writeParsedFile = function(page) {
var that = this;
var json = {
progress: page.progress,
- sections: pageUtil.normalize(page.sections, {
- navigation: that.book.navigation,
- base: path.dirname(input) || './',
- output: path.dirname(input) || './'
- })
+ sections: page.sections
};
- var output = links.changeExtension(input, ".json");
+ var output = links.changeExtension(page.path, ".json");
output = path.join(that.options.output, output);
return fs.writeFile(
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;