-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
43 lines (34 loc) · 1.12 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
Hogan = require('hogan.js'),
path = require('path'),
through = require('through2');
var defaultExtensions = ['.hogan', '.mustache', '.ms'];
module.exports = function hoganify (file, options) {
var extensions = defaultExtensions.concat(options.ext &&
options.ext.split(',') || []);
if (extensions.indexOf(path.extname(file)) === -1) {
return through();
}
var buffer = '';
function write (chunk, enc, next) {
buffer += chunk;
next();
}
function end () {
var
template = null,
text = JSON.stringify(buffer),
compiled = '';
compiled += "var Hogan = require('hogan.js');\n";
if (options.live) {
compiled += "module.exports = Hogan.compile(" + text + ");";
}
else {
template = Hogan.compile(buffer, { asString: true });
compiled += "module.exports = new Hogan.Template(" + template + ", " + text + ", Hogan);";
}
this.push(compiled);
this.push(null);
}
return through(write, end);
};