api.html
This file
Path
docs/api.html
1,091 lines · 68.9 KiB · HTML
Last changed by
Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629
History of this fileTake it
The walk stopped after 200 commits: lines older than 9750817 point at it.
Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1–3why, one step back1<html>2 <head>3 <title>Express</title>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 4why, one step back4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 5–57why, one step back5 <style>body {6 margin: 0;7 padding: 0;8 font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;9 color: #252519;10}11a {12 color: #252519;13}14a:hover {15 text-decoration: underline;16 color: #19469D;17}18p {19 margin: 12px 0;20}21h1, h2, h3 {22 margin: 0;23 padding: 0;24}25table#source {26 width: 100%;27 border-collapse: collapse;28}29table#source td:first-child {30 padding: 30px 40px 30px 40px;31 vertical-align: top;32}33table#source td:first-child,34table#source td:first-child pre {35 width: 450px;36}37table#source td:last-child {38 padding: 30px 0 30px 40px;39 border-left: 1px solid #E5E5EE;40 background: #F5F5FF;41}42table#source tr {43 border-bottom: 1px solid #E5E5EE;44}45table#source tr.filename {46 padding-top: 40px;47 border-top: 1px solid #E5E5EE;48}49table#source tr.filename td:first-child {50 text-transform: capitalize;51}52table#source tr.filename td:last-child {53 font-size: 12px;54}55table#source tr.filename h2 {56 margin: 0;57 padding: 0;Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 58why, one step back58 cursor: pointer;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 59–88why, one step back59}60table#source tr.code h1,61table#source tr.code h2,62table#source tr.code h3 {63 margin-top: 30px;64 font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;65 font-size: 18px;66}67table#source tr.code h2 {68 font-size: 16px;69}70table#source tr.code h3 {71 font-size: 14px;72}73table#source tr.code ul {74 margin: 15px 0 15px 35px;75 padding: 0;76}77table#source tr.code ul li {78 margin: 0;79 padding: 1px 0;80}81table#source tr.code ul li p {82 margin: 0;83 padding: 0;84}85table#source tr.code td:first-child pre {86 padding: 20px;87}88#ribbon {Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 89why, one step back89 position: fixed;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 90–98why, one step back90 top: 0;91 right: 0;92}93code .string { color: #219161; }94code .regexp { color: #219161; }95code .keyword { color: #954121; }96code .number { color: #19469D; }97code .comment { color: #bbb; }98code .this { color: #19469D; }</style>Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 99–108why, one step back99 <script>100 $(function(){101 $('tr.code').hide();102 $('tr.filename').toggle(function(){103 $(this).nextUntil('.filename').fadeIn();104 }, function(){105 $(this).nextUntil('.filename').fadeOut();106 });107 });108 </script>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 109–110why, one step back109 </head>110 <body>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 111why, one step back111<table id="source"><tbody><tr><td><h1>Express</h1><p>High performance web framework for <a href="http://nodejs.org">node</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/express/index.js"><a href="#">index</a></h2></td><td>lib/express/index.js</td></tr><tr class="code">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 112why, one step back112<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 113–114why, one step back113<p>Framework version.114 </p>Updated docsTj Holowaychukbefore adoption09dabef
lines 115–116why, one step back115</td>116<td class="code">Executable docsTj Holowaychukbefore adoption5e4d672
line 117why, one step back117<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'1.0.0beta'</span>;</code></pre>Updated docsTj Holowaychukbefore adoption09dabef
lines 118–121why, one step back118</td>119</tr>120<tr class="code">121<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 122–123why, one step back122<p>Module dependencies.123 </p>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 124–125why, one step back124</td>125<td class="code">Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2
line 126why, one step back126<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">exports</span>.<span class="class">Server</span> = <span class="variable">require</span>(<span class="string">'./server'</span>);</code></pre>Updated docsTj Holowaychukbefore adoption09dabef
lines 127–134why, one step back127</td>128</tr>129<tr class="code">130<td class="docs">131<p>Shortcut for <code>new Server(...)</code>.</p>132133<h2></h2>134Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 135why, one step back135<ul><li><p><strong>param</strong>: <em>Function</em> ...</p></li><li><p><strong>return</strong>: <em>Server</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Updated docsTj Holowaychukbefore adoption09dabef
lines 136–144why, one step back136</td>137<td class="code">138<pre><code><span class="variable">exports</span>.<span class="variable">createServer</span> = <span class="keyword">function</span>(){139 <span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Server</span>(<span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>));140};</code></pre>141</td>142</tr>143<tr class="code">144<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 145–146why, one step back145<p>View extensions.146 </p>Updated docsTj Holowaychukbefore adoption09dabef
lines 147–153why, one step back147</td>148<td class="code">149<pre><code><span class="variable">require</span>(<span class="string">'./view'</span>);150<span class="variable">require</span>(<span class="string">'./request'</span>);151<span class="variable">require</span>(<span class="string">'./response'</span>);152</code></pre>153</td>Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 154–339why, one step back154</tr><tr class="filename"><td><h2 id="lib/express/request.js"><a href="#">request</a></h2></td><td>lib/express/request.js</td></tr><tr class="code">155<td class="docs">156<p>Module dependencies.157 </p>158</td>159<td class="code">160<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),161 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),162 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>163</td>164</tr>165<tr class="code">166<td class="docs">167<p>Return request header or optional default.</p>168169<h2>Examples</h2>170171<pre><code>req.header('Content-Type');172// => "text/plain"173174req.header('content-type');175// => "text/plain"176177req.header('Accept');178// => undefined179180req.header('Accept', 'text/html');181// => "text/html"</code></pre>182183<h2></h2>184185<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> defaultValue</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>186</td>187<td class="code">188<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">defaultValue</span>){189 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>.<span class="variable">toLowerCase</span>()] || <span class="variable">defaultValue</span>;190};</code></pre>191</td>192</tr>193<tr class="code">194<td class="docs">195<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>196197<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise198the given <code>type</code> is matched by an exact match, and then subtypes. You199may pass the subtype such as "html" which is then converted internally200to "text/html" using the mime lookup table.</p>201202<h2>Examples</h2>203204<pre><code>// Accept: text/html205req.accepts('html');206// => true207208// Accept: text/*; application/json209req.accepts('html');210req.accepts('text/html');211req.accepts('text/plain');212req.accepts('application/json');213// => true214215req.accepts('image/png');216req.accepts('png');217// => false</code></pre>218219<h2></h2>220221<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>222</td>223<td class="code">224<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">accepts</span> = <span class="keyword">function</span>(<span class="variable">type</span>){225 <span class="keyword">var</span> <span class="variable">accept</span> = <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Accept'</span>);226 <span class="keyword">if</span> (!<span class="variable">accept</span> || <span class="variable">accept</span> === '*</code></pre>227</td>228</tr>229<tr class="code">230<td class="docs">231<p>') {232 return true;233 } else if (type) {234 // Allow "html" vs "text/html" etc235 if (type.indexOf('/') < 0) {236 type = mime.types['.' + type];237 }238 // Check if we have a direct match239 if (accept.indexOf(type) >= 0) {240 return true;241 // Check if we have type/<em>242 } else {243 type = type.split('/')[0] + '/</em>';244 return accept.indexOf(type) >= 0;245 }246 } else {247 return false;248 }249};</p>250251<p>/**252Return the value of param <code>name</code> when present.</p>253254<ul><li>Checks route placeholders, ex: <em>/user/:id</em></li><li>Checks query string params, ex: ?id=12</li><li>Checks urlencoded body params, ex: id=12</li></ul>255256<p>To utilize urlencoded request bodies, <code>req.body</code>257should be an object. This can be done by using258the <code>connect.bodyDecoder</code> middleware.</p>259260<h2></h2>261262<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>263</td>264<td class="code">265<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">param</span> = <span class="keyword">function</span>(<span class="variable">name</span>){266 <span class="comment">// Route params like /user/:id</span>267 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">params</span>.<span class="variable">path</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {268 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">params</span>.<span class="variable">path</span>[<span class="variable">name</span>]; 269 }270 <span class="comment">// Query string params</span>271 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">params</span>.<span class="variable">get</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {272 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">params</span>.<span class="variable">get</span>[<span class="variable">name</span>]; 273 }274 <span class="comment">// Request body params via connect.bodyDecoder</span>275 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">body</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {276 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>];277 }278};</code></pre>279</td>280</tr>281<tr class="code">282<td class="docs">283<p>Queue flash <code>msg</code> of the given <code>type</code>.</p>284285<h2>Examples</h2>286287<pre><code> req.flash('info', 'email sent');288 req.flash('error', 'email delivery failed');289 req.flash('info', 'email re-sent');290 // => 2291292 req.flash('info');293 // => ['email sent', 'email re-sent']294295 req.flash('info');296 // => []297298 req.flash();299 // => { error: ['email delivery failed'], info: [] }</code></pre>300301<h2></h2>302303<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li><li><p><strong>return</strong>: <em>Array | Object | Number</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>304</td>305<td class="code">306<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">flash</span> = <span class="keyword">function</span>(<span class="variable">type</span>, <span class="variable">msg</span>){307 <span class="keyword">var</span> <span class="variable">msgs</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> || {};308 <span class="keyword">if</span> (<span class="variable">type</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">msg</span>) {309 <span class="variable">msg</span> = <span class="variable">utils</span>.<span class="variable">miniMarkdown</span>(<span class="variable">utils</span>.<span class="variable">htmlEscape</span>(<span class="variable">msg</span>));310 <span class="keyword">return</span> (<span class="variable">msgs</span>[<span class="variable">type</span>] = <span class="variable">msgs</span>[<span class="variable">type</span>] || []).<span class="variable">push</span>(<span class="variable">msg</span>);311 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {312 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];313 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];314 <span class="keyword">return</span> <span class="variable">arr</span> || [];315 } <span class="keyword">else</span> {316 <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = {};317 <span class="keyword">return</span> <span class="variable">msgs</span>;318 }319};320321<span class="comment">// Callback for isXMLHttpRequest / xhr</span>322323<span class="keyword">function</span> <span class="variable">isxhr</span>() {324 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'X-Requested-With'</span>, <span class="string">''</span>).<span class="variable">toLowerCase</span>() === <span class="string">'xmlhttprequest'</span>;325}</code></pre>326</td>327</tr>328<tr class="code">329<td class="docs">330<p>Check if the request was an <em>XMLHttpRequest</em>.</p>331332<h2></h2>333334<ul><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>335</td>336<td class="code">337<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'isXMLHttpRequest'</span>, <span class="variable">isxhr</span>);338<span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'xhr'</span>, <span class="variable">isxhr</span>);</code></pre>339</td>Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629
lines 340–379why, one step back340</tr><tr class="filename"><td><h2 id="lib/express/utils.js"><a href="#">utils</a></h2></td><td>lib/express/utils.js</td></tr><tr class="code">341<td class="docs">342<p>Parse mini markdown implementation.343The following conversions are supported,344primarily for the "flash" middleware:</p>345346<p> <em>foo</em> or <em>foo</em> become <em>foo</em>347 <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>348 <a href="B">A</a> becomes <a href="B">A</a></p>349350<h2></h2>351352<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>353</td>354<td class="code">355<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){356 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)357 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)358 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)359 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);360};</code></pre>361</td>362</tr>363<tr class="code">364<td class="docs">365<p>Escape special characters in the given string of html.</p>366367<h2></h2>368369<ul><li><p><strong>param</strong>: <em>String</em> html</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>370</td>371<td class="code">372<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {373 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)374 .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)375 .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)376 .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)377 .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);378};</code></pre>379</td>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 380why, one step back380</tr><tr class="filename"><td><h2 id="lib/express/response.js"><a href="#">response</a></h2></td><td>lib/express/response.js</td></tr><tr class="code">More docsTj Holowaychukbefore adoptionbedff32
line 381why, one step back381<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 382–383why, one step back382<p>Module dependencies.383 </p>More docsTj Holowaychukbefore adoptionbedff32
lines 384–385why, one step back384</td>385<td class="code">Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 386–387why, one step back386<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),387 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),More docsTj Holowaychukbefore adoptionbedff32
lines 388–404why, one step back388 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),389 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),390 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,391 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>392</td>393</tr>394<tr class="code">395<td class="docs">396<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>397398<h2>Examples</h2>399400<pre><code>res.send(new Buffer('wahoo'));401res.send({ some: 'json' });402res.send('<p>some html</p>');403res.send('Sorry, cant find that', 404);404res.send('text', { 'Content-Type': 'text/plain' }, 201);Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 405why, one step back405res.send(404);</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 406–408why, one step back406407<h2></h2>408Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 409why, one step back409<ul><li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li><li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li><li><p><strong>param</strong>: <em>Number</em> status</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>More docsTj Holowaychukbefore adoptionbedff32
lines 410–436why, one step back410</td>411<td class="code">412<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">send</span> = <span class="keyword">function</span>(<span class="variable">body</span>, <span class="variable">headers</span>, <span class="variable">status</span>){413 <span class="comment">// Allow status as second arg</span>414 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {415 <span class="variable">status</span> = <span class="variable">headers</span>,416 <span class="variable">headers</span> = <span class="keyword">null</span>;417 }418419 <span class="comment">// Defaults</span>420 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;421 <span class="variable">headers</span> = <span class="variable">headers</span> || {};422423 <span class="comment">// Determine content type</span>424 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {425 <span class="keyword">case</span> <span class="string">'number'</span>:426 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {427 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);428 }429 <span class="variable">body</span> = <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span> = <span class="variable">body</span>];430 <span class="keyword">break</span>;431 <span class="keyword">case</span> <span class="string">'string'</span>:432 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {433 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);434 }435 <span class="keyword">break</span>;436 <span class="keyword">case</span> <span class="string">'object'</span>:More docs :)Tj Holowaychukbefore adoption0c5fe61
line 437why, one step back437 <span class="keyword">if</span> (<span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>) {More docsTj Holowaychukbefore adoptionbedff32
line 438why, one step back438 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {More docs :)Tj Holowaychukbefore adoption0c5fe61
lines 439–442why, one step back439 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.bin'</span>);440 }441 } <span class="keyword">else</span> {442 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {More docsTj Holowaychukbefore adoptionbedff32
lines 443–467why, one step back443 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);444 }445 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);446 }447 <span class="keyword">break</span>;448 }449450 <span class="comment">// Populate Content-Length</span>451 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {452 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Length'</span>, <span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>453 ? <span class="variable">body</span>.<span class="variable">length</span>454 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));455 }456457 <span class="comment">// Merge headers passed</span>458 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">headers</span>, <span class="variable">headers</span>);459460 <span class="comment">// Respond</span>461 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span>, <span class="this">this</span>.<span class="variable">headers</span>);462 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);463};</code></pre>464</td>465</tr>466<tr class="code">467<td class="docs">Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 468–472why, one step back468<p>Transfer the given <code>file</code>. Automatically sets the <em>Content-Type</em>469response header, and responds with 404 / 500 appropriately.</p>470471<h2></h2>472Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 473why, one step back473<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 474–492why, one step back474</td>475<td class="code">476<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">sendfile</span> = <span class="keyword">function</span>(<span class="variable">file</span>){477 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;478 <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">file</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">buf</span>){479 <span class="keyword">if</span> (<span class="variable">err</span>) {480 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">err</span>.<span class="variable">errno</span> === <span class="variable">process</span>.<span class="class">ENOENT</span>481 ? <span class="number integer">404</span>482 : <span class="number integer">500</span>);483 } <span class="keyword">else</span> {484 <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">file</span>);485 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);486 }487 });488};</code></pre>489</td>490</tr>491<tr class="code">492<td class="docs">More docsTj Holowaychukbefore adoptionbedff32
lines 493–498why, one step back493<p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>494495<h2>Examples</h2>496497<pre><code>var filename = 'path/to/image.png';498res.contentType(filename);Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 499why, one step back499// res.headers['Content-Type'] is now "image/png"</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 500–502why, one step back500501<h2></h2>502Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 503why, one step back503<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>More docsTj Holowaychukbefore adoptionbedff32
lines 504–516why, one step back504</td>505<td class="code">506<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">contentType</span> = <span class="keyword">function</span>(<span class="variable">type</span>){507 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Type'</span>, <span class="variable">mime</span>.<span class="variable">type</span>(<span class="variable">type</span>));508};</code></pre>509</td>510</tr>511<tr class="code">512<td class="docs">513<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>514515<h2></h2>516Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 517why, one step back517<ul><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>More docsTj Holowaychukbefore adoptionbedff32
lines 518–529why, one step back518</td>519<td class="code">520<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">attachment</span> = <span class="keyword">function</span>(<span class="variable">filename</span>){521 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>522 ? <span class="string">'attachment; filename="'</span> + <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">filename</span>) + <span class="string">'"'</span>523 : <span class="string">'attachment'</span>);524 <span class="keyword">return</span> <span class="this">this</span>;525};</code></pre>526</td>527</tr>528<tr class="code">529<td class="docs">Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 530–533why, one step back530<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>531532<h2></h2>533Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 534why, one step back534<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 535–543why, one step back535</td>536<td class="code">537<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">download</span> = <span class="keyword">function</span>(<span class="variable">file</span>, <span class="variable">filename</span>){538 <span class="this">this</span>.<span class="variable">attachment</span>(<span class="variable">filename</span> || <span class="variable">file</span>).<span class="variable">sendfile</span>(<span class="variable">file</span>);539};</code></pre>540</td>541</tr>542<tr class="code">543<td class="docs">More docsTj Holowaychukbefore adoptionbedff32
lines 544–547why, one step back544<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>545546<h2></h2>547Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 548why, one step back548<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>More docsTj Holowaychukbefore adoptionbedff32
lines 549–563why, one step back549</td>550<td class="code">551<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">val</span>){552 <span class="keyword">return</span> <span class="variable">val</span> === <span class="variable">undefined</span>553 ? <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>]554 : <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;555};</code></pre>556</td>557</tr>558<tr class="code">559<td class="docs">560<p>Redirect to the given <code>url</code> with optional response <code>status</code>561defauling to 302.</p>562563<p>The given <code>url</code> can also be the name of a mapped url, forRegenerated api docsTj Holowaychukbefore adoption69baa6e
lines 564–566why, one step back564example by default express supports "back" which redirects565to the <em>Referrer</em> or <em>Referer</em> headers or the application's566"home" setting. Express also supports "home" out of the box,More docsTj Holowaychukbefore adoptionbedff32
line 567why, one step back567which can be set via <code>app.set('home', '/blog');</code>, and defaultsRegenerated api docsTj Holowaychukbefore adoption69baa6e
line 568why, one step back568to '/'.</p>More docsTj Holowaychukbefore adoptionbedff32
lines 569–574why, one step back569570<h2>Redirect Mapping</h2>571572<p> To extend the redirect mapping capabilities that Express provides,573 we may use the <code>app.redirect()</code> method:</p>574Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 575why, one step back575<pre><code>app.redirect('google', 'http://google.com');</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 576–578why, one step back576577<p> Now in a route we may call:</p>578Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 579why, one step back579<pre><code>res.redirect('google');</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 580–584why, one step back580581<p> We may also map dynamic redirects:</p>582583<pre><code> app.redirect('comments', function(req, res, params){584 return '/post/' + params.id + '/comments';Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 585why, one step back585 });</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 586–592why, one step back586587<p> So now we may do the following, and the redirect will dynamically adjust to588 the context of the request. If we called this route with <em>GET /post/12</em> our589 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>590591<pre><code> app.get('/post/:id', function(req, res){592 res.redirect('comments');Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 593why, one step back593 });</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 594–596why, one step back594595<h2></h2>596Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 597why, one step back597<ul><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>More docsTj Holowaychukbefore adoptionbedff32
lines 598–620why, one step back598</td>599<td class="code">600<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">url</span>, <span class="variable">status</span>){601 <span class="keyword">var</span> <span class="variable">basePath</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>) || <span class="string">'/'</span>;602603 <span class="comment">// Setup redirect map</span>604 <span class="keyword">var</span> <span class="variable">map</span> = {605 <span class="variable">back</span>: <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referrer</span> || <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referer</span> || <span class="variable">basePath</span>,606 <span class="variable">home</span>: <span class="variable">basePath</span>607 };608609 <span class="comment">// Support custom redirect map</span>610 <span class="variable">map</span>.<span class="variable">__proto__</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">redirects</span>;611612 <span class="comment">// Attempt mapped redirect</span>613 <span class="keyword">var</span> <span class="variable">mapped</span> = <span class="keyword">typeof</span> <span class="variable">map</span>[<span class="variable">url</span>] === <span class="string">'function'</span>614 ? <span class="variable">map</span>[<span class="variable">url</span>](<span class="this">this</span>.<span class="variable">req</span>, <span class="this">this</span>, <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>)615 : <span class="variable">map</span>[<span class="variable">url</span>];616617 <span class="comment">// Perform redirect</span>618 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span> || <span class="number integer">302</span>, { <span class="string">'Location'</span>: <span class="variable">mapped</span> || <span class="variable">url</span> });619 <span class="this">this</span>.<span class="variable">end</span>();620};Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
lines 621–622why, one step back621</code></pre>622</td>Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 623–632why, one step back623</tr><tr class="filename"><td><h2 id="lib/express/server.js"><a href="#">server</a></h2></td><td>lib/express/server.js</td></tr><tr class="code">624<td class="docs">625<p>Module dependencies.626 </p>627</td>628<td class="code">629<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),630 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),631 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),632 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
line 633why, one step back633 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 634–651why, one step back634 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),635 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>636</td>637</tr>638<tr class="code">639<td class="docs">640<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>641642<h2></h2>643644<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>645</td>646<td class="code">647<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Server</span>(<span class="variable">middleware</span>){648 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;649 <span class="this">this</span>.<span class="variable">config</span> = {};650 <span class="this">this</span>.<span class="variable">settings</span> = {};651 <span class="this">this</span>.<span class="variable">redirects</span> = {};Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
lines 652–653why, one step back652 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};653 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 654–673why, one step back654 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">middleware</span> || []);655656 <span class="comment">// Expose objects to each other</span>657 <span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){658 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};659 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};660 <span class="variable">res</span>.<span class="variable">headers</span> = {};661 <span class="variable">req</span>.<span class="variable">app</span> = <span class="variable">res</span>.<span class="variable">app</span> = <span class="variable">self</span>;662 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;663 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;664 <span class="comment">// Assign req.params.get</span>665 <span class="keyword">if</span> (<span class="variable">req</span>.<span class="variable">url</span>.<span class="variable">indexOf</span>(<span class="string">'?'</span>) &<span class="variable">gt</span>; <span class="number integer">0</span>) {666 <span class="comment">// TODO: consider simple substr to increase performance</span>667 <span class="keyword">var</span> <span class="variable">query</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">query</span>;668 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = <span class="variable">queryString</span>.<span class="variable">parse</span>(<span class="variable">query</span>);669 }670 <span class="variable">next</span>();671 });672673 <span class="comment">// Use router, expose as app.get(), etc</span>Added view helper docs. Closes #344Tj Holowaychukbefore adoptionc4b5208
line 674why, one step back674 <span class="this">this</span>.<span class="variable">router</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 675–710why, one step back675};</code></pre>676</td>677</tr>678<tr class="code">679<td class="docs">680<p>Inherit from <code>connect.Server</code>.681 </p>682</td>683<td class="code">684<pre><code><span class="variable">sys</span>.<span class="variable">inherits</span>(<span class="class">Server</span>, <span class="variable">connect</span>.<span class="class">Server</span>);</code></pre>685</td>686</tr>687<tr class="code">688<td class="docs">689<p>Start listening on the given <code>port</code> / <code>host</code>.</p>690691<h2></h2>692693<ul><li><p><strong>param</strong>: <em>Number</em> port</p></li><li><p><strong>param</strong>: <em>String</em> host</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>694</td>695<td class="code">696<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span> = <span class="keyword">function</span>(<span class="variable">port</span>, <span class="variable">host</span>){697 <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>, <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">EXPRESS_ENV</span> || <span class="variable">process</span>.<span class="variable">connectEnv</span>.<span class="variable">name</span>);698 <span class="this">this</span>.<span class="variable">runConfig</span>(<span class="string">'any'</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>));699700 <span class="comment">// Setup view reloading</span>701 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {702 <span class="variable">view</span>.<span class="variable">watcher</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>));703 }704705 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">port</span>, <span class="variable">host</span>);706};</code></pre>707</td>708</tr>709<tr class="code">710<td class="docs">Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 711–719why, one step back711<p>Register the given view helpers <code>obj</code>. This method712can be called several times to apply additional helpers.</p>713714<h2></h2>715716<ul><li><p><strong>param</strong>: <em>Object</em> obj</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>717</td>718<td class="code">719<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">helpers</span> = <span class="keyword">function</span>(<span class="variable">obj</span>){Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
line 720why, one step back720 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">viewHelpers</span>, <span class="variable">obj</span>);Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
lines 721–735why, one step back721 <span class="keyword">return</span> <span class="this">this</span>;722};</code></pre>723</td>724</tr>725<tr class="code">726<td class="docs">727<p>Register the given dynamic view helpers <code>obj</code>. This method728can be called several times to apply additional helpers.</p>729730<h2></h2>731732<ul><li><p><strong>param</strong>: <em>Object</em> obj</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>733</td>734<td class="code">735<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">dynamicHelpers</span> = <span class="keyword">function</span>(<span class="variable">obj</span>){Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
line 736why, one step back736 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">dynamicViewHelpers</span>, <span class="variable">obj</span>);Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 737–742why, one step back737 <span class="keyword">return</span> <span class="this">this</span>;738};</code></pre>739</td>740</tr>741<tr class="code">742<td class="docs">Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 743–838why, one step back743<p>Assign a custom exception handler callback <code>fn</code>.</p>744745<h2></h2>746747<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>748</td>749<td class="code">750<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">error</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){751 <span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){752 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);753 });754 <span class="keyword">return</span> <span class="this">this</span>;755};</code></pre>756</td>757</tr>758<tr class="code">759<td class="docs">760<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>761762<h2></h2>763764<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Server | Mixed</em> for chaining, or the setting value</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>765</td>766<td class="code">767<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">set</span> = <span class="keyword">function</span>(<span class="variable">setting</span>, <span class="variable">val</span>){768 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {769 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];770 } <span class="keyword">else</span> {771 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;772 <span class="keyword">return</span> <span class="this">this</span>;773 }774};</code></pre>775</td>776</tr>777<tr class="code">778<td class="docs">779<p>Enable <code>setting</code>.</p>780781<h2></h2>782783<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>784</td>785<td class="code">786<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">enable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){787 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">true</span>);788};</code></pre>789</td>790</tr>791<tr class="code">792<td class="docs">793<p>Disable <code>setting</code>.</p>794795<h2></h2>796797<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>798</td>799<td class="code">800<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">disable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){801 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">false</span>);802};</code></pre>803</td>804</tr>805<tr class="code">806<td class="docs">807<p>Redirect <code>key</code> to <code>url</code>.</p>808809<h2></h2>810811<ul><li><p><strong>param</strong>: <em>String</em> key</p></li><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>812</td>813<td class="code">814<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">url</span>){815 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;816 <span class="keyword">return</span> <span class="this">this</span>;817};</code></pre>818</td>819</tr>820<tr class="code">821<td class="docs">822<p>Disable <code>setting</code>.</p>823824<h2></h2>825826<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>827</td>828<td class="code">829<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">configure</span> = <span class="keyword">function</span>(<span class="variable">env</span>, <span class="variable">fn</span>){830 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">env</span> === <span class="string">'function'</span>) <span class="variable">fn</span> = <span class="variable">env</span>, <span class="variable">env</span> = <span class="string">'any'</span>;831 (<span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] || []).<span class="variable">push</span>(<span class="variable">fn</span>);832 <span class="keyword">return</span> <span class="this">this</span>;833};834835<span class="comment">// Generate routing methods</span>836837(<span class="keyword">function</span>(<span class="variable">method</span>){838 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){Added view helper docs. Closes #344Tj Holowaychukbefore adoptionc4b5208
lines 839–842why, one step back839 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {840 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);841 <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;842 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 843–848why, one step back843 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);844 <span class="keyword">return</span> <span class="this">this</span>;845 };846 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;847})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);848</code></pre>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
line 849why, one step back849</td>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 850why, one step back850</tr><tr class="filename"><td><h2 id="lib/express/view.js"><a href="#">view</a></h2></td><td>lib/express/view.js</td></tr><tr class="code">More docs :)Tj Holowaychukbefore adoption0c5fe61
line 851why, one step back851<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 852–853why, one step back852<p>Module dependencies.853 </p>More docs :)Tj Holowaychukbefore adoption0c5fe61
lines 854–855why, one step back854</td>855<td class="code">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 856–857why, one step back856<pre><code><span class="keyword">var</span> <span class="variable">extname</span> = <span class="variable">require</span>(<span class="string">'path'</span>).<span class="variable">extname</span>,857 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 858why, one step back858 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 859why, one step back859 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),Regenerated docsTj Holowaychukbefore adoption09147a2
line 860why, one step back860 <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 861–869why, one step back861 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>862</td>863</tr>864<tr class="code">865<td class="docs">866<p>Cache supported template engine exports to867increase performance by lowering the number868of calls to <code>require()</code>.</p>869Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 870why, one step back870<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 871–872why, one step back871</td>872<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 873–878why, one step back873<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>874</td>875</tr>876<tr class="code">877<td class="docs">878<p>Cache view contents to prevent I/O hits.</p>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 879why, one step back879Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 880why, one step back880<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 881why, one step back881</td>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 882–884why, one step back882<td class="code">883<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>884</td>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 885–887why, one step back885</tr>886<tr class="code">887<td class="docs">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 888–889why, one step back888<p>Clear the view cache.</p>889Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 890why, one step back890<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 891–899why, one step back891</td>892<td class="code">893<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){894 <span class="variable">viewCache</span> = {};895};</code></pre>896</td>897</tr>898<tr class="code">899<td class="docs">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 900–903why, one step back900<p>Render <code>view</code> partial with the given <code>options</code>.</p>901902<h2>Options</h2>903Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 904why, one step back904<ul><li><p><code>object</code> Single object with name derived from the view (unless <code>as</code> is present) </p></li><li><p><code>as</code> Variable name for each <code>collection</code> value, defaults to the view name.</p><ul><li>as: 'something' will add the <code>something</code> local variable</li><li>as: this will use the collection value as the template context</li><li><p>as: global will merge the collection value's properties with <code>locals</code></p></li></ul></li><li><p><code>collection</code> Array of objects, the name is derived from the view name itself. Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 905why, one step back905For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
line 906why, one step back906Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 907–908why, one step back907<h2></h2>908Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 909why, one step back909<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 910–911why, one step back910</td>911<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
line 912why, one step back912<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>){Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 913why, one step back913 <span class="comment">// Inherit parent view extension when not present</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 914–916why, one step back914 <span class="keyword">if</span> (<span class="variable">ext</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {915 <span class="variable">view</span> += <span class="variable">ext</span>;916 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 917–918why, one step back917918 <span class="comment">// Allow collection to be passed as second param</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 919–921why, one step back919 <span class="keyword">if</span> (<span class="variable">options</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {920 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };921 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 922–923why, one step back922923 <span class="comment">// Defaults</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 924why, one step back924 <span class="variable">options</span> = <span class="variable">options</span> || {};Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 925why, one step back925 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 926–927why, one step back926 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;927 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 928–929why, one step back928929 <span class="comment">// Collection support</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 930–933why, one step back930 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;931 <span class="keyword">if</span> (<span class="variable">collection</span>) {932 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>],933 <span class="variable">len</span> = <span class="variable">collection</span>.<span class="variable">length</span>;Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 934–935why, one step back934 <span class="keyword">delete</span> <span class="variable">options</span>.<span class="variable">collection</span>;935 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">collectionLength</span> = <span class="variable">len</span>;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 936why, one step back936 <span class="keyword">return</span> <span class="variable">collection</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">i</span>){Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 937–945why, one step back937 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">firstInCollection</span> = <span class="variable">i</span> === <span class="number integer">0</span>;938 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;939 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">lastInCollection</span> = <span class="variable">i</span> === <span class="variable">len</span> - <span class="number integer">1</span>;940 <span class="variable">options</span>.<span class="variable">object</span> = <span class="variable">val</span>;941 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">partial</span>(<span class="variable">view</span>, <span class="variable">options</span>);942 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);943 } <span class="keyword">else</span> {944 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">object</span>) {945 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>];Regenerated docsTj Holowaychukbefore adoption09147a2
line 946why, one step back946 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">name</span> === <span class="string">'string'</span>) {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 947why, one step back947 <span class="variable">options</span>.<span class="variable">locals</span>[<span class="variable">name</span>] = <span class="variable">options</span>.<span class="variable">object</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 948why, one step back948 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">name</span> === <span class="variable">global</span>) {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 949why, one step back949 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">options</span>.<span class="variable">locals</span>, <span class="variable">options</span>.<span class="variable">object</span>);Regenerated docsTj Holowaychukbefore adoption09147a2
line 950why, one step back950 } <span class="keyword">else</span> {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 951why, one step back951 <span class="variable">options</span>.<span class="variable">context</span> = <span class="variable">options</span>.<span class="variable">object</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 952why, one step back952 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 953why, one step back953 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 954–964why, one step back954 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">render</span>(<span class="variable">view</span>, <span class="variable">options</span>);955 }956};</code></pre>957</td>958</tr>959<tr class="code">960<td class="docs">961<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.962When a callback function is given a response will <em>not</em> be made963automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>964Updated docsTj Holowaychukbefore adoption09dabef
lines 965–969why, one step back965<h2>Options</h2>966967<p> Most engines accept one or more of the following options,968 both <em>haml</em> and <em>jade</em> accept all:</p>969More view docsTj Holowaychukbefore adoption1c8ff48
line 970why, one step back970<ul><li><code>context|scope</code> Template evaluation context (<code>this</code>)</li><li><code>locals</code> Object containing local variables</li><li><code>filename</code> Filename used for the <code>cache</code> option</li><li><code>cache</code> Cache intermediate JavaScript in memory</li><li><code>debug</code> Output debugging information</li></ul>Updated docsTj Holowaychukbefore adoption09dabef
line 971why, one step back971Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 972–973why, one step back972<h2></h2>973Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 974why, one step back974<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 975–978why, one step back975</td>976<td class="code">977<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">fn</span>){978 <span class="variable">options</span> = <span class="variable">options</span> || {};Regenerated docsTj Holowaychukbefore adoption09147a2
line 979why, one step back979 <span class="keyword">var</span> <span class="variable">defaultEngine</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'view engine'</span>);Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 980why, one step back980Regenerated docsTj Holowaychukbefore adoption09147a2
lines 981–985why, one step back981 <span class="comment">// Support "view engine" setting</span>982 <span class="keyword">if</span> (<span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">defaultEngine</span>) {983 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;984 }985Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 986–987why, one step back986 <span class="comment">// Defaults</span>987 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
lines 988–989why, one step back988 <span class="variable">helpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">viewHelpers</span>,989 <span class="variable">dynamicHelpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">dynamicViewHelpers</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 990why, one step back990 <span class="variable">root</span> = <span class="variable">viewRoot</span>(<span class="this">this</span>.<span class="variable">app</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 991–996why, one step back991 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),992 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,993 <span class="variable">layout</span> = <span class="variable">options</span>.<span class="variable">layout</span> === <span class="variable">undefined</span> ? <span class="variable">true</span> : <span class="variable">options</span>.<span class="variable">layout</span>,994 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>995 ? <span class="string">'layout'</span> + <span class="variable">ext</span>996 : <span class="variable">layout</span>;Updated docsTj Holowaychukbefore adoption09dabef
line 997why, one step back997Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 998–1002why, one step back998 <span class="comment">// Allow layout name without extension</span>999 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">layout</span> === <span class="string">'string'</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">layout</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {1000 <span class="variable">layout</span> += <span class="variable">ext</span>;1001 }1002In depth partial docsTj Holowaychukbefore adoption793943f
lines 1003–1005why, one step back1003 <span class="comment">// Normalize "context" to "scope"</span>1004 <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>;1005Updated docsTj Holowaychukbefore adoption09dabef
lines 1006–1009why, one step back1006 <span class="comment">// Auto-cache in production</span>1007 <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>) {1008 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;1009 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1010–1027why, one step back10101011 <span class="comment">// Partials support</span>1012 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1013 <span class="variable">root</span> += <span class="string">'/partials'</span>;1014 }10151016 <span class="comment">// View path</span>1017 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;10181019 <span class="comment">// Send response</span>1020 <span class="keyword">function</span> <span class="variable">send</span>(<span class="variable">str</span>) {1021 <span class="variable">self</span>.<span class="variable">writeHead</span>(<span class="number integer">200</span>, {1022 <span class="string">'Content-Type'</span>: <span class="string">'text/html'</span>,1023 <span class="string">'Content-Length'</span>: <span class="variable">str</span>.<span class="variable">length</span>1024 });1025 <span class="variable">self</span>.<span class="variable">end</span>(<span class="variable">str</span>);1026 }1027Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1028–1030why, one step back1028 <span class="comment">// Pass filename to the engine and view</span>1029 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1030 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__filename</span> = <span class="variable">options</span>.<span class="variable">filename</span> = <span class="variable">path</span>;Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 1031–1040why, one step back10311032 <span class="comment">// Dynamic helper support</span>1033 <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">dynamicHelpers</span>);1034 <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {1035 <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1036 <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1037 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1038 <span class="variable">helpers</span>[<span class="variable">key</span>] = <span class="variable">val</span>.<span class="variable">call</span>(<span class="this">this</span>.<span class="variable">app</span>, <span class="this">this</span>.<span class="variable">req</span>, <span class="this">this</span>, <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>);1039 }1040 }Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1041–1045why, one step back10411042 <span class="comment">// Always expose partial() as a local</span>1043 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>){1044 <span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">partial</span>.<span class="variable">call</span>(<span class="variable">self</span>, <span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>);1045 };Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 1046–1047why, one step back1046 1047 <span class="comment">// Merge view helpers</span>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 1048why, one step back1048 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__proto__</span> = <span class="variable">helpers</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 1049why, one step back1049Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1050–1057why, one step back1050 <span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">err</span>) {1051 <span class="keyword">if</span> (<span class="variable">fn</span>) {1052 <span class="variable">fn</span>(<span class="variable">err</span>);1053 } <span class="keyword">else</span> {1054 <span class="keyword">throw</span> <span class="variable">err</span>;1055 }1056 }1057Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1058–1059why, one step back1058 <span class="comment">// Cache contents</span>1059 <span class="keyword">try</span> {Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2
line 1060why, one step back1060 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">viewCache</span>[<span class="variable">path</span>] || <span class="variable">cacheViewSync</span>(<span class="variable">path</span>);Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1061–1088why, one step back1061 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1062 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1063 }10641065 <span class="comment">// Cache template engine exports</span>1066 <span class="keyword">var</span> <span class="variable">engine</span> = <span class="variable">cache</span>[<span class="variable">ext</span>] || (<span class="variable">cache</span>[<span class="variable">ext</span>] = <span class="variable">require</span>(<span class="variable">ext</span>.<span class="variable">substr</span>(<span class="number integer">1</span>)));10671068 <span class="comment">// Attempt render</span>1069 <span class="keyword">try</span> {1070 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">engine</span>.<span class="variable">render</span>(<span class="variable">str</span>, <span class="variable">options</span>);1071 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1072 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1073 }10741075 <span class="comment">// Layout support</span>1076 <span class="keyword">if</span> (<span class="variable">layout</span>) {1077 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1078 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1079 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1080 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1081 <span class="keyword">return</span> <span class="variable">str</span>;1082 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1083 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1084 } <span class="keyword">else</span> {1085 <span class="variable">send</span>(<span class="variable">str</span>);1086 }1087};1088</code></pre>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1089–1091why, one step back1089</td>1090</tr> </body>1091</html></tbody></table>