-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (29 loc) · 817 Bytes
/
index.js
File metadata and controls
36 lines (29 loc) · 817 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
'use strict';
const gutil = require('gulp-util');
const through = require('through2');
const cedr = require('cedr');
module.exports = (options) => {
let opts = Object.assign({}, options);
let library = opts.library || {};
let evalContext = {};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-cedr', 'Streaming not supported'));
return;
}
if (file.isBuffer()) {
let pageJs = eval.call(evalContext, file.contents.toString());
let html = cedr(pageJs, library);
if (html !== '') {
file.contents = new Buffer(html);
file.path = gutil.replaceExtension(file.path, '.html');
this.push(file);
}
}
cb();
});
};