Skip to content
Myr

Added partial local inheritance [suggested by masylum]. Closes #102

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 f65874d · Browse files · 4 files+20 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+20 added−10 removed

  • tests:+3 added−0 removed
  • other:+17 added−10 removed

4 files+20 added−10 removed

modified:lib/express/view.js+17 added-10 removed
8 unmodified lines
9 * Module dependencies.10 */1112var extname = require('path').extname13 , utils = require('connect').utils14 , http = require('http')15 , fs = require('fs')16 , mime = utils.mime;13 , utils = require('connect').utils14 , http = require('http')15 , fs = require('fs')16 , mime = utils.mime;1718/**19 * Cache supported template engine exports to20 * increase performance by lowering the number
88 unmodified lines
109 * @return {String}110 * @api public111 */112113http.ServerResponse.prototype.partial = function(view, options, ext){113http.ServerResponse.prototype.partial = function(view, options, ext, locals){114 // Inherit parent view extension when not present115 if (ext && view.indexOf('.') < 0) {116 view += ext;117 }
4 unmodified lines
122 }123124 // Defaults125 options = options || {};126127 // Inherit locals from parent128 options.locals = options.locals || {};129 utils.merge(options.locals, locals);130131 // Partials dont need layouts132 options.partial = true;133 options.layout = false;134135 // Deduce name from view path136 var name = options.as || view.split('/').slice(-1)[0].split('.')[0];137138 // Collection support139 var collection = options.collection;
101 unmodified lines
241 ? view242 : root + '/' + view;243244 // Pass filename to the engine and view238 options.locals = options.locals || {};245 var locals = options.locals = options.locals || {};246 options.locals.__filename = options.filename = path;247248 // Dynamic helper support249 if (options.dynamicHelpers !== false) {
16 unmodified lines
266 // apply267 utils.merge(helpers, this.__dynamicHelpers);268 }269270 // Merge view helpers271 options.locals.__proto__ = helpers;272273 // Always expose partial() as a local274 options.locals.partial = function(view, options){265 return self.partial.call(self, view, options, ext);275 return self.partial.call(self, view, options, ext, locals);276 };267 268 // Merge view helpers269 options.locals.__proto__ = helpers;277278 function error(err) {279 if (fn) {280 fn(err);
36 unmodified lines
added:test/fixtures/partials/pet-count.jade+1 added
1| We have #{pets.length} cool pets
modified:test/fixtures/pets.jade+1 added
1h1= site2p!= partial('pet-count')3ul!= partial('pet', pets)
modified:test/view.test.js+1 added
480 unmodified lines
481 var html = [482 '<html>',483 '<body>',484 '<h1>My Cool Pets</h1>',485 '<p>We have 3 cool pets\n</p>',486 '<ul>',487 '<li>Tobi is the coolest of My Cool Pets</li>',488 '<li>Jane</li>',489 '<li>Bandit</li>',
112 unmodified lines