Added support for partial(view, array) as collection
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 8ece01c · Browse files · 5 files·+49 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
5 files+49 added−5 removed
- tests:+39 added−3 removed
- other:+10 added−2 removed
Provenance
- Commit
22100f7- Tree
c3aed01- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
8ece01c
5 files changed+49 added−5 removed
modified:lib/express/view.js+5 added-2 removed
44 unmodified lines454647484949505152535454555657585960616263646566121 unmodified linesExpand all44 unmodified lines/** * Render `view` partial with the given `options`. * * Options: * - `as` String name for the id used to which "collection" assign it's current value. * - `as` Variable name for each `collection` value, defaults to the view name. * - `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. * * @param {String} view * @param {Object} options * @param {Object|Array} options or collection * @return {String} * @api public */
http.ServerResponse.prototype.partial = function(view, options){ if (options instanceof Array) { options = { collection: options }; } options = options || {}; options.partial = true; options.layout = false; var collection = options.collection;121 unmodified linesExpand alladded:test/fixtures/partials/movie.jade+3 added
1+li2+ .title= movie.title3+ .director= movie.directoradded:test/fixtures/movies.jade+1 added
1+ul!= partial('movie.jade', movies)modified:test/view.test.js+35 added-3 removed
1 unmodified line2 /**3 * Module dependencies.4 */5 6-var express = require('express');6+var express = require('express'),7+ connect = require('connect');8 9 module.exports = {10 'test #render()': function(assert){11 var app = express.createServer();43 unmodified lines55 'test #partial()': function(assert){56 var app = express.createServer();57 app.set('views', __dirname + '/fixtures');58 59+ // Auto-assigned local w/ collection option60 app.get('/', function(req, res){61 res.render('items.jade', { locals: { items: ['one', 'two'] }});62 });61-62- assert.response(app,63+ 64+ assert.response(app,65 { url: '/' },66 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });67+68+ // Auto-assigned local w/ collection array 69+ var movies = [70+ { title: 'Nightmare Before Christmas', director: 'Tim Burton' },71+ { title: 'Avatar', director: 'James Cameron' }72+ ];73+ app.get('/movies', function(req, res){74+ res.render('movies.jade', { locals: { movies: movies }});75+ });76+ 77+ var html = [78+ '<html>',79+ '<body>',80+ '<ul>',81+ '<li>',82+ '<div class="title">Nightmare Before Christmas</div>',83+ '<div class="director">Tim Burton</div>',84+ '</li>',85+ '<li>',86+ '<div class="title">Avatar</div>',87+ '<div class="director">James Cameron</div>',88+ '</li>',89+ '</ul>',90+ '</body>',91+ '</html>'92+ ].join('');93+94+ assert.response(app,95+ { url: '/movies' },96+ { body: html });97 }98 };modified:.pomo+5 added
72 unmodified lines73 complete: false74 description: 75 length: 2576 name: view mtime check interval77+- !ruby/object:Pomo::Task 78+ complete: false79+ description: 80+ length: 2581+ name: next(err) from within view system?