Skip to content
Myr

Removed `app.dynamicLocals()`. Closes #756

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 eab03fd · Browse files · 2 files+0 added−89 removed
This commit

State

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

Diff stats

2 files+0 added−89 removed

  • tests:+0 added−58 removed
  • other:+0 added−31 removed

2 files+0 added−89 removed

modified:lib/http.js-31 removed
62 unmodified lines
63 this.settings = {};64 this.redirects = {};65 this.isCallbacks = {};66 this._locals = {};67 this._dynamicLocals = {};6768 this.set('home', '/');69 this.set('env', process.env.NODE_ENV || 'development');70 this.use(connect.query());
231 unmodified lines
302 return this;303};304305/**307 * Register the given dynamic view locals `obj`. This method308 * can be called several times to apply additional locals.309 *310 * @param {Object} obj311 * @return {Server} for chaining312 * @api public313 */314315app.dynamicLocals = function(obj){316 for (var key in obj) {317 this.dynamicLocal(key, obj[key]);318 }319 return this;320};321322/**323 * Register a dynamic local with `name` and callback `fn(req, res)`.324 *325 * @param {String} name326 * @param {Object} fn327 * @return {Server} for chaining328 * @api public329 */330331app.dynamicLocal = function(name, fn){332 this._dynamicLocals[name] = fn;333 return this;334};335336/**306 * Map the given param placeholder `name`(s) to the given callback `fn`.307 *308 * Param mapping is used to provide pre-conditions to routes309 * which us normalized placeholders. This callback has the same
212 unmodified lines
modified:test/view.test.js-58 removed
312 unmodified lines
313 { url: '/' },314 { body: '<cool><p>Welcome</p></cool>' });315 },316 317 'test #render() view helpers': function(beforeExit){318 var app = create()319 , calls = 0;320 321 app.locals({322 lastName: 'holowaychuk'323 });324 325 app.locals({ 326 greetings: function(sess, lastName){327 return 'Hello ' + sess.name + ' ' + lastName; 328 }329 });330 331 var ret = app.dynamicLocals({332 session: function(req, res){333 ++calls;334 req.should.be.a('object');335 res.should.be.a('object');336 this.should.equal(app);337 return req.session;338 }339 });340 341 assert.equal(app, ret, 'Server#helpers() is not chainable');342 343 app.get('/', function(req, res){344 req.session = { name: 'tj' };345 res.render('dynamic-helpers.jade', { layout: false });346 });347 348 app.get('/ejs', function(req, res){349 req.session = { name: 'tj' };350 res.render('dynamic-helpers.ejs', { layout: false });351 });352 353 app.get('/precedence', function(req, res){354 req.session = { name: 'tj' };355 res.render('dynamic-helpers.jade', {356 lastName: 'foobar'357 });358 });359 360 assert.response(app,361 { url: '/' },362 { body: '<p>Hello tj holowaychuk</p>' });363 assert.response(app,364 { url: '/ejs' },365 { body: '<p>Hello tj holowaychuk</p>' });366 assert.response(app,367 { url: '/precedence' },368 { body: '<html><body><p>Hello tj foobar</p></body></html>' });369 370 beforeExit(function(){371 assert.equal(3, calls);372 });373 },374 317 'test #partial() collection object': function(){318 var app = create();319320 app.get('/', function(req, res){
733 unmodified lines