diff options
Diffstat (limited to 'lib/template.js')
-rw-r--r-- | lib/template.js | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/lib/template.js b/lib/template.js index 28b11c6..320c8bf 100644 --- a/lib/template.js +++ b/lib/template.js @@ -12,31 +12,31 @@ var pkg = require("../package.json"); // The loader should handle relative and git url var BookLoader = nunjucks.Loader.extend({ - async: true, + async: true, init: function(book) { - this.book = book; + this.book = book; }, getSource: function(fileurl, callback) { - var that = this; - - git.resolveFile(fileurl) - .then(function(filepath) { - // Is local file - if (!filepath) filepath = path.resolve(that.book.root, fileurl); - 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 { - src: source.toString(), - path: filepath - } - }); - }) - .nodeify(callback); + var that = this; + + git.resolveFile(fileurl) + .then(function(filepath) { + // Is local file + if (!filepath) filepath = path.resolve(that.book.root, fileurl); + 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 { + src: source.toString(), + path: filepath + } + }); + }) + .nodeify(callback); }, resolve: function(from, to) { @@ -46,27 +46,27 @@ var BookLoader = nunjucks.Loader.extend({ var TemplateEngine = function(book) { - this.book = book; + this.book = book; this.log = this.book.log; - // Nunjucks env - this.env = new nunjucks.Environment( - new BookLoader(book), - { - // Escaping is done after by the markdown parser - autoescape: false, - - // Tags - tags: { - blockStart: '{%', - blockEnd: '%}', - variableStart: '{{', - variableEnd: '}}', - commentStart: '{###', - commentEnd: '###}' - } - } - ); + // Nunjucks env + this.env = new nunjucks.Environment( + new BookLoader(book), + { + // Escaping is done after by the markdown parser + autoescape: false, + + // Tags + tags: { + blockStart: '{%', + blockEnd: '%}', + variableStart: '{{', + variableEnd: '}}', + commentStart: '{###', + commentEnd: '###}' + } + } + ); // List of tags shortcuts this.shortcuts = []; @@ -336,7 +336,7 @@ TemplateEngine.prototype.renderString = function(content, context, options) { // Render a file from the book TemplateEngine.prototype.renderFile = function(filename, options) { - var that = this, context; + var that = this, context; return that.book.readFile(filename) .then(function(content) { |