Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('../../lib/express'); | ||
|
||
// App with session support | ||
|
||
var app = express.createServer( | ||
express.cookieDecoder(), | ||
express.session() | ||
); | ||
|
||
// View settings | ||
|
||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'ejs'); | ||
|
||
// | ||
|
||
app.dynamicHelpers({ | ||
messages: function(req, res){ | ||
var types = req.flash(), | ||
keys = Object.keys(types), | ||
len = keys.length; | ||
if (len) { | ||
return '<div id="messages">' + keys.map(function(key){ | ||
var msgs = types[key]; | ||
return '<ul id="messages-' + key + '">' + msgs.map(function(msg){ | ||
return '<li>' + msg + '</li>'; | ||
}).join('\n') + '</ul>'; | ||
}).join('\n') + '</div>'; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
}); | ||
|
||
app.get('/', function(req, res){ | ||
// Not very realistic notifications but illustrates usage | ||
req.flash('info', 'email queued'); | ||
req.flash('info', 'email sent'); | ||
req.flash('error', 'delivery failed'); | ||
res.render('index'); | ||
}); | ||
|
||
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Flash Message Example</h1> | ||
<%- messages %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<%- body %> | ||
</body> | ||
</html> |