-
Notifications
You must be signed in to change notification settings - Fork 0
/
lasso-jade-plugin.js
54 lines (47 loc) · 1.79 KB
/
lasso-jade-plugin.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
var fs = require('fs');
var jade = require('jade');
function compileFile(path, callback) {
fs.readFile(path, 'utf8', function(err, src) {
if (err) {
return callback(err);
}
callback(null, 'module.exports=function(jade) { return ' + jade.compileClient(src) + '\n};');
});
}
module.exports = function(lasso, config) {
['jade'].forEach(function(ext) {
lasso.dependencies.registerRequireType(
ext,
{
properties: {
'path': 'string'
},
init: function(lassoContext, callback) {
if (!this.path) {
const pathError = new Error('"path" is required for a Jade dependency');
if (callback) return callback(pathError);
throw pathError;
}
this.path = this.resolvePath(this.path);
if (callback) callback();
},
read: function(lassoContext, callback) {
if (callback) {
compileFile(this.path, callback);
} else {
return new Promise((resolve, reject) => {
compileFile(this.path, (err, res) => {
return err ? reject(err) : resolve(res);
});
});
}
},
getSourceFile: function() {
return this.path;
},
getLastModified: function(lassoContext, callback) {
return lassoContext.getFileLastModified(this.path, callback);
}
});
});
};