implementing new 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 d1a790d · Browse files · 1 file·+18 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+18 added−19 removed
- other:+18 added−19 removed
Provenance
- Commit
4780168- Tree
50f62b7- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
d1a790d
1 file changed+18 added−19 removed
modified:lib/express/view.js+18 added-19 removed
272 unmodified lines273 * @api public274 */275 276 http.ServerResponse.prototype.partial = function(view, options, locals, parent){277- locals = locals || {};277 278 // Inherit parent view extension when not present279 if (parent && !~view.indexOf('.')) {280 view += parent.extension;10 unmodified lines291 options = {};292 }293 294 // Inherit locals from parent296- options.locals = options.locals297- ? merge(locals, options.locals)298- : locals;295+ merge(options, locals);296 297+ // Merge locals298+ if (options.locals) {299+ merge(options, options.locals);300+ }301+302 // Partials dont need layouts303 options.renderPartial = true;304 options.layout = false;305 7 unmodified lines313 if (collection) {314 var len = collection.length315 , buf = '';316 delete options.collection;315- options.locals.collectionLength = len;317+ options.collectionLength = len;318 for (var i = 0; i < len; ++i) {319 var val = collection[i];318- options.locals.firstInCollection = i === 0;319- options.locals.indexInCollection = i;320- options.locals.lastInCollection = i === len - 1;320+ options.firstInCollection = i === 0;321+ options.indexInCollection = i;322+ options.lastInCollection = i === len - 1;323 options.object = val;324 buf += this.partial(view, options);325 }326 return buf;327 } else {328 if (options.object) {329 if ('string' == typeof name) {328- options.locals[name] = options.object;330+ options[name] = options.object;331 } else if (name === global) {330- merge(options.locals, options.object);332+ merge(options, options.object);333 } else {334 options.scope = options.object;335 }336 }51 unmodified lines388 389 // Default execution scope to the response390 options.scope = options.scope || this.req;391 390- // Pass filename to the engine and view391- var locals = options.locals = options.locals || {};392-392 // Populate view393 options.parentView = parent;394 395 // "views" setting20 unmodified lines416 }417 }418 419 // apply421- merge(options.locals, this.__dynamicHelpers);420+ merge(options, this.__dynamicHelpers);421 }422 423 // Merge view helpers425- options.locals = merge(clone(helpers), options.locals);424+ options = merge(clone(helpers), options);425 426 // Always expose partial() as a local428- options.locals.partial = function(path, options){429- return self.partial(path, options, locals, view);427+ options.partial = function(path, opts){428+ return self.partial(path, opts, options, view);429 };430 431 function error(err) {432 if (fn) {5 unmodified lines438 439 // Attempt render440 try {441 var template = view.templateEngine.compile(view.contents, options);443- str = template.call(options.scope, options.locals);442+ str = template.call(options.scope, options);443 } catch (err) {444 return error(err);445 }446 447 // Layout support448 if (layout) {449 options.layout = false;451- options.locals.body = str;450+ options.body = str;451 self.render(layout, options, fn, view);452 } else if (partial) {453 return str;454 } else if (fn) {5 unmodified lines