api.html
This file
Path
docs/api.html
1,089 lines · 56.6 KiB · HTML
Last changed by
Fixed bannerTj Holowaychukbefore adoption2fda5c7
History of this fileTake it
Generated docsTj Holowaychukbefore adoptionbafa300
lines 1–138why, one step back1<html>2 <head>3 <title>Express</title>4 <style>body {5 margin: 0;6 padding: 0;7 font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;8 color: #252519;9}10a {11 color: #252519;12}13a:hover {14 text-decoration: underline;15 color: #19469D;16}17p {18 margin: 12px 0;19}20h1, h2, h3 {21 margin: 0;22 padding: 0;23}24ul#menu {25 opacity: 0;26 position: fixed;27 top: 0;28 right: 0;29 list-style: none;30 margin: 0;31 padding: 10px 2px;32 text-align: right;33 background: rgba(255,255,255,0.7);34 -webkit-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);35 -moz-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);36 -webkit-border-bottom-left-radius: 5px;37 -moz-border-bottom-left-radius: 5px;38 -webkit-transition-properties: opacity;39 -webkit-transition-duration: 0.6s;40}41ul#menu:hover {42 opacity: 1;43}44ul#menu li {45 padding: 2px 10px;46 border-bottom: 1px solid #eee;47}48ul#menu li:hover {49 background: rgba(0,0,0,0.03);50}51ul#menu li:last-child {52 border-bottom: none;53}54ul#menu li a {55 text-decoration: none;56 font-size: 12px;57 color: rgba(0,0,0,0.5);58}59ul#menu li a strong {60 font-weight: normal;61 color: #252519;62}63table#source {64 width: 100%;65 border-collapse: collapse;66}67table#source td:first-child {68 padding: 30px 40px 30px 40px;69 vertical-align: top;70}71table#source td:first-child,72table#source td:first-child pre {73 width: 450px;74}75table#source td:last-child {76 padding: 30px 0 30px 40px;77 border-left: 1px solid #E5E5EE;78 background: #F5F5FF;79}80table#source tr {81 border-bottom: 1px solid #E5E5EE;82}83table#source tr.filename {84 padding-top: 40px;85 border-top: 1px solid #E5E5EE;86}87table#source tr.filename td:first-child {88 text-transform: capitalize;89}90table#source tr.filename td:last-child {91 font-size: 12px;92}93table#source tr.filename h2 {94 margin: 0;95 padding: 0;96}97table#source tr.code h1,98table#source tr.code h2,99table#source tr.code h3 {100 margin-top: 30px;101 font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;102 font-size: 18px;103}104table#source tr.code h2 {105 font-size: 16px;106}107table#source tr.code h3 {108 font-size: 14px;109}110table#source tr.code ul {111 margin: 15px 0 15px 35px;112 padding: 0;113}114table#source tr.code ul li {115 margin: 0;116 padding: 1px 0;117}118table#source tr.code ul li p {119 margin: 0;120 padding: 0;121}122table#source tr.code td:first-child pre {123 padding: 20px;124}125#ribbon {126 position: absolute;127 top: 0;128 right: 0;129}130code .string { color: #219161; }131code .regexp { color: #219161; }132code .keyword { color: #954121; }133code .number { color: #19469D; }134code .comment { color: #bbb; }135code .this { color: #19469D; }</style>136 </head>137 <body>138<ul id="menu"><li><a href="#lib/express/index.js">lib/express/<strong>index</strong></a></li>Updated docsTj Holowaychukbefore adoption09dabef
line 139why, one step back139<li><a href="#lib/express/request.js">lib/express/<strong>request</strong></a></li>Generated docsTj Holowaychukbefore adoptionbafa300
lines 140–141why, one step back140<li><a href="#lib/express/response.js">lib/express/<strong>response</strong></a></li>141<li><a href="#lib/express/server.js">lib/express/<strong>server</strong></a></li>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 142why, one step back142<li><a href="#lib/express/utils.js">lib/express/<strong>utils</strong></a></li>Updated docsTj Holowaychukbefore adoption09dabef
line 143why, one step back143<li><a href="#lib/express/view.js">lib/express/<strong>view</strong></a></li></ul><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">index</h2></td><td>lib/express/index.js</td></tr><tr class="code">Generated docsTj Holowaychukbefore adoptionbafa300
line 144why, one step back144<td class="docs">Updated docsTj Holowaychukbefore adoption09dabef
lines 145–152why, one step back145<p>Framework version.</p>146</td>147<td class="code">148<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.14.0'</span>;</code></pre>149</td>150</tr>151<tr class="code">152<td class="docs">Generated docsTj Holowaychukbefore adoptionbafa300
lines 153–155why, one step back153<p>Module dependencies.</p>154</td>155<td class="code">Updated docsTj Holowaychukbefore adoption09dabef
lines 156–187why, one step back156<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">require</span>(<span class="string">'./server'</span>);</code></pre>157</td>158</tr>159<tr class="code">160<td class="docs">161<p>Shortcut for <code>new Server(...)</code>.</p>162163<h2></h2>164165<ul>166<li><p><strong>param</strong>: <em>Function</em> …</p></li>167<li><p><strong>return</strong>: <em>Server</em></p></li>168<li><p><strong>api</strong>: <em>public</em></p></li>169</ul>170171</td>172<td class="code">173<pre><code><span class="variable">exports</span>.<span class="variable">createServer</span> = <span class="keyword">function</span>(){174 <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>));175};</code></pre>176</td>177</tr>178<tr class="code">179<td class="docs">180<p>View extensions.</p>181</td>182<td class="code">183<pre><code><span class="variable">require</span>(<span class="string">'./view'</span>);184<span class="variable">require</span>(<span class="string">'./request'</span>);185<span class="variable">require</span>(<span class="string">'./response'</span>);186</code></pre>187</td>Fixed bannerTj Holowaychukbefore adoption2fda5c7
lines 188–344why, one step back188</tr><tr class="filename"><td><h2 id="lib/express/response.js">response</h2></td><td>lib/express/response.js</td></tr><tr class="code">189<td class="docs">190<p>Module dependencies.</p>191</td>192<td class="code">193<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),194 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),195 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),196 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,197 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>198</td>199</tr>200<tr class="code">201<td class="docs">202<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>203204<h2>Examples</h2>205206<pre><code>res.send(new Buffer('wahoo'));207res.send({ some: 'json' });208res.send('<p>some html</p>');209res.send('Sorry, cant find that', 404);210res.send('text', { 'Content-Type': 'text/plain' }, 201);211res.send(404);212</code></pre>213214<h2></h2>215216<ul>217<li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li>218<li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li>219<li><p><strong>param</strong>: <em>Number</em> status</p></li>220<li><p><strong>return</strong>: <em>ServerResponse</em></p></li>221<li><p><strong>api</strong>: <em>public</em></p></li>222</ul>223224</td>225<td class="code">226<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>){227 <span class="comment">// Allow status as second arg</span>228 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {229 <span class="variable">status</span> = <span class="variable">headers</span>,230 <span class="variable">headers</span> = <span class="keyword">null</span>;231 }232233 <span class="comment">// Defaults</span>234 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;235 <span class="variable">headers</span> = <span class="variable">headers</span> || {};236237 <span class="comment">// Determine content type</span>238 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {239 <span class="keyword">case</span> <span class="string">'number'</span>:240 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {241 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);242 }243 <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>];244 <span class="keyword">break</span>;245 <span class="keyword">case</span> <span class="string">'string'</span>:246 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {247 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);248 }249 <span class="keyword">break</span>;250 <span class="keyword">case</span> <span class="string">'object'</span>:251 <span class="keyword">if</span> (!(<span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>)) {252 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {253 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);254 }255 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);256 }257 <span class="keyword">break</span>;258 }259260 <span class="comment">// Populate Content-Length</span>261 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {262 <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>263 ? <span class="variable">body</span>.<span class="variable">length</span>264 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));265 }266267 <span class="comment">// Merge headers passed</span>268 <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>);269270 <span class="comment">// Respond</span>271 <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>);272 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);273};</code></pre>274</td>275</tr>276<tr class="code">277<td class="docs">278<p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>279280<h2>Examples</h2>281282<pre><code>var filename = 'path/to/image.png';283res.contentType(filename);284// res.headers['Content-Type'] is now "image/png"285</code></pre>286287<h2></h2>288289<ul>290<li><p><strong>param</strong>: <em>String</em> type</p></li>291<li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li>292<li><p><strong>api</strong>: <em>public</em></p></li>293</ul>294295</td>296<td class="code">297<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>){298 <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>));299};</code></pre>300</td>301</tr>302<tr class="code">303<td class="docs">304<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>305306<h2></h2>307308<ul>309<li><p><strong>param</strong>: <em>String</em> filename</p></li>310<li><p><strong>return</strong>: <em>ServerResponse</em></p></li>311<li><p><strong>api</strong>: <em>public</em></p></li>312</ul>313314</td>315<td class="code">316<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>){317 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>318 ? <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>319 : <span class="string">'attachment'</span>);320 <span class="keyword">return</span> <span class="this">this</span>;321};</code></pre>322</td>323</tr>324<tr class="code">325<td class="docs">326<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>327328<h2></h2>329330<ul>331<li><p><strong>param</strong>: <em>String</em> name</p></li>332<li><p><strong>param</strong>: <em>String</em> val</p></li>333<li><p><strong>return</strong>: <em>String</em></p></li>334<li><p><strong>api</strong>: <em>public</em></p></li>335</ul>336337</td>338<td class="code">339<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>){340 <span class="keyword">return</span> <span class="variable">val</span> === <span class="variable">undefined</span>341 ? <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>]342 : <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;343};</code></pre>344</td>Updated docsTj Holowaychukbefore adoption09dabef
lines 345–349why, one step back345</tr><tr class="filename"><td><h2 id="lib/express/request.js">request</h2></td><td>lib/express/request.js</td></tr><tr class="code">346<td class="docs">347<p>Module dependencies.</p>348</td>349<td class="code">Generated docsTj Holowaychukbefore adoptionbafa300
line 350why, one step back350<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),Started migration docsTj Holowaychukbefore adoption9e68a5b
line 351why, one step back351 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),Updated docsTj Holowaychukbefore adoption09dabef
lines 352–477why, one step back352 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>353</td>354</tr>355<tr class="code">356<td class="docs">357<p>Return request header or optional default.</p>358359<h2>Examples</h2>360361<pre><code>req.header('Content-Type');362// => "text/plain"363364req.header('content-type');365// => "text/plain"366367req.header('Accept');368// => undefined369370req.header('Accept', 'text/html');371// => "text/html"372</code></pre>373374<h2></h2>375376<ul>377<li><p><strong>param</strong>: <em>String</em> name</p></li>378<li><p><strong>param</strong>: <em>String</em> defaultValue</p></li>379<li><p><strong>return</strong>: <em>String</em></p></li>380<li><p><strong>api</strong>: <em>public</em></p></li>381</ul>382383</td>384<td class="code">385<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>){386 <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>;387};</code></pre>388</td>389</tr>390<tr class="code">391<td class="docs">392<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>393394<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise395the given <code>type</code> is matched by an exact match, and then subtypes. You396may pass the subtype such as “html” which is then converted internally397to “text/html” using the mime lookup table.</p>398399<h2>Examples</h2>400401<pre><code>// Accept: text/html402req.accepts('html');403// => true404405// Accept: text/*; application/json406req.accepts('html');407req.accepts('text/html');408req.accepts('text/plain');409req.accepts('application/json');410// => true411412req.accepts('image/png');413req.accepts('png');414// => false415</code></pre>416417<h2></h2>418419<ul>420<li><p><strong>param</strong>: <em>String</em> type</p></li>421<li><p><strong>return</strong>: <em>Boolean</em></p></li>422<li><p><strong>api</strong>: <em>public</em></p></li>423</ul>424425</td>426<td class="code">427<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>){428 <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>);429 <span class="keyword">if</span> (!<span class="variable">accept</span> || <span class="variable">accept</span> === '*</code></pre>430</td>431</tr>432<tr class="code">433<td class="docs">434<p>‘) {</p>435436<pre><code> return true;437} else if (type) {438 // Allow "html" vs "text/html" etc439 if (type.indexOf('/') < 0) {440 type = mime.types['.' + type];441 }442 // Check if we have a direct match443 if (accept.indexOf(type) >= 0) {444 return true;445 // Check if we have type/*446 } else {447 type = type.split('/')[0] + '/*';448 return accept.indexOf(type) >= 0;449 }450} else {451 return false;452}453</code></pre>454455<p>};</p>456457<p>/**458Return the value of param <code>name</code> when present.</p>459460<ul>461<li>Checks route placeholders, ex: <em>/user/:id</em></li>462<li>Checks query string params, ex: ?id=12</li>463<li>Checks urlencoded body params, ex: id=12</li>464</ul>465466467<p>To utilize urlencoded request bodies, <code>req.body</code>468should be an object. This can be done by using469the <code>connect.bodyDecoder</code> middleware.</p>470471<h2></h2>472473<ul>474<li><p><strong>param</strong>: <em>String</em> name</p></li>475<li><p><strong>return</strong>: <em>String</em></p></li>476<li><p><strong>api</strong>: <em>public</em></p></li>477</ul>Added menu to docsTj Holowaychukbefore adoptionac560be
line 478why, one step back478Updated docsTj Holowaychukbefore adoption09dabef
lines 479–493why, one step back479</td>480<td class="code">481<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>){482 <span class="comment">// Route params like /user/:id</span>483 <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>) {484 <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>]; 485 }486 <span class="comment">// Query string params</span>487 <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>) {488 <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>]; 489 }490 <span class="comment">// Request body params via connect.bodyDecoder</span>491 <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>) {492 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>];493 }Started migration docsTj Holowaychukbefore adoption9e68a5b
line 494why, one step back494};</code></pre>Updated docsTj Holowaychukbefore adoption09dabef
lines 495–498why, one step back495</td>496</tr>497<tr class="code">498<td class="docs">Started migration docsTj Holowaychukbefore adoption9e68a5b
line 499why, one step back499<p>Queue flash <code>msg</code> of the given <code>type</code>.</p>Updated docsTj Holowaychukbefore adoption09dabef
line 500why, one step back500Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 501–502why, one step back501<h2>Examples</h2>502Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 503–506why, one step back503<pre><code> req.flash('info', 'email sent');504 req.flash('error', 'email delivery failed');505 req.flash('info', 'email re-sent');506 // => 2Regenerated docsTj Holowaychukbefore adoption60cfd56
line 507why, one step back507Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 508–509why, one step back508 req.flash('info');509 // => ['email sent', 'email re-sent']Regenerated docsTj Holowaychukbefore adoption60cfd56
line 510why, one step back510Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 511–512why, one step back511 req.flash('info');512 // => []Regenerated docsTj Holowaychukbefore adoption60cfd56
line 513why, one step back513Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 514–515why, one step back514 req.flash();515 // => { error: ['email delivery failed'], info: [] }Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 516–521why, one step back516</code></pre>517518<h2></h2>519520<ul>521<li><p><strong>param</strong>: <em>String</em> type</p></li>Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 522–523why, one step back522<li><p><strong>param</strong>: <em>String</em> msg</p></li>523<li><p><strong>return</strong>: <em>Array | Object | Number</em></p></li>Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 524–528why, one step back524<li><p><strong>api</strong>: <em>public</em></p></li>525</ul>526527</td>528<td class="code">Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 529–542why, one step back529<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>){530 <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> || {};531 <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>) {532 <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>));533 <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>);534 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {535 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];536 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];537 <span class="keyword">return</span> <span class="variable">arr</span> || [];538 } <span class="keyword">else</span> {539 <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = {};540 <span class="keyword">return</span> <span class="variable">msgs</span>;541 }542};Regenerated docsTj Holowaychukbefore adoption60cfd56
line 543why, one step back543Started migration docsTj Holowaychukbefore adoption9e68a5b
line 544why, one step back544<span class="comment">// Callback for isXMLHttpRequest / xhr</span>Regenerated docsTj Holowaychukbefore adoption60cfd56
line 545why, one step back545Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 546–548why, one step back546<span class="keyword">function</span> <span class="variable">isxhr</span>() {547 <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>;548}</code></pre>Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 549–552why, one step back549</td>550</tr>551<tr class="code">552<td class="docs">Started migration docsTj Holowaychukbefore adoption9e68a5b
line 553why, one step back553<p>Check if the request was an <em>XMLHttpRequest</em>.</p>Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 554–557why, one step back554555<h2></h2>556557<ul>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 558why, one step back558<li><p><strong>return</strong>: <em>Boolean</em></p></li>Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 559–563why, one step back559<li><p><strong>api</strong>: <em>public</em></p></li>560</ul>561562</td>563<td class="code">Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 564–565why, one step back564<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>);565<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>Regenerated docsTj Holowaychukbefore adoption60cfd56
line 566why, one step back566</td>Generated docsTj Holowaychukbefore adoptionbafa300
lines 567–572why, one step back567</tr><tr class="filename"><td><h2 id="lib/express/server.js">server</h2></td><td>lib/express/server.js</td></tr><tr class="code">568<td class="docs">569<p>Module dependencies.</p>570</td>571<td class="code">572<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),Updated docsTj Holowaychukbefore adoption09dabef
line 573why, one step back573 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),Regenerated docsTj Holowaychukbefore adoption09147a2
line 574why, one step back574 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),Generated docsTj Holowaychukbefore adoptionbafa300
line 575why, one step back575 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),Updated docsTj Holowaychukbefore adoption09dabef
line 576why, one step back576 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),Generated docsTj Holowaychukbefore adoptionbafa300
lines 577–589why, one step back577 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>578</td>579</tr>580<tr class="code">581<td class="docs">582<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>583584<h2></h2>585586<ul>587<li><p><strong>param</strong>: <em>Array</em> middleware</p></li>588<li><p><strong>api</strong>: <em>public</em></p></li>589</ul>Absolute labs bannerTj Holowaychukbefore adoption2b2fa7e
line 590why, one step back590Generated docsTj Holowaychukbefore adoptionbafa300
lines 591–598why, one step back591</td>592<td class="code">593<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>){594 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;595 <span class="this">this</span>.<span class="variable">config</span> = {};596 <span class="this">this</span>.<span class="variable">settings</span> = {};597 <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> || []);598Updated docsTj Holowaychukbefore adoption09dabef
line 599why, one step back599 <span class="comment">// Expose objects to each other</span>Generated docsTj Holowaychukbefore adoptionbafa300
line 600why, one step back600 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){Updated docsTj Holowaychukbefore adoption09dabef
lines 601–603why, one step back601 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};602 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};603 <span class="variable">res</span>.<span class="variable">headers</span> = {};Generated docsTj Holowaychukbefore adoptionbafa300
line 604why, one step back604 <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>;Updated docsTj Holowaychukbefore adoption09dabef
lines 605–612why, one step back605 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;606 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;607 <span class="comment">// Assign req.params.get</span>608 <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>) {609 <span class="comment">// TODO: consider simple substr to increase performance</span>610 <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>;611 <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>);612 }Generated docsTj Holowaychukbefore adoptionbafa300
lines 613–624why, one step back613 <span class="variable">next</span>();614 });615616 <span class="comment">// Use router, expose as app.get(), etc</span>617 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){618 <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>;619 }));620};</code></pre>621</td>622</tr>623<tr class="code">624<td class="docs">Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 625why, one step back625<p>Inherit from <code>connect.Server</code>.</p>Generated docsTj Holowaychukbefore adoptionbafa300
lines 626–640why, one step back626</td>627<td class="code">628<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>629</td>630</tr>631<tr class="code">632<td class="docs">633<p>Listen on the given <code>port</code> after running configuration blocks.</p>634635<h2></h2>636637<ul>638<li><p><strong>param</strong>: <em>Number</em> port</p></li>639<li><p><strong>api</strong>: <em>public</em></p></li>640</ul>Absolute labs bannerTj Holowaychukbefore adoption2b2fa7e
line 641why, one step back641Generated docsTj Holowaychukbefore adoptionbafa300
lines 642–644why, one step back642</td>643<td class="code">644<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>){Updated docsTj Holowaychukbefore adoption09dabef
lines 645–646why, one step back645 <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>);646 <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>));Regenerated docsTj Holowaychukbefore adoption09147a2
lines 647–652why, one step back647648 <span class="comment">// Setup view reloading</span>649 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {650 <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>));651 }652 Generated docsTj Holowaychukbefore adoptionbafa300
lines 653–720why, one step back653 <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>);654};</code></pre>655</td>656</tr>657<tr class="code">658<td class="docs">659<p>Run config callbacks for the given environment(s);</p>660661<h2></h2>662663<ul>664<li><p><strong>param</strong>: <em>String</em> env …</p></li>665<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>666<li><p><strong>api</strong>: <em>public</em></p></li>667</ul>668669</td>670<td class="code">671<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">runConfig</span> = <span class="keyword">function</span>(){672 <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">arguments</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>) {673 <span class="keyword">var</span> <span class="variable">env</span> = <span class="variable">arguments</span>[<span class="variable">i</span>];674 <span class="keyword">if</span> (<span class="variable">env</span> <span class="keyword">in</span> <span class="this">this</span>.<span class="variable">config</span>) {675 <span class="keyword">var</span> <span class="variable">config</span> = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>];676 <span class="variable">config</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">fn</span>){677 <span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>);678 }, <span class="this">this</span>);679 }680 }681 <span class="keyword">return</span> <span class="this">this</span>;682};</code></pre>683</td>684</tr>685<tr class="code">686<td class="docs">687<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>’s value.</p>688689<h2></h2>690691<ul>692<li><p><strong>param</strong>: <em>String</em> setting</p></li>693<li><p><strong>param</strong>: <em>String</em> val</p></li>694<li><p><strong>return</strong>: <em>Server | Mixed</em> for chaining, or the setting value</p></li>695<li><p><strong>api</strong>: <em>public</em></p></li>696</ul>697698</td>699<td class="code">700<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>){701 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {702 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];703 } <span class="keyword">else</span> {704 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;705 <span class="keyword">return</span> <span class="this">this</span>;706 }707};</code></pre>708</td>709</tr>710<tr class="code">711<td class="docs">712<p>Enable <code>setting</code>.</p>713714<h2></h2>715716<ul>717<li><p><strong>param</strong>: <em>String</em> setting</p></li>718<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>719<li><p><strong>api</strong>: <em>public</em></p></li>720</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 721why, one step back721ZQGenerated docsTj Holowaychukbefore adoptionbafa300
lines 722–739why, one step back722</td>723<td class="code">724<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>){725 <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>);726};</code></pre>727</td>728</tr>729<tr class="code">730<td class="docs">731<p>Disable <code>setting</code>.</p>732733<h2></h2>734735<ul>736<li><p><strong>param</strong>: <em>String</em> setting</p></li>737<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>738<li><p><strong>api</strong>: <em>public</em></p></li>739</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 740why, one step back740PGenerated docsTj Holowaychukbefore adoptionbafa300
lines 741–758why, one step back741</td>742<td class="code">743<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>){744 <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>);745};</code></pre>746</td>747</tr>748<tr class="code">749<td class="docs">750<p>Disable <code>setting</code>.</p>751752<h2></h2>753754<ul>755<li><p><strong>param</strong>: <em>String</em> setting</p></li>756<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>757<li><p><strong>api</strong>: <em>public</em></p></li>758</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 759why, one step back759PGenerated docsTj Holowaychukbefore adoptionbafa300
lines 760–767why, one step back760</td>761<td class="code">762<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>){763 <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>;764 (<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>);765 <span class="keyword">return</span> <span class="this">this</span>;766};767Updated docsTj Holowaychukbefore adoption09dabef
line 768why, one step back768<span class="comment">// Generate routing methods</span>Generated docsTj Holowaychukbefore adoptionbafa300
lines 769–776why, one step back769770(<span class="keyword">function</span>(<span class="variable">method</span>){771 <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>){772 <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>);773 <span class="keyword">return</span> <span class="this">this</span>;774 };775 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;776})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 777–785why, one step back777</code></pre>778</td>779</tr><tr class="filename"><td><h2 id="lib/express/view.js">view</h2></td><td>lib/express/view.js</td></tr><tr class="code">780<td class="docs">781<p>Module dependencies.</p>782</td>783<td class="code">784<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>,785 <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 786why, one step back786 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),Added contributors back to docsTj Holowaychukbefore adoption195c8a9
line 787why, one step back787 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),Regenerated docsTj Holowaychukbefore adoption09147a2
line 788why, one step back788 <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 789–803why, one step back789 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>790</td>791</tr>792<tr class="code">793<td class="docs">794<p>Cache supported template engine exports to795increase performance by lowering the number796of calls to <code>require()</code>.</p>797798<ul>799<li><strong>type</strong>: <em>Object</em></li>800</ul>801802</td>803<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 804–809why, one step back804<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>805</td>806</tr>807<tr class="code">808<td class="docs">809<p>Cache view contents to prevent I/O hits.</p>Added contributors back to docsTj Holowaychukbefore adoption195c8a9
line 810why, one step back810Regenerated docsTj Holowaychukbefore adoption09147a2
lines 811–813why, one step back811<ul>812<li><strong>type</strong>: <em>Object</em></li>813</ul>Added menu to docsTj Holowaychukbefore adoptionac560be
line 814why, one step back814Added contributors back to docsTj Holowaychukbefore adoption195c8a9
line 815why, one step back815</td>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 816–818why, one step back816<td class="code">817<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>818</td>Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 819–821why, one step back819</tr>820<tr class="code">821<td class="docs">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 822–826why, one step back822<p>Clear the view cache.</p>823824<ul>825<li><strong>api</strong>: <em>public</em></li>826</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 827why, one step back827Regenerated docsTj Holowaychukbefore adoption09147a2
lines 828–836why, one step back828</td>829<td class="code">830<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){831 <span class="variable">viewCache</span> = {};832};</code></pre>833</td>834</tr>835<tr class="code">836<td class="docs">Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 837–841why, one step back837<p>View helpers merged with each render’s locals.</p>838839<ul>840<li><strong>type</strong>: <em>Object</em></li>841</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 842why, one step back842Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 843–849why, one step back843</td>844<td class="code">845<pre><code><span class="keyword">var</span> <span class="variable">helpers</span> = <span class="variable">exports</span>.<span class="variable">helpers</span> = {};</code></pre>846</td>847</tr>848<tr class="code">849<td class="docs">Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 850–854why, one step back850<p>Render <code>view</code> partial with the given <code>options</code>.</p>851852<h2>Options</h2>853854<ul>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 855–860why, one step back855<li><p><code>as</code> Variable name for each <code>collection</code> value, defaults to the view name.</p>856857<ul>858<li>as: ‘something’ will add the <code>something</code> local variable</li>859<li>as: this will use the collection value as the template context</li>860<li>as: global will merge the collection value’s properties with <code>locals</code></li>Added contributors back to docsTj Holowaychukbefore adoption195c8a9
line 861why, one step back861</ul>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 862–865why, one step back862</li>863<li><p><code>collection</code> Array of objects, the name is derived from the view name itself.864For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li>865</ul>Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 866–871why, one step back866867868<h2></h2>869870<ul>871<li><p><strong>param</strong>: <em>String</em> view</p></li>Regenerated docsTj Holowaychukbefore adoption09147a2
line 872why, one step back872<li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li>Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 873–875why, one step back873<li><p><strong>return</strong>: <em>String</em></p></li>874<li><p><strong>api</strong>: <em>public</em></p></li>875</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 876why, one step back876ZQAdded contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 877–878why, one step back877</td>878<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 879–885why, one step back879<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>){880 <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>) {881 <span class="variable">view</span> += <span class="variable">ext</span>;882 }883 <span class="keyword">if</span> (<span class="variable">options</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {884 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };885 }Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 886–895why, one step back886 <span class="variable">options</span> = <span class="variable">options</span> || {};887 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;888 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;889 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;890 <span class="keyword">if</span> (<span class="variable">collection</span>) {891 <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>],892 <span class="variable">len</span> = <span class="variable">collection</span>.<span class="variable">length</span>;893 <span class="keyword">var</span> <span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};894 <span class="variable">locals</span>.<span class="variable">collectionLength</span> = <span class="variable">len</span>;895 <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>){Regenerated docsTj Holowaychukbefore adoption09147a2
lines 896–902why, one step back896 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">name</span> === <span class="string">'string'</span>) {897 <span class="variable">locals</span>[<span class="variable">name</span>] = <span class="variable">val</span>;898 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">name</span> === <span class="variable">global</span>) {899 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">locals</span>, <span class="variable">val</span>);900 } <span class="keyword">else</span> {901 <span class="variable">options</span>.<span class="variable">context</span> = <span class="variable">val</span>;902 }Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 903–919why, one step back903 <span class="variable">locals</span>.<span class="variable">firstInCollection</span> = <span class="variable">i</span> === <span class="number integer">0</span>;904 <span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;905 <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>;906 <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>);907 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);908 } <span class="keyword">else</span> {909 <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>);910 }911};</code></pre>912</td>913</tr>914<tr class="code">915<td class="docs">916<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.917When a callback function is given a response will <em>not</em> be made918automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>919Updated docsTj Holowaychukbefore adoption09dabef
lines 920–933why, one step back920<h2>Options</h2>921922<p> Most engines accept one or more of the following options,923 both <em>haml</em> and <em>jade</em> accept all:</p>924925<ul>926<li><code>context</code> Template evaluation context (<code>this</code>)</li>927<li><code>locals</code> Object containing local variables</li>928<li><code>filename</code> Filename used for the <code>cache</code> option</li>929<li><code>cache</code> Cache intermediate JavaScript in memory</li>930<li><code>debug</code> Output debugging information</li>931</ul>932933Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 934–941why, one step back934<h2></h2>935936<ul>937<li><p><strong>param</strong>: <em>String</em> view</p></li>938<li><p><strong>param</strong>: <em>Object</em> options</p></li>939<li><p><strong>param</strong>: <em>Function</em> fn</p></li>940<li><p><strong>api</strong>: <em>public</em></p></li>941</ul>Fixed bannerTj Holowaychukbefore adoption2fda5c7
line 942why, one step back942Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 943–946why, one step back943</td>944<td class="code">945<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>){946 <span class="variable">options</span> = <span class="variable">options</span> || {};Regenerated docsTj Holowaychukbefore adoption09147a2
line 947why, one step back947 <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 contributors back to docsTj Holowaychukbefore adoption195c8a9
line 948why, one step back948Regenerated docsTj Holowaychukbefore adoption09147a2
lines 949–953why, one step back949 <span class="comment">// Support "view engine" setting</span>950 <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>) {951 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;952 }953Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 954–955why, one step back954 <span class="comment">// Defaults</span>955 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 956why, one step back956 <span class="variable">root</span> = <span class="variable">viewRoot</span>(<span class="this">this</span>.<span class="variable">app</span>),Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 957–962why, one step back957 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),958 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,959 <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>,960 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>961 ? <span class="string">'layout'</span> + <span class="variable">ext</span>962 : <span class="variable">layout</span>;Updated docsTj Holowaychukbefore adoption09dabef
lines 963–967why, one step back963964 <span class="comment">// Auto-cache in production</span>965 <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>) {966 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;967 }Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 968–985why, one step back968969 <span class="comment">// Partials support</span>970 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {971 <span class="variable">root</span> += <span class="string">'/partials'</span>;972 }973974 <span class="comment">// View path</span>975 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;976977 <span class="comment">// Send response</span>978 <span class="keyword">function</span> <span class="variable">send</span>(<span class="variable">str</span>) {979 <span class="variable">self</span>.<span class="variable">writeHead</span>(<span class="number integer">200</span>, {980 <span class="string">'Content-Type'</span>: <span class="string">'text/html'</span>,981 <span class="string">'Content-Length'</span>: <span class="variable">str</span>.<span class="variable">length</span>982 });983 <span class="variable">self</span>.<span class="variable">end</span>(<span class="variable">str</span>);984 }985Regenerated docsTj Holowaychukbefore adoption09147a2
lines 986–993why, one step back986 <span class="comment">// Pass filename to the engine and view</span>987 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};988 <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>;989990 <span class="comment">// Always expose partial() as a local</span>991 <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>){992 <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>);993 };Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 994–995why, one step back994 995 <span class="comment">// Merge view helpers</span>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 996why, one step back996 <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 997why, one step back997Added contributors back to docsTj Holowaychukbefore adoption195c8a9
lines 998–1005why, one step back998 <span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">err</span>) {999 <span class="keyword">if</span> (<span class="variable">fn</span>) {1000 <span class="variable">fn</span>(<span class="variable">err</span>);1001 } <span class="keyword">else</span> {1002 <span class="keyword">throw</span> <span class="variable">err</span>;1003 }1004 }1005Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1006–1036why, one step back1006 <span class="comment">// Cache contents</span>1007 <span class="keyword">try</span> {1008 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">viewCache</span>[<span class="variable">path</span>] || <span class="variable">cacheView</span>(<span class="variable">path</span>);1009 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1010 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1011 }10121013 <span class="comment">// Cache template engine exports</span>1014 <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>)));10151016 <span class="comment">// Attempt render</span>1017 <span class="keyword">try</span> {1018 <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>);1019 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1020 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1021 }10221023 <span class="comment">// Layout support</span>1024 <span class="keyword">if</span> (<span class="variable">layout</span>) {1025 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1026 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1027 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1028 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1029 <span class="keyword">return</span> <span class="variable">str</span>;1030 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1031 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1032 } <span class="keyword">else</span> {1033 <span class="variable">send</span>(<span class="variable">str</span>);1034 }1035};1036</code></pre>Fixed bannerTj Holowaychukbefore adoption2fda5c7
lines 1037–1086why, one step back1037</td>1038</tr><tr class="filename"><td><h2 id="lib/express/utils.js">utils</h2></td><td>lib/express/utils.js</td></tr><tr class="code">1039<td class="docs">1040<p>Parse mini markdown implementation.1041The following conversions are supported,1042primarily for the “flash” middleware:</p>10431044<p> <em>foo</em> or <em>foo</em> become <em>foo</em>1045 <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>1046 <a href="B">A</a> becomes <a href="B">A</a></p>10471048<h2></h2>10491050<ul>1051<li><p><strong>param</strong>: <em>String</em> str</p></li>1052<li><p><strong>return</strong>: <em>String</em></p></li>1053<li><p><strong>api</strong>: <em>public</em></p></li>1054</ul>10551056</td>1057<td class="code">1058<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){1059 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)1060 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)1061 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)1062 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);1063};</code></pre>1064</td>1065</tr>1066<tr class="code">1067<td class="docs">1068<p>Escape special characters in the given string of html.</p>10691070<h2></h2>10711072<ul>1073<li><p><strong>param</strong>: <em>String</em> html</p></li>1074<li><p><strong>return</strong>: <em>String</em></p></li>1075<li><p><strong>api</strong>: <em>public</em></p></li>1076</ul>10771078</td>1079<td class="code">1080<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {1081 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)1082 .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)1083 .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)1084 .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)1085 .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);1086};</code></pre>Generated docsTj Holowaychukbefore adoptionbafa300
lines 1087–1089why, one step back1087</td>1088</tr> </body>1089</html></tbody></table>