Skip to content
Myr

merging res.locals

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 294bc8c · Browse files · 2 files+19 added−5 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+19 added−5 removed

  • other:+19 added−5 removed

2 files+19 added−5 removed

modified:lib/application.js+15 added-5 removed
555 unmodified lines
556 */557558app.render = function(view, options, fn){559 var self = this560 , opts = {}561 , engines = this.engines562 , root = this.set('views') || process.cwd() + '/views';563564 // support callback function as second arg
1 unmodified line
566 fn = options, options = {};567 }568569 // merge app.locals569 union(options, this.locals);570 utils.merge(opts, this.locals);571572 // merge options.locals573 if (options.locals) {574 utils.merge(opts, options.locals);575 delete opts.locals;576 }577578 // merge options579 utils.merge(opts, options);580581 // join "view engine" if necessary582 var ext = extname(view);583 if (!ext) view += '.' + (ext = this.set('view engine'));584585 // pass .cache to the engine576 options.cache = this.enabled('view cache');586 opts.cache = this.enabled('view cache');587588 // when no extension nor "view engine" is given589 if (!ext) return fn(new Error('failed to find view "' + view + '"'));590591 // render592 try {593 var engine = engines[ext] = engines[ext] || require(ext);584 options.filename = join(root, view);585 view = fs.readFileSync(options.filename, 'utf8');586 engine.render(view, options, fn);594 opts.filename = join(root, view);595 view = fs.readFileSync(opts.filename, 'utf8');596 engine.render(view, opts, fn);597 } catch (err) {598 fn(err);599 }600};
modified:lib/response.js+4 added
500 unmodified lines
501 */502503res.render = function(view, options, fn){504 var self = this505 , options = options || {}506 , req = this.req507 , app = req.app;508509 // support callback function as second arg510 if ('function' == typeof options) {511 fn = options, options = {};512 }513514 // merge res.locals515 options.locals = this.locals;516517 // status option518 if (options.status) this.statusCode = options.status;519520 // charset option
11 unmodified lines