-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.js
43 lines (39 loc) · 1018 Bytes
/
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
/*!
* Express - Contrib - messages
* Copyright(c) 2010 TJ Holowaychuk <[email protected]>
* MIT Licensed
*/
module.exports = function (req, res) {
return function (template, locals) {
var flash = req.flash()
, types = Object.keys(flash)
, output = '';
if (types.length) {
if (template) {
locals = locals || {};
locals.messages = flash;
res.render(template, locals, function (err, html) {
if (html) {
output = html;
}
});
} else {
var buf = [];
buf.push('<div id="messages">');
types.forEach(function (type) {
var msgs = flash[type];
if (msgs) {
buf.push(' <ul class="' + type + '">');
msgs.forEach(function (msg) {
buf.push(' <li>' + msg + '</li>');
});
buf.push(' </ul>');
}
});
buf.push('</div>');
output = buf.join('\n');
}
}
return output;
};
};