summaryrefslogtreecommitdiffstats
path: root/lib/templating
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-04-30 20:06:43 +0200
committerSamy Pesse <samypesse@gmail.com>2016-04-30 20:06:43 +0200
commitb51470db398e7da090805da666d2a6cc9c0b3deb (patch)
tree6b5750cdba1f6b6300b671db95b2521fc5087007 /lib/templating
parenta5f4596f8d863d8eb7061ef50f78346bde25d7ac (diff)
downloadgitbook-b51470db398e7da090805da666d2a6cc9c0b3deb.zip
gitbook-b51470db398e7da090805da666d2a6cc9c0b3deb.tar.gz
gitbook-b51470db398e7da090805da666d2a6cc9c0b3deb.tar.bz2
Add tests for conrefs loader
Diffstat (limited to 'lib/templating')
-rw-r--r--lib/templating/__tests__/conrefsLoader.js34
-rw-r--r--lib/templating/conrefsLoader.js4
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/templating/__tests__/conrefsLoader.js b/lib/templating/__tests__/conrefsLoader.js
new file mode 100644
index 0000000..3480a48
--- /dev/null
+++ b/lib/templating/__tests__/conrefsLoader.js
@@ -0,0 +1,34 @@
+var TemplateEngine = require('../../models/templateEngine');
+var renderTemplate = require('../render');
+
+describe('ConrefsLoader', function() {
+ var ConrefsLoader = require('../conrefsLoader');
+
+ var engine = TemplateEngine({
+ loader: new ConrefsLoader(__dirname)
+ });
+
+ describe('Git', function() {
+ pit('should include content from git', function() {
+ return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
+ .then(function(str) {
+ expect(str).toBe('Hello from git');
+ });
+ });
+
+ pit('should handle deep inclusion (1)', function() {
+ return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
+ .then(function(str) {
+ expect(str).toBe('First Hello. Hello from git');
+ });
+ });
+
+ pit('should handle deep inclusion (2)', function() {
+ return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
+ .then(function(str) {
+ expect(str).toBe('First Hello. Hello from git');
+ });
+ });
+ });
+});
+
diff --git a/lib/templating/conrefsLoader.js b/lib/templating/conrefsLoader.js
index e46b4d0..c3e5048 100644
--- a/lib/templating/conrefsLoader.js
+++ b/lib/templating/conrefsLoader.js
@@ -48,9 +48,9 @@ var ConrefsLoader = nunjucks.Loader.extend({
resolve: function(from, to) {
// If origin is in the book, we enforce result file to be in the book
- if (PathUtils.isInRoot(this.root, from)) {
+ if (PathUtils.isInRoot(this.rootFolder, from)) {
var href = LocationUtils.toAbsolute(to, path.dirname(from), '');
- return PathUtils.resolveInRoot(this.root, href);
+ return PathUtils.resolveInRoot(this.rootFolder, href);
}
// If origin is in a git repository, we resolve file in the git repository