diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-09-15 11:48:18 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-09-15 11:48:18 +0200 |
commit | 87e4ee1eeb9918cbf151407c66b3377014612d5d (patch) | |
tree | ce283acc1495272a66f55132130d00d36e53cc6b | |
parent | 45833eea9ad5fb97ab5e5095e4e4b8e3481c7d2e (diff) | |
download | gitbook-87e4ee1eeb9918cbf151407c66b3377014612d5d.zip gitbook-87e4ee1eeb9918cbf151407c66b3377014612d5d.tar.gz gitbook-87e4ee1eeb9918cbf151407c66b3377014612d5d.tar.bz2 |
Handle absolute file correctly for conrefs
Add test for absolute file for conrefs
-rw-r--r-- | lib/template.js | 8 | ||||
-rw-r--r-- | test/books/conrefs/README.md | 5 | ||||
-rw-r--r-- | test/conrefs.js | 14 |
3 files changed, 22 insertions, 5 deletions
diff --git a/lib/template.js b/lib/template.js index b1bc632..65f24c5 100644 --- a/lib/template.js +++ b/lib/template.js @@ -31,7 +31,7 @@ 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) @@ -53,6 +53,12 @@ var BookLoader = nunjucks.Loader.extend({ // 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); } }); diff --git a/test/books/conrefs/README.md b/test/books/conrefs/README.md index 7f56eed..cf15b87 100644 --- a/test/books/conrefs/README.md +++ b/test/books/conrefs/README.md @@ -3,8 +3,9 @@ ### Relative <p id="t1">{% include "./hello.md" %}</p> +<p id="t2">{% include "/hello.md" %}</p> ### Git -<p id="t2">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}</p> -<p id="t3">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}</p> +<p id="t3">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}</p> +<p id="t4">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}</p> diff --git a/test/conrefs.js b/test/conrefs.js index 8d6a181..281fb1c 100644 --- a/test/conrefs.js +++ b/test/conrefs.js @@ -26,14 +26,24 @@ describe('ConRefs', function () { }); }); - it('should handle git references', function() { + it('should handle local references with absolute paths', function() { readme.should.be.html({ ".page-inner p#t2": { count: 1, + text: "Hello World", + trim: true + } + }); + }); + + it('should handle git references', function() { + readme.should.be.html({ + ".page-inner p#t3": { + count: 1, text: "Hello from git", trim: true }, - ".page-inner p#t3": { + ".page-inner p#t4": { count: 1, text: "First Hello. Hello from git", trim: true |