Merge branch 'flash'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents 99789c3, 9727fac · Browse files · 4 files·+88 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+88 added−0 removed
- tests:+33 added−0 removed
- other:+55 added−0 removed
Provenance
- Commit
3863a76- Tree
7e74f09- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
99789c3- Parent 2
9727fac
4 files changed+88 added−0 removed
added:lib/express/plugins/flash.js+54 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
// Express - Flash - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.Flash = Plugin.extend({ extend: { /** * Initialize extensions. */ init: function(){ Request.include({ /** * Get / set flash _key_ and _val_. * * When a flash _key_ and _val_ are present, * it will persist in the session until outputted. * The _val_ pushed is returned. * * Example: * * this.flash('info') * // => [] * * this.flash('info', 'email sent') * this.flash('info', 'email received') * this.flash('info') * // => ['email sent', 'email received'] * * this.flash('info') * // => [] * * @param {string} key * @param {string} val * @return {string} * @api public */ flash: function(key, val) { if (!this.session.flash) this.session.flash = {} if (!(key in this.session.flash)) this.session.flash[key] = [] if (val) return this.session.flash[key].push(val), val else if (key) { var vals = this.session.flash[key] delete this.session.flash[key] return vals } } }) } }})No newline at end of filemodified:lib/express/plugins.js+1 added
1234567893 unmodified lines
// Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
process.mixin(require('express/plugins/hooks'))process.mixin(require('express/plugins/flash'))process.mixin(require('express/plugins/cache'))process.mixin(require('express/plugins/cookie'))process.mixin(require('express/plugins/session'))process.mixin(require('express/plugins/profiler'))3 unmodified linesmodified:spec/node.js+1 added
41 unmodified lines42434445464748495019 unmodified lines41 unmodified lines 'plugins.redirect', 'plugins.hooks', 'plugins.cookie', 'plugins.session', 'plugins.flash', ], dependant: [ 'element-collection' ]19 unmodified linesadded:spec/spec.plugins.flash.js+32 added
1234567891011121314151617181920212223242526272829303132
describe 'Express' before_each reset() use(require('express/plugins/cookie').Cookie) use(require('express/plugins/session').Session) use(require('express/plugins/flash').Flash) Session.store.clear() end describe 'Flash' describe 'flash()' it 'should push a flash message' var headers = { headers: { cookie: 'sid=123' }} post('/', function(){ return this.flash('info', 'email sent') }) get('/', function(){ return this.flash('info', 'email received') }) get('/info', function(){ return this.flash('info').join(', ') || 'empty' }) get('/messages', function(){ return this.flash('info').join(', ') || 'empty' }) post('/', headers).body.should.eql 'email sent' get('/', headers).body.should.eql 'email received' get('/info', headers).body.should.eql 'email sent, email received' // TODO: seperate once segfault is fixed... end it 'should return the message pushed' get('/', function(){ return this.flash('info', 'email sent') }) get('/').body.should.eql 'email sent' end end endendNo newline at end of file