Skip to content
Myr

Added res.locals(obj)

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 723c908 · Browse files · 4 files+28 added−7 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+28 added−7 removed

  • tests:+1 added−2 removed
  • other:+27 added−5 removed

4 files+28 added−7 removed

modified:docs/guide.md+9 added
1005 unmodified lines
1006 // can pass more if we wish1007 res.render('movie', { displayReviews: true });1008 });10091010### res.local(obj)10111012 Assign several locals with the given _obj_. The following are equivalent:1013 1014 res.local('foo', bar);1015 res.local('bar', baz);10161017 res.locals({ foo: bar, bar, baz });10181019### app.set(name[, val])10201021Apply an application level setting _name_ to _val_, or1022get the value of _name_ when _val_ is not present:
207 unmodified lines
modified:lib/response.js+16 added-3 removed
376 unmodified lines
377 * @api public378 */379380res.local = function(name, val){381 this.locals = this.locals || {};381 this._locals = this._locals || {};382 return undefined === val383 ? this.locals[name]384 : this.locals[name] = val;383 ? this._locals[name]384 : this._locals[name] = val;385};386387/**388 * Assign several locals with the given `obj`.389 *390 * @param {Object} obj391 * @return {ServerResponse} for chaining392 * @api public393 */394395res.locals = function(obj){396 for (var key in obj) this.local(key, obj[key]);397 return this;398};
modified:lib/view.js+2 added-2 removed
223 unmodified lines
224225 // merge "view options"226 if (viewOptions) merge(options, viewOptions);227228 // merge res.locals229 if (this.locals) merge(options, this.locals);228 // merge res._locals229 if (this._locals) merge(options, this._locals);230231 // merge render() options232 if (opts) merge(options, opts);233
132 unmodified lines
modified:test/view.test.js+1 added-2 removed
588 unmodified lines
589 { url: '/stats/callback' },590 { body: 'got: <p>Hits 12</p><p>Misses 1</p>' });591592 app.get('/stats/callback/2', function(req, res){593 res.local('hits', 12);594 res.local('misses', 1);593 res.locals({ hits: 12, misses: 1 });594 res.partial('stats', function(err, html){595 res.send('got: ' + html);596 });597 });
427 unmodified lines