Skip to content
Myr

request-level render()

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 cecbaf2 · Browse files · 2 files+41 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+41 added−1 removed

  • other:+41 added−1 removed

2 files+41 added−1 removed

modified:lib/application.js-1 removed
9 unmodified lines
10 */1112var connect = require('connect')13 , Router = require('./router')14 , view = require('./view')14 , toArray = require('./utils').toArray15 , methods = Router.methods.concat('del', 'all')16 , res = require('./response')17 , union = require('./utils').union
577 unmodified lines
modified:lib/response.js+41 added
476 unmodified lines
477 this.statusCode = status;478 this.header('Location', url);479 this.end(head ? null : body);480};481482/**483 * Render `view` with the given `options` and optional callback `fn`.484 * When a callback function is given a response will _not_ be made485 * automatically, otherwise a response of _200_ and _text/html_ is given.486 *487 * Options:488 * 489 * - `status` Response status code (`res.statusCode`)490 * - `charset` Set the charset (`res.charset`)491 *492 * Reserved locals:493 *494 * - `cache` boolean hinting to the engine it should cache495 * - `filename` filename of the view being rendered496 *497 * @param {String} view498 * @param {Object|Function} options or callback function499 * @param {Function} fn500 * @api public501 */502503res.render = function(view, options, fn){504 var self = this505 , req = this.req506 , app = req.app;507508 // support callback function as second arg509 if ('function' == typeof options) {510 fn = options, options = null;511 }512513 // default callback to respond514 fn = fn || function(err, str){515 if (err) return req.next(err);516 self.send(str);517 };518519 // render520 app.render(view, options, fn);521};