diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-09-15 12:22:54 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-09-15 12:22:54 +0200 |
commit | 2a52326a454a23444bd8f0395a9ab8a1f5f68831 (patch) | |
tree | cf5f447e84e3b4ac2d74d7092d8c522bd6e67b79 /lib/template.js | |
parent | 87e4ee1eeb9918cbf151407c66b3377014612d5d (diff) | |
download | gitbook-2a52326a454a23444bd8f0395a9ab8a1f5f68831.zip gitbook-2a52326a454a23444bd8f0395a9ab8a1f5f68831.tar.gz gitbook-2a52326a454a23444bd8f0395a9ab8a1f5f68831.tar.bz2 |
Improve conrefs to handle all absolute file paths correctly
Add test for it
Diffstat (limited to 'lib/template.js')
-rw-r--r-- | lib/template.js | 49 |
1 files changed, 1 insertions, 48 deletions
diff --git a/lib/template.js b/lib/template.js index 65f24c5..9f01d3c 100644 --- a/lib/template.js +++ b/lib/template.js @@ -4,11 +4,10 @@ var path = require("path"); var nunjucks = require("nunjucks"); var escapeStringRegexp = require("escape-string-regexp"); -var git = require("./utils/git"); -var fs = require("./utils/fs"); var batch = require("./utils/batch"); var pkg = require("../package.json"); var defaultBlocks = require("./blocks"); +var BookLoader = require("./conrefs_loader") // Normalize result from a block function normBlockResult(blk) { @@ -16,52 +15,6 @@ function normBlockResult(blk) { return blk; } -// The loader should handle relative and git url -var BookLoader = nunjucks.Loader.extend({ - async: true, - - init: function(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(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) { - // If origin is in the book, we enforce result file to be in the book - if (this.book.fileIsInBook(from)) { - return this.book.resolve(path.dirname(from), to); - } - - // If origin is not in the book (include from a git content ref) - return path.resolve(path.dirname(from), to); - }, - - // 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); - } -}); - var TemplateEngine = function(book) { this.book = book; |