blob: fbf39d34e5f5390ee82a95e7db2312bc61aafdea (
plain)
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
|
var Immutable = require('immutable');
var TemplateEngine = require('../models/templateEngine');
var ConrefsLoader = require('./loaders/conrefs');
var defaultBlocks = require('../constants/defaultBlocks');
var defaultFilters = require('../constants/defaultFilters');
/**
Create template engine for an output.
It adds default filters/blocks, then add the ones from plugins
@param {Output} output
@return {TemplateEngine}
*/
function createTemplateEngine(output) {
var plugins = output.getPlugins();
var filters = plugins
.reduce(function(result, plugin) {
return result.merge(plugin.getFilters());
}, Immutable.Map());
var blocks = plugins
.map(function(plugin) {
return plugin.getBlocks();
})
.flatten(1);
// Extend with default
blocks = defaultBlocks.concat(blocks);
filters = defaultFilters.merge(filters);
var loader = new ConrefsLoader();
return new TemplateEngine({
filters: filters,
blocks: blocks,
loader: loader
});
}
module.exports = createTemplateEngine;
|