-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrapper.js
38 lines (24 loc) · 899 Bytes
/
wrapper.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
// Jade 'HTML' wrapper for SocketStream 0.3
var fs = require('fs'),
jade = require('jade');
exports.init = function(root, config) {
if (!(config && typeof(config) === 'object')) config = {};
return {
name: 'Jade',
extensions: ['jade'],
assetType: 'html',
contentType: 'text/html',
compile: function(path, options, cb) {
var locals = {};
// Merge any locals passed to config.locals
if (config.locals && typeof(config.locals) === 'object')
for (var attrname in config.locals) { locals[attrname] = config.locals[attrname]; }
// If passing optional headers for main view HTML
if (options && options.headers) locals['SocketStream'] = options.headers;
var input = fs.readFileSync(path, 'utf8');
var parser = jade.compile(input, {filename: path});
var output = parser(locals);
cb(output);
}
};
};