forked from Wildhoney/gulp-processhtml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·47 lines (31 loc) · 1.16 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
44
45
46
47
var through = require('through2'),
gutil = require('gulp-util'),
path = require('path'),
HTMLProcessor = require('htmlprocessor'),
PluginError = gutil.PluginError;
module.exports = function(options) {
options = options || {};
if (!options.customBlockTypes) {
options.customBlockTypes = [];
}
// Add some custom block types.
options.customBlockTypes.push(path.join(__dirname, 'custom/replace.js'));
var processor = new HTMLProcessor(options),
content = '';
function processContent(file, enc, cb) {
if (file.isStream()) {
this.emit('error', new PluginError('gulp-processhtml', 'Streams aren\'t supported'));
return cb();
}
if (file.isBuffer()) {
content = processor.processContent(file.contents.toString(enc), file.path);
if (options && options.process) {
content = processor.template(content, processor.data, options.templateSettings);
}
file.contents = new Buffer(content, enc);
}
this.push(file);
cb();
}
return through.obj(processContent);
};