summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-04-19 15:46:37 +0200
committerSamy Pesse <samypesse@gmail.com>2016-04-19 15:46:37 +0200
commit53ced205b820a0b8cf6bfc0d3090b3bb3dc20d6b (patch)
tree093625eba7cdd1e7498dd188c9c0610a85037cf5
parent61c49839498ef5056b3d8ac1719e87baef6656af (diff)
downloadgitbook-53ced205b820a0b8cf6bfc0d3090b3bb3dc20d6b.zip
gitbook-53ced205b820a0b8cf6bfc0d3090b3bb3dc20d6b.tar.gz
gitbook-53ced205b820a0b8cf6bfc0d3090b3bb3dc20d6b.tar.bz2
Ensure "template" is always set when rendering a template
-rw-r--r--lib/output/website/index.js6
-rw-r--r--lib/output/website/templateEnv.js6
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/output/website/index.js b/lib/output/website/index.js
index 9acc631..0a8618c 100644
--- a/lib/output/website/index.js
+++ b/lib/output/website/index.js
@@ -154,9 +154,7 @@ WebsiteOutput.prototype.renderAsString = function(tpl, context) {
// Calcul template name
var filename = this.templateName(tpl);
- context = _.extend({
- template: {}
- }, context, {
+ context = _.extend(context, {
plugins: {
resources: this.resources
},
@@ -167,7 +165,7 @@ WebsiteOutput.prototype.renderAsString = function(tpl, context) {
// Create environment
var env = setupTemplateEnv(this, context);
- return Promise.nfcall(env.render.bind(env), filename);
+ return Promise.nfcall(env.render.bind(env), filename, context);
};
/*
diff --git a/lib/output/website/templateEnv.js b/lib/output/website/templateEnv.js
index b3009db..d385108 100644
--- a/lib/output/website/templateEnv.js
+++ b/lib/output/website/templateEnv.js
@@ -21,6 +21,11 @@ function templatesPath(dir) {
@return {Nunjucks.Environment}
*/
function setupTemplateEnv(output, context) {
+ context = _.defaults(context || {}, {
+ // Required by ThemeLoader
+ template: {}
+ });
+
var loader = new ThemeLoader(
_.map(output.searchPaths, templatesPath)
);
@@ -84,7 +89,6 @@ function setupTemplateEnv(output, context) {
return location.normalize(href);
});
-
return env;
}