-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (40 loc) · 1.1 KB
/
index.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
/*!
* Adds layout support in express for Parse
*
* @author Ion Caliman <[email protected]>
* @license MIT
*/
module.exports = function (req, res, next) {
var render = res.render;
res.render = function (view, options, fn) {
var layout, self = this, app = req.app,
defaultLayout = app.get('layout');
options = options || {};
if (typeof options === 'function') {
fn = options;
options = {};
}
if (options.layout === false || ((options.layout || defaultLayout) === false)) {
render.call(res, view, options, fn);
return;
}
layout = options.layout || defaultLayout;
if (layout === true || layout === undefined) {
layout = 'layout';
}
render.call(res, view, options, function (err, str) {
var l, locals;
if (err) { return fn ? fn(err) : next(err); }
locals = {
body: str
};
for (l in options) {
if (options.hasOwnProperty(l) && l !== 'layout' && l !== 'include') {
locals[l] = options[l];
}
}
render.call(self, layout, locals, fn);
});
};
next();
};