Skip to content
Myr

Merge branch 'perf/cache-dynamicHelpers'

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 b083aed, 65d9f78 · Browse files · 2 files+25 added−13 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+25 added−13 removed

  • tests:+9 added−4 removed
  • other:+16 added−9 removed

2 files+25 added−13 removed

modified:lib/express/view.js+16 added-9 removed
238 unmodified lines
239 options.locals.__filename = options.filename = path;240241 // Dynamic helper support242 if (options.dynamicHelpers !== false) {243 // cache244 if (!this.__dynamicHelpers) {245 this.__dynamicHelpers = {};243 var keys = Object.keys(dynamicHelpers);244 for (var i = 0, len = keys.length; i < len; ++i) {245 var key = keys[i],246 val = dynamicHelpers[key];247 if (typeof val === 'function') {248 helpers[key] = val.call(249 this.app, 250 this.req, 251 this);246 var keys = Object.keys(dynamicHelpers);247 for (var i = 0, len = keys.length; i < len; ++i) {248 var key = keys[i],249 val = dynamicHelpers[key];250 if (typeof val === 'function') {251 this.__dynamicHelpers[key] = val.call(252 this.app, 253 this.req, 254 this);255 }256 }257 }258259 // apply260 utils.merge(helpers, this.__dynamicHelpers);261 }262263 // Always expose partial() as a local264 options.locals.partial = function(view, options){
45 unmodified lines
modified:test/view.test.js+9 added-4 removed
242 unmodified lines
243 'Content-Type': 'text/html; charset=utf-8'244 }});245 },246 247 'test #render() view helpers': function(assert){248 var app = create();247 'test #render() view helpers': function(assert, beforeExit){248 var app = create(),249 calls = 0;250251 app.helpers({ 252 lastName: 'holowaychuk',253 greetings: function(sess, lastName){
2 unmodified lines
256 });257258 var ret = app.dynamicHelpers({259 session: function(req, res){260 ++calls;261 assert.equal('object', typeof req, 'Test dynamic helper req');262 assert.equal('object', typeof res, 'Test dynamic helper res');263 assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');264 return req.session;
12 unmodified lines
277 });278 app.get('/precedence', function(req, res){279 req.session = { name: 'tj' };280 res.render('dynamic-helpers.jade', {279 layout: false,281 locals: {282 lastName: 'foobar'283 }284 });
6 unmodified lines
291 { url: '/ejs' },292 { body: '<p>Hello tj holowaychuk</p>' });293 assert.response(app,294 { url: '/precedence' },294 { body: '<p>Hello tj foobar</p>' });295 { body: '<html><body><p>Hello tj foobar</p></body></html>' });296297 beforeExit(function(){298 assert.equal(3, calls);299 });300 },301 302 'test #partial()': function(assert){303 var app = create();
203 unmodified lines