Skip to content
Myr

Added extending of flash formatters via app.flashFormatters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent a4d155c · Browse files · 3 files+15 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−4 removed

  • tests:+9 added−0 removed
  • other:+6 added−4 removed

3 files+15 added−4 removed

modified:lib/express/index.js+1 added-1 removed
modified:lib/express/request.js+5 added-3 removed
172 unmodified lines
173http.IncomingMessage.prototype.flash = function(type, msg){174 var msgs = this.session.flash = this.session.flash || {};175 if (type && msg) {176 var i = 2,177 args = arguments;177 args = arguments,178 formatters = this.app.flashFormatters || {};179 formatters.__proto__ = flashFormatters;180 msg = utils.miniMarkdown(utils.htmlEscape(msg));181 msg = msg.replace(/%([a-zA-Z])/g, function(_, format){180 format = flashFormatters[format];181 if (format) return format(args[i++]);182 var formatter = formatters[format];183 if (formatter) return formatter(args[i++]);184 });185 return (msgs[type] = msgs[type] || []).push(msg);186 } else if (type) {187 var arr = msgs[type];
23 unmodified lines
modified:test/request.test.js+9 added
115 unmodified lines
116 connect.cookieDecoder(),117 connect.session({ store: memoryStore })118 );119120 app.flashFormatters = {121 u: function(val){122 return String(val).toUpperCase();123 }124 };125126 app.get('/', function(req, res){127 assert.eql([], req.flash('info'));128 assert.eql([], req.flash('error'));129 assert.eql({}, req.flash());
13 unmodified lines
143 144 req.flash('info', 'Welcome _%s_ to %s', 'TJ', 'something');145 assert.eql(['Welcome <em>TJ</em> to something'], req.flash('info'));146147 req.flash('info', 'Foo %u', 'bar');148 assert.eql(['Foo BAR'], req.flash('info'));149150 res.send('ok');151 });152 153 assert.response(app,
4 unmodified lines