-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (38 loc) · 1.09 KB
/
index.js
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 gutil = require('gulp-util');
var through = require('through2');
var dot = require('dot');
module.exports = render;
function render (data, options) {
options = options || {
evaluate: /\{\{([\s\S]+?)\}\}/g,
interpolate: /\{\{=([\s\S]+?)\}\}/g,
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g,
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
varname: 'it',
strip: false,
append: true,
selfcontained: false
};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-dot-template', 'Streaming not supported!'));
return;
}
try {
var renderer = dot.template(file.contents.toString(), options);
var rendered = renderer(data);
file.contents = new Buffer(rendered);
this.push(file);
} catch (error) {
this.emit('error', new gutil.PluginError('gulp-dot-template', error, { file: file.path }));
}
cb();
});
}