-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
59 lines (48 loc) · 1.66 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
48
49
50
51
52
53
54
55
56
57
58
59
const through = require('through2'),
PluginError = require('plugin-error');
includer = require('./lib/htmlincluder');
// @options = (optional) options for configuring htmlIncluder
// options.jsonInput = A json object used to populate data in files
// options.insertPattern = The test looked for in order to insert files
// (this is so ssi includes can be used instead)
// options.filePathAttribute = the name used for the file pathing for #insert
// and #wrap (default= 'path')
// options.jsonPathAttribute = the name used for the file pathing for #insert
// , #wrap, #data, #jsonInsert (default= 'jsonPath')
//
//
// options.dev.limitIterations = the number of times processFileWithJsonInput will loop
// options.dev.printIterations = console log each processFileWithJsonInput loop
// options.dev.printResult = console logs the final output
// options.dev.printPaths = console logs the output of buildPathFromRelativePath
//
module.exports = function (options) {
"use strict";
let that;
includer.initialize(options);
function htmlincluder() {
includer.buildFileResult(file => {
const f = file.file;
f.contents = Buffer.from(file.content);
that.push(f);
});
}
function aggregateFiles(file, enc, callback) {
that = this; //defined in scope of module
// Do nothing if no contents
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
this.emit("error",
new PluginError("gulp-htmlincluder", "Stream content is not supported"));
return callback();
}
if (file.isBuffer()) {
includer.hashFile(file);
}
return callback();
}
return through.obj(aggregateFiles, htmlincluder);
};