Added as: global support
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 edfb18b · Browse files · 4 files·+26 added−4 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+26 added−4 removed
- tests:+15 added−2 removed
- other:+11 added−2 removed
Provenance
- Commit
a32c7d5- Tree
b261b70- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
edfb18b
4 files changed+26 added−4 removed
modified:lib/express/view.js+6 added-2 removed
9 unmodified lines10111213141516171828 unmodified lines4748495050515152535455565718 unmodified lines76777879808182838485113 unmodified linesExpand all9 unmodified lines */
var extname = require('path').extname, mime = require('connect/utils').mime, utils = require('connect/utils'), http = require('http'), fs = require('fs');
/**28 unmodified lines * Render `view` partial with the given `options`. * * Options: * - `as` Variable name for each `collection` value, defaults to the view name. * When assigning `as: this`, each value in the collection will become the * evaluation context of the template. * * as: 'something' will add the `something` local variable * * as: this will use the collection value as the template context * * as: global will merge the collection value's properties with `locals` * * - `collection` Array of objects, the name is derived from the view name itself. * For example _video.html_ will have a object _video_ available to it. *18 unmodified lines locals.collectionLength = len; return collection.map(function(val, i){ if (typeof name === 'string') { locals[name] = val; } else if (name === global) { utils.merge(locals, val); } else { options.context = val; } locals.firstInCollection = i === 0;113 unmodified linesExpand alladded:test/fixtures/partials/video.jade+1 added
1+p= directormodified:test/view.test.js+14 added-2 removed
93 unmodified lines94 assert.response(app,95 { url: '/movies' },96 { body: html });97 98- // "as" collection option98+ // as: str collection option99 app.get('/user', function(req, res){100 res.send(res.partial('user.jade', {101 as: 'person',102 collection: [{ name: 'tj' }]3 unmodified lines106 assert.response(app,107 { url: '/user' },108 { body: '<p>tj</p>' });109 110- // "as" this collection option110+ // as: this collection option111 app.get('/person', function(req, res){112 res.send(res.partial('person.jade', {113 as: this,114 collection: [{ name: 'tj' }]2 unmodified lines117 118 assert.response(app,119 { url: '/person' },120 { body: '<p>tj</p>' });121+122+ // as: global collection option123+ app.get('/videos', function(req, res){124+ res.send(res.partial('video.jade', {125+ as: global,126+ collection: movies127+ }));128+ });129+130+ assert.response(app,131+ { url: '/videos' },132+ { body: '<p>Tim Burton</p><p>James Cameron</p>' });133 }134 };modified:.pomo+5 added
77 unmodified lines78 complete: false79 description: 80 length: 2581 name: next(err) from within view system?82+- !ruby/object:Pomo::Task 83+ complete: false84+ description: 85+ length: 2586+ name: view defaults / extension defaults