Skip to content
Myr

Fixed partials example

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 bd1ab7a · Browse files · 9 files+33 added−34 removed
This commit

State

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

Diff stats

9 files+33 added−34 removed

  • other:+33 added−34 removed

9 files+33 added−34 removed

added:examples/partials/views/ninja/victim/index.jade+5 added
1// this is insane overkill, I do not recommend2// doing tiny partials like this as it gets expensive3// with collections, however this illustrates the new4// partial lookup mechanism5!= partial('../../li', { object: victim, as: 'value' })
added:examples/partials/views/ninja/_weapon.jade+1 added
1li.weapon= weapon
added:examples/partials/views/ninja/index.jade+22 added
1h1= ninja.name23// file, partial name, and partial object all match ('summary')4// the partial filename prefix '_' is completely optional.56// In this case we need to specify ninja.summary as the object7// option, since it is a "plain" object Express cannot otherwise8// tell if it is intended to be locals, or THE summary object9#summary!= partial('summary', { object: ninja.summary })1011// file, partial name = '_weapon', resolves to 'weapon' object within partial12#weapons13 h2 Weapons14 // the weapon partial is rendered once per item in15 // the weapons array or "collection"16 ul!= partial('weapon', ninja.weapons)17 18// partial name 'victim' resolves to 'victim.jade'19// or 'victim/index.jade', providing the "victim" local20#victims21 h2 Victims22 ul!= partial('victim', ninja.victims)
added:examples/partials/views/ninja/summary.jade+4 added
1h2 Summary2p= summary.email3p= summary.description4p taught by master #{summary.master}
deleted:examples/partials/views/ninjas/victim/index.jade-5 removed
1// this is insane overkill, I do not recommend2// doing tiny partials like this as it gets expensive3// with collections, however this illustrates the new4// partial lookup mechanism5!= partial('../../li', { object: victim, as: 'value' })
deleted:examples/partials/views/ninjas/_weapon.jade-1 removed
1li.weapon= weapon
deleted:examples/partials/views/ninjas/index.jade-18 removed
1h1= ninja.name23// file, partial name, and partial object all match ('summary')4// the partial filename prefix '_' is completely optional5#summary!= partial('summary', ninja.summary)67// file, partial name = '_weapon', resolves to 'weapon' object within partial8#weapons9 h2 Weapons10 // the weapon partial is rendered once per item in11 // the weapons array or "collection"12 ul!= partial('weapon', ninja.weapons)13 14// partial name 'victim' resolves to 'victim.jade'15// or 'victim/index.jade', providing the "victim" local16#victims17 h2 Victims18 ul!= partial('victim', ninja.victims)
deleted:examples/partials/views/ninjas/summary.jade-4 removed
1h2 Summary2p= summary.email3p= summary.description4p taught by master #{summary.master}
modified:examples/partials/app.js+1 added-6 removed
26 unmodified lines
27 victims: ['shredder', 'brain', 'beebop', 'rocksteady']28};2930app.get('/', function(req, res){31 res.render('ninjas', { ninja: ninja });31 res.render('ninja', { ninja: ninja });32});3334app.get('/li', function(req, res){35 res.partial('li', { object: 'Testing', as: 'value' });36});373834app.listen(3000);35console.log('Express app started on port 3000');