diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-10-20 17:08:44 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-10-20 17:08:44 +0200 |
commit | ba5f9132c9ef27a3922f475646ddff3a419cb372 (patch) | |
tree | a5f5e51960e075803302540b29b27dc96ca4e91b /lib/conrefs_loader.js | |
parent | 991681daa2357b8649e40ae9f04e58c88ba0d23f (diff) | |
download | gitbook-ba5f9132c9ef27a3922f475646ddff3a419cb372.zip gitbook-ba5f9132c9ef27a3922f475646ddff3a419cb372.tar.gz gitbook-ba5f9132c9ef27a3922f475646ddff3a419cb372.tar.bz2 |
Fix #982: fix shortcuts for included templates
Diffstat (limited to 'lib/conrefs_loader.js')
-rw-r--r-- | lib/conrefs_loader.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/conrefs_loader.js b/lib/conrefs_loader.js index a6c2049..255bf06 100644 --- a/lib/conrefs_loader.js +++ b/lib/conrefs_loader.js @@ -1,15 +1,19 @@ -var path = require("path"); -var nunjucks = require("nunjucks"); +var _ = require('lodash'); +var path = require('path'); +var nunjucks = require('nunjucks'); -var git = require("./utils/git"); -var fs = require("./utils/fs"); -var pathUtil = require("./utils/path"); +var git = require('./utils/git'); +var fs = require('./utils/fs'); +var pathUtil = require('./utils/path'); // The loader should handle relative and git url var BookLoader = nunjucks.Loader.extend({ async: true, - init: function(book) { + init: function(book, opts) { + this.opts = _.defaults(opts || {}, { + interpolate: _.identity + }); this.book = book; }, @@ -20,14 +24,20 @@ var BookLoader = nunjucks.Loader.extend({ .then(function(filepath) { // Is local file if (!filepath) filepath = path.resolve(fileurl); - else that.book.log.debug.ln("resolve from git", fileurl, "to", filepath); + else that.book.log.debug.ln('resolve from git', fileurl, 'to', filepath); // Read file from absolute path return fs.readFile(filepath) .then(function(source) { + return that.opts.interpolate(filepath, source.toString()); + }) + .then(function(source) { return { - src: source.toString(), - path: filepath + src: source, + path: filepath, + + // We disable cache sincde content is modified (shortcuts, ...) + noCache: true }; }); }) @@ -53,7 +63,7 @@ var BookLoader = nunjucks.Loader.extend({ return path.resolve(path.dirname(from), to); }, - // Handle all files as relative, so that nunjucks pass responsability to "resolve" + // Handle all files as relative, so that nunjucks pass responsability to 'resolve' // Only git urls are considered as absolute isRelative: function(filename) { return !git.checkUrl(filename); |