1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
var path = require('path');
var TemplateEngine = require('../../models/templateEngine');
var renderTemplate = require('../render');
var ConrefsLoader = require('../conrefsLoader');
describe('ConrefsLoader', function() {
var dirName = __dirname + '/';
var fileName = path.join(dirName, 'test.md');
describe('Git', function() {
var engine = TemplateEngine({
loader: new ConrefsLoader(dirName)
});
it('should include content from git', function() {
return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello from git');
});
});
it('should handle deep inclusion (1)', function() {
return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('First Hello. Hello from git');
});
});
it('should handle deep inclusion (2)', function() {
return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('First Hello. Hello from git');
});
});
});
describe('Local', function() {
var engine = TemplateEngine({
loader: new ConrefsLoader(dirName)
});
describe('Relative', function() {
it('should resolve basic relative filepath', function() {
return renderTemplate(engine, fileName, '{% include "include.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello World');
});
});
it('should resolve basic parent filepath', function() {
return renderTemplate(engine, path.join(dirName, 'hello/test.md'), '{% include "../include.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello World');
});
});
});
describe('Absolute', function() {
it('should resolve absolute filepath', function() {
return renderTemplate(engine, fileName, '{% include "/include.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello World');
});
});
it('should resolve absolute filepath when in a directory', function() {
return renderTemplate(engine, path.join(dirName, 'hello/test.md'), '{% include "/include.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello World');
});
});
});
});
describe('transform', function() {
function transform(filePath, source) {
expect(filePath).toBeA('string');
expect(source).toBeA('string');
expect(filePath).toBe(path.resolve(__dirname, 'include.md'));
expect(source).toBe('Hello World');
return 'test-' + source + '-endtest';
}
var engine = TemplateEngine({
loader: new ConrefsLoader(dirName, transform)
});
it('should transform included content', function() {
return renderTemplate(engine, fileName, '{% include "include.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('test-Hello World-endtest');
});
});
});
});
|