summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-14 22:55:48 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-14 22:55:48 +0100
commit8628c87be479015b204520bb058b0cc823859d70 (patch)
treee2924a4c569d515c25f05a882a28d7f697833da8 /lib
parentfef822145d43d80dbbefa8712eab88ad7044d6c1 (diff)
downloadgitbook-8628c87be479015b204520bb058b0cc823859d70.zip
gitbook-8628c87be479015b204520bb058b0cc823859d70.tar.gz
gitbook-8628c87be479015b204520bb058b0cc823859d70.tar.bz2
Interpolate template before running it
Diffstat (limited to 'lib')
-rw-r--r--lib/output/conrefs.js6
-rw-r--r--lib/template/index.js2
-rw-r--r--lib/template/loader.js10
3 files changed, 10 insertions, 8 deletions
diff --git a/lib/output/conrefs.js b/lib/output/conrefs.js
index fb2d5bb..98230d9 100644
--- a/lib/output/conrefs.js
+++ b/lib/output/conrefs.js
@@ -32,12 +32,8 @@ ConrefsLoader.prototype.onGetTemplate = function(sourceURL) {
// Read file from absolute path
return fs.readFile(filepath)
.then(function(source) {
- return source.toString('utf8');
- //return that.engine.interpolate(filepath, source);
- })
- .then(function(source) {
return {
- src: source,
+ src: source.toString('utf8'),
path: filepath
};
});
diff --git a/lib/template/index.js b/lib/template/index.js
index 6074f51..3f74267 100644
--- a/lib/template/index.js
+++ b/lib/template/index.js
@@ -27,7 +27,7 @@ function TemplateEngine(output) {
this.log = this.book.log;
// Create file loader
- this.loader = new Loader(output);
+ this.loader = new Loader(this);
// Create nunjucks instance
this.env = new nunjucks.Environment(
diff --git a/lib/template/loader.js b/lib/template/loader.js
index 6b54015..23d179a 100644
--- a/lib/template/loader.js
+++ b/lib/template/loader.js
@@ -8,16 +8,22 @@ Simple nunjucks loader which is passing the reponsability to the Output
var Loader = nunjucks.Loader.extend({
async: true,
- init: function(output, opts) {
- this.output = output;
+ init: function(engine, opts) {
+ this.engine = engine;
+ this.output = engine.output;
},
getSource: function(sourceURL, callback) {
+ var that = this;
+
this.output.onGetTemplate(sourceURL)
.then(function(out) {
// We disable cache since content is modified (shortcuts, ...)
out.noCache = true;
+ // Transform template before runnign it
+ out.source = that.engine.interpolate(out.path, out.source);
+
return out;
})
.nodeify(callback);