forked from visionmedia/express-messages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (28 loc) · 763 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
/*!
* Express - Contrib - messages
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
module.exports = function(req, res){
return function(){
var buf = []
, messages = req.flash()
, types = Object.keys(messages)
, len = types.length;
if (!len) return '';
for (var i = 0; i < len; ++i) {
var type = types[i]
, msgs = messages[type];
if (msgs) {
buf.push(' <div class="alert-message ' + type + '">');
buf.push(' <a class="close" href="#">x</a>');
for (var j = 0, l = msgs.length; j < l; ++j) {
var msg = msgs[j];
buf.push(' <p>' + msg + '</p>');
}
buf.push(' </div>');
}
}
return buf.join('\n');
}
};