Skip to content
Myr

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

1 file+18 added−19 removed

modified:lib/express/view.js+18 added-19 removed
272 unmodified lines
273 * @api public274 */275276http.ServerResponse.prototype.partial = function(view, options, locals, parent){277 locals = locals || {};277278 // Inherit parent view extension when not present279 if (parent && !~view.indexOf('.')) {280 view += parent.extension;
10 unmodified lines
291 options = {};292 }293294 // Inherit locals from parent296 options.locals = options.locals297 ? merge(locals, options.locals)298 : locals;295 merge(options, locals);296297 // Merge locals298 if (options.locals) {299 merge(options, options.locals);300 }301302 // Partials dont need layouts303 options.renderPartial = true;304 options.layout = false;305
7 unmodified lines
313 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 lines
388389 // Default execution scope to the response390 options.scope = options.scope || this.req;391390 // Pass filename to the engine and view391 var locals = options.locals = options.locals || {};392392 // Populate view393 options.parentView = parent;394395 // "views" setting
20 unmodified lines
416 }417 }418419 // apply421 merge(options.locals, this.__dynamicHelpers);420 merge(options, this.__dynamicHelpers);421 }422423 // Merge view helpers425 options.locals = merge(clone(helpers), options.locals);424 options = merge(clone(helpers), options);425426 // 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 };430431 function error(err) {432 if (fn) {
5 unmodified lines
438439 // 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 }446447 // 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