Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added flash to the locals w/connect-flash #2

Merged
merged 1 commit into from

2 participants

Scott Tesoriere Pavan Kumar Sunkara
Scott Tesoriere

I guess you didn't really need connect-flash, but it was easier.

As an aside, do you plan on writing something like this for flatiron?

Pavan Kumar Sunkara
Owner

lgtm, but what about multiple flash messages?

Yes, I plan something like this for flatiron too. This module already uses director, nconf, resourceful from flatiron.

Scott Tesoriere

I added support for multiple flash messages, I look forward to trying out flatiron more, the RVP proposal was interesting.

Pavan Kumar Sunkara pksunkara merged commit 660400c into from
Pavan Kumar Sunkara
Owner

Done.

@scottkf Thanks. Do you have any more ideas or suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 22, 2012
  1. Scott Tesoriere
This page is out of date. Refresh to see the latest.
3  example/app/controllers/posts.js
View
@@ -46,6 +46,9 @@ module.exports = {
self.req.body.post.isNewRecord = false;
self.res.render('posts/edit', { post: self.req.body.post, errs: err });
} else {
+ self.req.flash("success", 'Updated!')
+ self.req.flash("info", 'Hey, there are multiple messages!')
+ self.req.flash("An example")
self.res.redirect(app.r.post_path(data.id));
}
});
1  lib/bullet.js
View
@@ -23,6 +23,7 @@ bullet.init = function (app, pwd) {
app.views = path.join(pwd, 'app', 'views');
app.session = app.config.get('session');
+ app.flash = require('./flash');
require('./error')(app);
require('./model')(app, pwd);
11 lib/flash.js
View
@@ -0,0 +1,11 @@
+module.exports = function (type, msg) {
+ var msgs = this.session.flash = this.session.flash || [];
+ if (type && msg) {
+ msgs.push({type:type, msg:msg})
+ } else if (type) {
+ msgs.push({type:'info', msg:type})
+ } else {
+ this.session.flash = []
+ }
+ return msgs
+};
4 lib/helper.js
View
@@ -4,7 +4,7 @@ var path = require('path')
module.exports = function (app, pwd) {
- var locals = { r: app.r, flash: null, errs: {} };
+ var locals = { r: app.r, errs: {} };
var dir = path.join(pwd, 'app/helpers');
var files = fs.readdirSync(dir);
@@ -80,6 +80,8 @@ module.exports = function (app, pwd) {
app.helpers = function (req, res, next) {
res.locals = locals;
+ req.flash = app.flash;
+ res.locals.flash = req.flash();
next();
};
};
13 lib/template/app/views/layout.jade
View
@@ -23,12 +23,13 @@ html
a.brand(href='/') bullet
.nav-collapse
.container-fluid
- - if (flash)
- .row-fluid
- .span12
- .alert(class='alert-#{flash.type}')
- a.close(href='#', data-dismiss='alert') ×
- = flash.msg
+ if (flash)
+ each msg in flash
+ .row-fluid
+ .span12
+ .alert(class='alert-#{msg['type']}')
+ a.close(href='#', data-dismiss='alert') ×
+ = msg['msg']
.row-fluid
.span12
block content
Something went wrong with that request. Please try again.