diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-26 09:41:26 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-26 09:41:26 +0100 |
commit | d3d64f636c859f7f01a64f7774cf70bd8ccdc562 (patch) | |
tree | 4f7731f37c3a793d187b0ab1cd77680e69534c6c /lib/template/loader.js | |
parent | 4cb9cbb5ae3aa8f9211ffa3ac5e3d34232c0ca4f (diff) | |
parent | eef072693b17526347c37b66078a5059c71caa31 (diff) | |
download | gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.zip gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.gz gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.bz2 |
Merge pull request #1109 from GitbookIO/3.0.0
Version 3.0.0
Diffstat (limited to 'lib/template/loader.js')
-rw-r--r-- | lib/template/loader.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/template/loader.js b/lib/template/loader.js new file mode 100644 index 0000000..23d179a --- /dev/null +++ b/lib/template/loader.js @@ -0,0 +1,42 @@ +var nunjucks = require('nunjucks'); +var location = require('../utils/location'); + +/* +Simple nunjucks loader which is passing the reponsability to the Output +*/ + +var Loader = nunjucks.Loader.extend({ + async: true, + + 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); + }, + + resolve: function(from, to) { + return this.output.onResolveTemplate(from, to); + }, + + // Handle all files as relative, so that nunjucks pass responsability to 'resolve' + isRelative: function(filename) { + return location.isRelative(filename); + } +}); + +module.exports = Loader; |