Skip to content
Myr

Merge branch 'flash-formatting'

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 · parents bb18f87, 192144f · Browse files · 3 files+44 added−1 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+44 added−1 removed

  • tests:+13 added−0 removed
  • other:+31 added−1 removed

3 files+44 added−1 removed

modified:lib/express/index.js+1 added-1 removed
modified:lib/express/request.js+30 added
12 unmodified lines
13 utils = require('./utils'),14 mime = require('connect/utils').mime;1516/**17 * Default flash formatters.18 *19 * @type Object20 */2122var flashFormatters = exports.flashFormatters = {23 s: function(val){24 return String(val);25 }26};2728/**29 * Return request header or optional default.30 *31 * Examples:32 *
120 unmodified lines
153 *154 * req.flash();155 * // => { error: ['email delivery failed'], info: [] }156 *157 * Formatting:158 *159 * Flash notifications also support arbitrary formatting support.160 * For example you may pass variable arguments to `req.flash()`161 * and use the %s specifier to be replaced by the associated argument:162 *163 * req.flash('info', 'email has been sent to %s.', userName);164 *165 * To add custom formatters use the `exports.flashFormatters` object.166 *167 * @param {String} type168 * @param {String} msg169 * @return {Array|Object|Number}170 * @api public
1 unmodified line
172173http.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,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){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];188 delete msgs[type];
22 unmodified lines
modified:test/request.test.js+13 added