-
Notifications
You must be signed in to change notification settings - Fork 24
/
jadeify.js
42 lines (33 loc) · 1.08 KB
/
jadeify.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
"use strict";
var through = require("through");
var jade = require("jade");
module.exports = function (fileName, options) {
if (!/\.jade$/i.test(fileName)) {
return through();
}
options.runtimePath = options.runtimePath === undefined ? "jade/runtime" : options.runtimePath;
var inputString = "";
return through(
function (chunk) {
inputString += chunk;
},
function () {
var self = this;
options.filename = fileName;
var result;
try {
result = jade.compileClientWithDependenciesTracked(inputString, options);
} catch (e) {
self.emit("error", e);
return;
}
result.dependencies.forEach(function (dep) {
self.emit("file", dep);
});
var moduleBody = "var jade = require(\"" + options.runtimePath + "\");\n\n" +
"module.exports = " + result.body + ";";
self.queue(moduleBody);
self.queue(null);
}
);
};