-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.js
42 lines (42 loc) · 1.06 KB
/
helpers.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
(function() {
var FlashMessage;
exports.helpers = {
nameAndVersion: function(name, version) {
return name + ' v' + version;
},
appName: 'Nodepad',
version: '0.1'
};
FlashMessage = (function() {
function FlashMessage(type, messages) {
this.type = type;
this.messages = messages;
}
FlashMessage.prototype.stateClass = function() {
switch (this.type) {
case 'info':
return 'success';
default:
return 'error';
}
};
FlashMessage.prototype.toHTML = function() {
return '<div class="alert-box ' + this.stateClass() + '">' + this.messages.join(', ') + '</div>';
};
return FlashMessage;
})();
exports.dynamicHelpers = {
flashMessages: function(req, res) {
var html;
html = '';
['error', 'info'].forEach(function(type) {
var messages;
messages = req.flash(type);
if (messages.length > 0) {
return html += new FlashMessage(type, messages).toHTML();
}
});
return html;
}
};
}).call(this);