forked from latentflip/domthingify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domthingify.js
33 lines (27 loc) · 938 Bytes
/
domthingify.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
var through = require('through');
var domthing = require('domthing');
module.exports = function (fileName) {
if (!/\.dom$/i.test(fileName)) {
return through();
}
var inputString = '';
return through(
function (chunk) {
inputString += chunk;
},
function () {
domthing.parser(inputString, function (err, ast) {
if (err) return this.emit('error', err);
var compiled = domthing.compiler.compile(ast);
var moduleBody = [
"var _runtime = require('domthing/runtime');",
"module.exports = function (template, runtime) {",
" return " + compiled + "(template, runtime || _runtime);",
"}"
].join('\n');
this.queue(moduleBody);
this.queue(null);
}.bind(this));
}
);
};