In depth partial docs
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 e98f86c · Browse files · 4 files·+171 added−0 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+171 added−0 removed
- other:+171 added−0 removed
Provenance
- Commit
793943f- Tree
0310843- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
e98f86c
4 files changed+171 added−0 removed
modified:docs/api.html+3 added
952 unmodified lines953 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>954 ? <span class="string">'layout'</span> + <span class="variable">ext</span>955 : <span class="variable">layout</span>;956 957+ <span class="comment">// Normalize "context" to "scope"</span>958+ <span class="variable">options</span>.<span class="variable">scope</span> = <span class="variable">options</span>.<span class="variable">scope</span> || <span class="variable">options</span>.<span class="variable">context</span>;959+960 <span class="comment">// Auto-cache in production</span>961 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="string">'production'</span>) {962 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;963 }72 unmodified linesmodified:docs/guide.1+81 added
703 unmodified lines704 \fIdebug\fR Output debugging information705 .706 .IP "" 0707 .708+.SS "res\.partial(view[, options])"709+Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.710+.711+.IP "\(bu" 4712+\fIas\fR Variable name for each \fIcollection\fR value, defaults to the view name\.713+.714+.IP "\(bu" 4715+as: \'something\' will add the \fIsomething\fR local variable716+.717+.IP "\(bu" 4718+as: this will use the collection value as the template context719+.720+.IP "\(bu" 4721+as: global will merge the collection value\'s properties with \fIlocals\fR722+.723+.IP "" 0724+725+.726+.IP "\(bu" 4727+\fIcollection\fR Array of objects, the name is derived from the view name itself\. For example \fIvideo\.html\fR will have a object \fIvideo\fR available to it\.728+.729+.IP "" 0730+.731+.P732+The following are equivalent, and the name of collection value when passed to the partial will be \fImovie\fR as derived from the name\.733+.734+.IP "" 4735+.736+.nf737+738+partial(\'movie\.jade\', { collection: movies });739+partial(\'movie\.jade\', movies);740+partial(\'movie\', movies);741+// In view: movie\.director742+.743+.fi744+.745+.IP "" 0746+.747+.P748+To change the local from \fImovie\fR to \fIvideo\fR we can use the \"as\" option:749+.750+.IP "" 4751+.752+.nf753+754+partial(\'movie\', { collection: movies, as: \'video\' });755+// In view: video\.director756+.757+.fi758+.759+.IP "" 0760+.761+.P762+Also we can make our movie the value of \fIthis\fR within our view so that instead of \fImovie\.director\fR we could use \fIthis\.director\fR\.763+.764+.IP "" 4765+.766+.nf767+768+partial(\'movie\', { collection: movies, as: this });769+// In view: this\.director770+.771+.fi772+.773+.IP "" 0774+.775+.P776+Another alternative is to \"explode\" the properties of the collection item into pseudo globals (local variables) by using \fIas: global\fR, which again is syntactic sugar:777+.778+.IP "" 4779+.780+.nf781+782+partials(\'movie\', { collection: movies, as: global });783+// In view: director784+.785+.fi786+.787+.IP "" 0788+.789 .SS "app\.set(name[, val])"790 Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:791 .792 .IP "" 4172 unmodified linesmodified:docs/guide.html+49 added
188 unmodified lines189 <li><a href="#res-download-file-filename-">res.download()</a></li>190 <li><a href="#res-send-body-status-headers-status-status-">res.send()</a></li>191 <li><a href="#res-redirect-url-status-">res.redirect()</a></li>192 <li><a href="#res-render-view-options-fn-">res.render()</a></li>193+<li><a href="#res-partial-view-options-">res.partial()</a></li>194 <li><a href="#app-set-name-val-">app.set()</a></li>195 <li><a href="#app-enable-name-">app.enable()</a></li>196 <li><a href="#app-disable-name-">app.disable()</a></li>197 <li><a href="#app-configure-env-function-function-">app.configure()</a></li>495 unmodified lines693 <li><em>debug</em> Output debugging information</li>694 </ul>695 696 697+<h3 id="res-partial-view-options-">res.partial(view[, options])</h3>698+699+<p>Render <em>view</em> partial with the given <em>options</em>. This method is always available700+to the view as a local variable.</p>701+702+<ul>703+<li><p><em>as</em> Variable name for each <em>collection</em> value, defaults to the view name.</p>704+705+<ul>706+<li>as: 'something' will add the <em>something</em> local variable</li>707+<li>as: this will use the collection value as the template context</li>708+<li>as: global will merge the collection value's properties with <em>locals</em></li>709+</ul>710+</li>711+<li><p><em>collection</em> Array of objects, the name is derived from the view name itself.712+For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li>713+</ul>714+715+716+<p>The following are equivalent, and the name of collection value when passed717+to the partial will be <em>movie</em> as derived from the name.</p>718+719+<pre><code>partial('movie.jade', { collection: movies });720+partial('movie.jade', movies);721+partial('movie', movies);722+// In view: movie.director723+</code></pre>724+725+<p>To change the local from <em>movie</em> to <em>video</em> we can use the "as" option:</p>726+727+<pre><code>partial('movie', { collection: movies, as: 'video' });728+// In view: video.director729+</code></pre>730+731+<p>Also we can make our movie the value of <em>this</em> within our view so that instead732+of <em>movie.director</em> we could use <em>this.director</em>.</p>733+734+<pre><code>partial('movie', { collection: movies, as: this });735+// In view: this.director736+</code></pre>737+738+<p>Another alternative is to "explode" the properties of the collection item into739+pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>740+741+<pre><code>partials('movie', { collection: movies, as: global });742+// In view: director743+</code></pre>744+745 <h3 id="app-set-name-val-">app.set(name[, val])</h3>746 747 <p>Apply an application level setting <em>name</em> to <em>val</em>, or748 get the value of <em>name</em> when <em>val</em> is not present:</p>107 unmodified linesmodified:docs/guide.md+38 added
433 unmodified lines434 - _filename_ Filename used for the _cache_ option435 - _cache_ Cache intermediate JavaScript in memory436 - _debug_ Output debugging information437 438+### res.partial(view[, options])439+440+Render _view_ partial with the given _options_. This method is always available441+to the view as a local variable.442+443+- _as_ Variable name for each _collection_ value, defaults to the view name.444+ * as: 'something' will add the _something_ local variable445+ * as: this will use the collection value as the template context446+ * as: global will merge the collection value's properties with _locals_447+448+- _collection_ Array of objects, the name is derived from the view name itself. 449+ For example _video.html_ will have a object _video_ available to it.450+451+The following are equivalent, and the name of collection value when passed452+to the partial will be _movie_ as derived from the name.453+454+ partial('movie.jade', { collection: movies });455+ partial('movie.jade', movies);456+ partial('movie', movies);457+ // In view: movie.director458+459+To change the local from _movie_ to _video_ we can use the "as" option:460+461+ partial('movie', { collection: movies, as: 'video' });462+ // In view: video.director463+464+Also we can make our movie the value of _this_ within our view so that instead465+of _movie.director_ we could use _this.director_.466+467+ partial('movie', { collection: movies, as: this });468+ // In view: this.director469+470+Another alternative is to "explode" the properties of the collection item into471+pseudo globals (local variables) by using _as: global_, which again is syntactic sugar:472+473+ partials('movie', { collection: movies, as: global });474+ // In view: director475+476 ### app.set(name[, val])477 478 Apply an application level setting _name_ to _val_, or479 get the value of _name_ when _val_ is not present:90 unmodified lines