-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotExpressBridge.js
More file actions
35 lines (30 loc) · 809 Bytes
/
dotExpressBridge.js
File metadata and controls
35 lines (30 loc) · 809 Bytes
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
var dot = require('dot')
, fs = require('fs');
exports.__express = dotExpressBridge;
var cache = exports.cache = {};
function dotExpressBridge(path, options, callback) {
if( typeof options === 'function' ) {
callback = options;
options = {};
}
if( cache[path] ) {
try {
return callback(null, cache[path](options));
}
catch(err) {
return callback(err);
}
}
else {
fs.readFile(path, 'utf8', function(err, str) {
try {
cache[path] = dot.compile(str);
return callback(null, cache[path](options));
}
catch(err) {
return callback(err);
}
});
}
}
dot.__express = exports.__express;