Skip to content
Myr

Added res.render() callback support as second argument

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

This previously was not valid: res.render(foo, function(){});

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0b4388b · Browse files · 2 files+15 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

2 files+15 added−1 removed

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

2 files+15 added−1 removed

modified:lib/express/view.js+6 added-1 removed
147 unmodified lines
148 * - `locals` Object containing local variables149 * - `debug` Output debugging information150 *151 * @param {String} view152 * @param {Object} options152 * @param {Object|Function} options or callback function153 * @param {Function} fn154 * @api public155 */156157http.ServerResponse.prototype.render = function(view, options, fn){158 // Support callback function as second arg159 if (typeof options === 'function') {160 fn = options, options = {};161 }162 163 var options = options || {},164 viewOptions = this.app.set('view options'),165 defaultEngine = this.app.set('view engine');166
112 unmodified lines
modified:test/view.test.js+9 added
25 unmodified lines
26 });27 app.get('/haml', function(req, res){28 res.render('hello.haml', { layout: false });29 });30 app.get('/callback/layout/no-options', function(req, res){31 res.render('hello.jade', function(err, str){32 assert.ok(!err);33 res.send(str.replace(':(', ':)'));34 });35 });36 app.get('/callback/layout', function(req, res){37 res.render('hello.jade', {}, function(err, str){38 assert.ok(!err);39 res.send(str.replace(':(', ':)'));
40 unmodified lines
80 assert.response(app,81 { url: '/callback/layout' },82 { body: '<html><body><p>:)</p></body></html>' });83 assert.response(app,84 { url: '/callback/layout/no-options' },85 { body: '<html><body><p>:)</p></body></html>' });86 assert.response(app,87 { url: '/error' },88 { body: 'doesNotExist' });89 assert.response(app,90 { url: '/invalid' },
354 unmodified lines