Skip to content

Commit

Permalink
Added res.render() callback support as second argument
Browse files Browse the repository at this point in the history
This previously was not valid:

    res.render(foo, function(){});
  • Loading branch information
tj committed Aug 11, 2010
1 parent 0b4388b commit f7f7592
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/express/view.js
Expand Up @@ -149,12 +149,17 @@ http.ServerResponse.prototype.partial = function(view, options, ext){
* - `debug` Output debugging information
*
* @param {String} view
* @param {Object} options
* @param {Object|Function} options or callback function
* @param {Function} fn
* @api public
*/

http.ServerResponse.prototype.render = function(view, options, fn){
// Support callback function as second arg
if (typeof options === 'function') {
fn = options, options = {};
}

var options = options || {},
viewOptions = this.app.set('view options'),
defaultEngine = this.app.set('view engine');
Expand Down
9 changes: 9 additions & 0 deletions test/view.test.js
Expand Up @@ -27,6 +27,12 @@ module.exports = {
app.get('/haml', function(req, res){
res.render('hello.haml', { layout: false });
});
app.get('/callback/layout/no-options', function(req, res){
res.render('hello.jade', function(err, str){
assert.ok(!err);
res.send(str.replace(':(', ':)'));
});
});
app.get('/callback/layout', function(req, res){
res.render('hello.jade', {}, function(err, str){
assert.ok(!err);
Expand Down Expand Up @@ -74,6 +80,9 @@ module.exports = {
assert.response(app,
{ url: '/callback/layout' },
{ body: '<html><body><p>:)</p></body></html>' });
assert.response(app,
{ url: '/callback/layout/no-options' },
{ body: '<html><body><p>:)</p></body></html>' });
assert.response(app,
{ url: '/error' },
{ body: 'doesNotExist' });
Expand Down

0 comments on commit f7f7592

Please sign in to comment.