forked from rogeriopvl/gulp-ejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (31 loc) · 968 Bytes
/
Copy pathindex.js
File metadata and controls
38 lines (31 loc) · 968 Bytes
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
'use strict';
var through = require('through2');
var gutil = require('gulp-util');
var ejs = require('ejs');
//module.exports = function (options, settings) {
module.exports = function (_data, _options) {
var data = _data || {},
options = _options || {};
options.ext = typeof options.ext === 'undefined' ? '.html' : options.ext;
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit(
'error',
new gutil.PluginError('gulp-ejs', 'Streaming not supported')
);
}
data.filename = options.filename = file.path;
try {
file.contents = new Buffer(ejs.render(file.contents.toString(), data, options));
file.path = gutil.replaceExtension(file.path, options.ext);
} catch (err) {
this.emit('error', new gutil.PluginError('gulp-ejs', err.toString()));
}
this.push(file);
cb();
});
};