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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
var path = require('path');
var _ = require('lodash');
var assert = require('assert');
var fs = require("fs");
var Plugin = require("../lib/plugin");
var PLUGINS_ROOT = path.resolve(__dirname, "plugins");
describe('Plugins', function () {
describe('invalid plugin', function() {
it('should signal as invalid', function() {
var plugin = new Plugin(books[0], "invalid");
plugin.load("./invalid", PLUGINS_ROOT);
assert(!plugin.isValid());
});
});
describe('empty plugin', function() {
var plugin = new Plugin(books[0], "invalid");
plugin.load("./empty", PLUGINS_ROOT);
it('should valid a plugin', function() {
assert(plugin.isValid());
});
it('should return an empty list of resources', function(done) {
qdone(
plugin.getResources()
.then(function(resources) {
_.each(Plugin.RESOURCES, function(resName) {
assert.equal(resources[resName].length, 0);
});
}),
done);
});
});
describe('resources plugin', function() {
var plugin = new Plugin(books[0], "resources");
plugin.load("./resources", PLUGINS_ROOT);
before(function(done) {
qdone(books[0].plugins.load(plugin), done);
});
it('should valid a plugin', function() {
assert(plugin.isValid());
});
it('should return a valid list of resources', function(done) {
qdone(
plugin.getResources()
.then(function(resources) {
assert.equal(resources["js"].length, 1);
}),
done);
});
it('should extend books plugins', function() {
var resources = books[0].plugins.resources;
assert.equal(resources["js"].length, 1);
});
});
describe('filters', function() {
var plugin = new Plugin(books[0], "filters");
plugin.load("./filters", PLUGINS_ROOT);
before(function(done) {
qdone(books[0].plugins.load(plugin), done);
});
it('should valid a plugin', function() {
assert(plugin.isValid());
});
it('should return a map of filters', function() {
var filters = plugin.getFilters();
assert.equal(_.size(filters), 2);
assert(filters["hello"]);
assert(filters["helloCtx"]);
});
it('should correctly extend template filters', function(done) {
qdone(
books[0].template.renderString('{{ "World"|hello }}')
.then(function(content) {
assert.equal(content, "Hello World");
}),
done
);
});
it('should correctly set book as context', function(done) {
qdone(
books[0].template.renderString('{{ "root"|helloCtx }}')
.then(function(content) {
assert.equal(content, "root:"+books[0].root);
}),
done
);
});
});
describe('blocks', function() {
var plugin = new Plugin(books[0], "blocks");
plugin.load("./blocks", PLUGINS_ROOT);
var testTpl = function(str, args, options) {
return books[0].template.renderString(str, args, options)
.then(books[0].template.postProcess)
};
before(function(done) {
qdone(books[0].plugins.load(plugin), done);
});
it('should valid a plugin', function() {
assert(plugin.isValid());
});
it('should correctly extend template blocks', function(done) {
qdone(
testTpl('{% test %}hello{% endtest %}')
.then(function(content) {
assert.equal(content, "testhellotest");
}),
done
);
});
it('should correctly accept shortcuts', function(done) {
qdone(
testTpl('$$hello$$', {}, {
type: "markdown"
})
.then(function(content) {
assert.equal(content, "testhellotest");
}),
done
);
});
it('should correctly extend template blocks with defined end', function(done) {
qdone(
testTpl('{% test2 %}hello{% endtest2end %}')
.then(function(content) {
assert.equal(content, "test2hellotest2");
}),
done
);
});
it('should correctly extend template blocks with sub-blocks', function(done) {
qdone(
testTpl('{% test3join separator=";" %}hello{% also %}world{% endtest3join %}')
.then(function(content) {
assert.equal(content, "hello;world");
}),
done
);
});
it('should correctly extend template blocks with different sub-blocks', function(done) {
qdone(
testTpl('{% test4join separator=";" %}hello{% also %}the{% finally %}world{% endtest4join %}')
.then(function(content) {
assert.equal(content, "hello;the;world");
}),
done
);
});
});
});
|