Skip to content
Myr

Merge branch 'docs' into connect

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents 1aad62b, 3ced7b7 · Browse files · 12 files+411 added−270 removed
This commit

State

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

Diff stats

12 files+411 added−270 removed

  • other:+411 added−270 removed

12 files+411 added−270 removed

modified:docs/layout/head.html+17 added
modified:docs/api.html+226 added-226 removed
149 unmodified lines
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>154</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">155<td class="docs">156<p>Parse mini markdown implementation.157The following conversions are supported,158primarily for the "flash" middleware:</p>159160<p> <em>foo</em> or <em>foo</em> become &lt;em&gt;foo&lt;/em&gt;161 <strong>foo</strong> or <strong>foo</strong> become &lt;strong&gt;foo&lt;/strong&gt;162 <a href="B">A</a> becomes &lt;a href="B"&gt;A&lt;/a&gt;</p>163164<h2></h2>165166<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>167</td>168<td class="code">169<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){170 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)171 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)172 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)173 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</span>);174};</code></pre>175</td>176</tr>177<tr class="code">178<td class="docs">179<p>Escape special characters in the given string of html.</p>180181<h2></h2>182183<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>184</td>185<td class="code">186<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {187 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)188 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)189 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)190 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)191 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);192};</code></pre>193</td>194</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">195<td class="docs">196<p>Module dependencies.197 </p>198</td>199<td class="code">200<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),201 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),202 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>203</td>204</tr>205<tr class="code">206<td class="docs">207<p>Return request header or optional default.</p>208209<h2>Examples</h2>210211<pre><code>req.header('Content-Type');212// =&gt; "text/plain"213214req.header('content-type');215// =&gt; "text/plain"216217req.header('Accept');218// =&gt; undefined219220req.header('Accept', 'text/html');221// =&gt; "text/html"</code></pre>222223<h2></h2>224225<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>226</td>227<td class="code">228<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>){229 <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>;230};</code></pre>231</td>232</tr>233<tr class="code">234<td class="docs">235<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>236237<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise238the given <code>type</code> is matched by an exact match, and then subtypes. You239may pass the subtype such as "html" which is then converted internally240to "text/html" using the mime lookup table.</p>241242<h2>Examples</h2>243244<pre><code>// Accept: text/html245req.accepts('html');246// =&gt; true247248// Accept: text/*; application/json249req.accepts('html');250req.accepts('text/html');251req.accepts('text/plain');252req.accepts('application/json');253// =&gt; true254255req.accepts('image/png');256req.accepts('png');257// =&gt; false</code></pre>258259<h2></h2>260261<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>262</td>263<td class="code">264<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>){265 <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>);266 <span class="keyword">if</span> (!<span class="variable">accept</span> || <span class="variable">accept</span> === '*</code></pre>267</td>268</tr>269<tr class="code">270<td class="docs">271<p>') {272 return true;273 } else if (type) {274 // Allow "html" vs "text/html" etc275 if (type.indexOf('/') &lt; 0) {276 type = mime.types['.' + type];277 }278 // Check if we have a direct match279 if (accept.indexOf(type) &gt;= 0) {280 return true;281 // Check if we have type/<em>282 } else {283 type = type.split('/')[0] + '/</em>';284 return accept.indexOf(type) &gt;= 0;285 }286 } else {287 return false;288 }289};</p>290291<p>/**292Return the value of param <code>name</code> when present.</p>293294<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>295296<p>To utilize urlencoded request bodies, <code>req.body</code>297should be an object. This can be done by using298the <code>connect.bodyDecoder</code> middleware.</p>299300<h2></h2>301302<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>303</td>304<td class="code">305<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>){306 <span class="comment">// Route params like /user/:id</span>307 <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>) {308 <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>]; 309 }310 <span class="comment">// Query string params</span>311 <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>) {312 <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>]; 313 }314 <span class="comment">// Request body params via connect.bodyDecoder</span>315 <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>) {316 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>];317 }318};</code></pre>319</td>320</tr>321<tr class="code">322<td class="docs">323<p>Queue flash <code>msg</code> of the given <code>type</code>.</p>324325<h2>Examples</h2>326327<pre><code> req.flash('info', 'email sent');328 req.flash('error', 'email delivery failed');329 req.flash('info', 'email re-sent');330 // =&gt; 2331332 req.flash('info');333 // =&gt; ['email sent', 'email re-sent']334335 req.flash('info');336 // =&gt; []337338 req.flash();339 // =&gt; { error: ['email delivery failed'], info: [] }</code></pre>340341<h2></h2>342343<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>344</td>345<td class="code">346<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>){347 <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> || {};348 <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>) {349 <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>));350 <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>);351 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {352 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];353 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];354 <span class="keyword">return</span> <span class="variable">arr</span> || [];355 } <span class="keyword">else</span> {356 <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = {};357 <span class="keyword">return</span> <span class="variable">msgs</span>;358 }359};360361<span class="comment">// Callback for isXMLHttpRequest / xhr</span>362363<span class="keyword">function</span> <span class="variable">isxhr</span>() {364 <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>;365}</code></pre>366</td>367</tr>368<tr class="code">369<td class="docs">370<p>Check if the request was an <em>XMLHttpRequest</em>.</p>371372<h2></h2>373374<ul><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>375</td>376<td class="code">377<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>);378<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>379</td>154</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">155<td class="docs">156<p>Module dependencies.157 </p>
448 unmodified lines
606 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;607})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);608</code></pre>609</td>610</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">611<td class="docs">612<p>Module dependencies.613 </p>614</td>615<td class="code">616<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),617 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),618 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>619</td>620</tr>621<tr class="code">622<td class="docs">623<p>Return request header or optional default.</p>624625<h2>Examples</h2>626627<pre><code>req.header('Content-Type');628// =&gt; "text/plain"629630req.header('content-type');631// =&gt; "text/plain"632633req.header('Accept');634// =&gt; undefined635636req.header('Accept', 'text/html');637// =&gt; "text/html"</code></pre>638639<h2></h2>640641<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>642</td>643<td class="code">644<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>){645 <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>;646};</code></pre>647</td>648</tr>649<tr class="code">650<td class="docs">651<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>652653<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise654the given <code>type</code> is matched by an exact match, and then subtypes. You655may pass the subtype such as "html" which is then converted internally656to "text/html" using the mime lookup table.</p>657658<h2>Examples</h2>659660<pre><code>// Accept: text/html661req.accepts('html');662// =&gt; true663664// Accept: text/*; application/json665req.accepts('html');666req.accepts('text/html');667req.accepts('text/plain');668req.accepts('application/json');669// =&gt; true670671req.accepts('image/png');672req.accepts('png');673// =&gt; false</code></pre>674675<h2></h2>676677<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>678</td>679<td class="code">680<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>){681 <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>);682 <span class="keyword">if</span> (!<span class="variable">accept</span> || <span class="variable">accept</span> === '*</code></pre>683</td>684</tr>685<tr class="code">686<td class="docs">687<p>') {688 return true;689 } else if (type) {690 // Allow "html" vs "text/html" etc691 if (type.indexOf('/') &lt; 0) {692 type = mime.types['.' + type];693 }694 // Check if we have a direct match695 if (accept.indexOf(type) &gt;= 0) {696 return true;697 // Check if we have type/<em>698 } else {699 type = type.split('/')[0] + '/</em>';700 return accept.indexOf(type) &gt;= 0;701 }702 } else {703 return false;704 }705};</p>706707<p>/**708Return the value of param <code>name</code> when present.</p>709710<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>711712<p>To utilize urlencoded request bodies, <code>req.body</code>713should be an object. This can be done by using714the <code>connect.bodyDecoder</code> middleware.</p>715716<h2></h2>717718<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>719</td>720<td class="code">721<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>){722 <span class="comment">// Route params like /user/:id</span>723 <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>) {724 <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>]; 725 }726 <span class="comment">// Query string params</span>727 <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>) {728 <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>]; 729 }730 <span class="comment">// Request body params via connect.bodyDecoder</span>731 <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>) {732 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>];733 }734};</code></pre>735</td>736</tr>737<tr class="code">738<td class="docs">739<p>Queue flash <code>msg</code> of the given <code>type</code>.</p>740741<h2>Examples</h2>742743<pre><code> req.flash('info', 'email sent');744 req.flash('error', 'email delivery failed');745 req.flash('info', 'email re-sent');746 // =&gt; 2747748 req.flash('info');749 // =&gt; ['email sent', 'email re-sent']750751 req.flash('info');752 // =&gt; []753754 req.flash();755 // =&gt; { error: ['email delivery failed'], info: [] }</code></pre>756757<h2></h2>758759<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>760</td>761<td class="code">762<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>){763 <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> || {};764 <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>) {765 <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>));766 <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>);767 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {768 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];769 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];770 <span class="keyword">return</span> <span class="variable">arr</span> || [];771 } <span class="keyword">else</span> {772 <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = {};773 <span class="keyword">return</span> <span class="variable">msgs</span>;774 }775};776777<span class="comment">// Callback for isXMLHttpRequest / xhr</span>778779<span class="keyword">function</span> <span class="variable">isxhr</span>() {780 <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>;781}</code></pre>782</td>783</tr>784<tr class="code">785<td class="docs">786<p>Check if the request was an <em>XMLHttpRequest</em>.</p>787788<h2></h2>789790<ul><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>791</td>792<td class="code">793<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>);794<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>795</td>796</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">797<td class="docs">798<p>Module dependencies.799 </p>
210 unmodified lines
1010 }1011};1012</code></pre>1013</td>1014</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">1015<td class="docs">1016<p>Parse mini markdown implementation.1017The following conversions are supported,1018primarily for the "flash" middleware:</p>10191020<p> <em>foo</em> or <em>foo</em> become &lt;em&gt;foo&lt;/em&gt;1021 <strong>foo</strong> or <strong>foo</strong> become &lt;strong&gt;foo&lt;/strong&gt;1022 <a href="B">A</a> becomes &lt;a href="B"&gt;A&lt;/a&gt;</p>10231024<h2></h2>10251026<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>1027</td>1028<td class="code">1029<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){1030 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)1031 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)1032 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)1033 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</span>);1034};</code></pre>1035</td>1036</tr>1037<tr class="code">1038<td class="docs">1039<p>Escape special characters in the given string of html.</p>10401041<h2></h2>10421043<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>1044</td>1045<td class="code">1046<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {1047 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)1048 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)1049 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)1050 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)1051 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);1052};</code></pre>1053</td>1054</tr> </body>1055</html></tbody></table>
modified:docs/contrib.html+17 added
42 unmodified lines
43 border: none !important; }4445 a {46 font-weight: bold;47 text-decoration: none;48 color: white;49 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;50 -webkit-transition-duration: 0.15s;51 -webkit-transition-timing-function: ease-out; }
60 unmodified lines
112 margin: 0 auto;113 padding-top: 110px;114 width: 550px; }115116 #toc {117 position: fixed;118 top: 60px;119 left: 0;120 margin: 0 0 0 15px;121 padding: 15px;122 height: 100%;123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }
84 unmodified lines
modified:docs/executable.html+17 added
42 unmodified lines
43 border: none !important; }4445 a {46 font-weight: bold;47 text-decoration: none;48 color: white;49 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;50 -webkit-transition-duration: 0.15s;51 -webkit-transition-timing-function: ease-out; }
60 unmodified lines
112 margin: 0 auto;113 padding-top: 110px;114 width: 550px; }115116 #toc {117 position: fixed;118 top: 60px;119 left: 0;120 margin: 0 0 0 15px;121 padding: 15px;122 height: 100%;123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }
66 unmodified lines
modified:docs/guide.1+12 added-12 removed
248 unmodified lines
249.fi250.251.IP "" 0252.253.SS "ServerRequest#header(key[, defaultValue])"253.SS "Request#header(key[, defaultValue])"254Get the case\-insensitive request header \fIkey\fR, with optional \fIdefaultValue\fR:255.256.IP "" 4257.
6 unmodified lines
264.fi265.266.IP "" 0267.268.SS "ServerRequest#accepts(type)"268.SS "Request#accepts(type)"269Check if the \fIAccept\fR header is present, and includes the given \fItype\fR\.270.271.P272When the \fIAccept\fR header is not present \fItrue\fR is returned\. Otherwise the given \fItype\fR is matched by an exact match, and then subtypes\. You may pass the subtype such as \"html\" which is then converted internally to \"text/html\" using the mime lookup table\.
20 unmodified lines
293.fi294.295.IP "" 0296.297.SS "ServerRequest#param(name)"297.SS "Request#param(name)"298Return the value of param \fIname\fR when present\.299.300.IP "\(bu" 4301Checks route placeholders, ex: /user/:id
8 unmodified lines
310.311.P312To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIconnect\.bodyDecoder\fR middleware\.313.314.SS "ServerRequest#flash(type[, msg])"314.SS "Request#flash(type[, msg])"315Queue flash \fImsg\fR of the given \fItype\fR\.316.317.IP "" 4318.
16 unmodified lines
335.fi336.337.IP "" 0338.339.SS "ServerRequest#isXMLHttpRequest"339.SS "Request#isXMLHttpRequest"340Also aliased as \fIreq\.xhr\fR, this getter checks the \fIX\-Requested\-With\fR header to see if it was issued by an \fIXMLHttpRequest\fR:341.342.IP "" 4343.
5 unmodified lines
349.fi350.351.IP "" 0352.353.SS "ServerResponse#header(key[, val])"353.SS "Response#header(key[, val])"354Get or set the response header \fIkey\fR\.355.356.IP "" 4357.
11 unmodified lines
369.fi370.371.IP "" 0372.373.SS "ServerResponse#contentType(type)"373.SS "Response#contentType(type)"374Sets the \fIContent\-Type\fR response header to the given \fItype\fR\.375.376.IP "" 4377.
6 unmodified lines
384.fi385.386.IP "" 0387.388.SS "ServerResponse#attachment([filename])"388.SS "Response#attachment([filename])"389Sets the \fIContent\-Disposition\fR response header to \"attachment\", with optional \fIfilename\fR\.390.391.IP "" 4392.
4 unmodified lines
397.fi398.399.IP "" 0400.401.SS "ServerResponse#sendfile(path)"401.SS "Response#sendfile(path)"402Used by \fBres\.download()\fR to transfer an arbitrary file\.403.404.IP "" 4405.
7 unmodified lines
413.414.P415\fBNOTE\fR: this is \fInot\fR a replacement for Connect\'s \fIstaticProvider\fR middleware, nor does it perform any security checks, use with caution when using in a dynamic manor\.416.417.SS "ServerResponse#download(file[, filename])"417.SS "Response#download(file[, filename])"418Transfer the given \fIfile\fR as an attachment with optional alternative \fIfilename\fR\.419.420.IP "" 4421.
19 unmodified lines
441.fi442.443.IP "" 0444.445.SS "ServerRequest#send(body|status[, headers|status[, status]])"445.SS "Response#send(body|status[, headers|status[, status]])"446The \fBres\.send()\fR method is a high level response utility allowing you to pass objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status code based responses\. The following are all valid uses:447.448.IP "" 4449.
12 unmodified lines
462.463.P464By default the \fIContent\-Type\fR response header is set, however if explicitly assigned through \fBres\.send()\fR or previously with \fBres\.header()\fR or \fBres\.contentType()\fR it will not be set again\.465.466.SS "ServerResponse#redirect(url[, status])"466.SS "Response#redirect(url[, status])"467Redirect to the given \fIurl\fR with a default response \fIstatus\fR of 302\.468.469.IP "" 4470.
64 unmodified lines
modified:docs/guide.html+51 added-13 removed
42 unmodified lines
43 border: none !important; }4445 a {46 font-weight: bold;47 text-decoration: none;48 color: white;49 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;50 -webkit-transition-duration: 0.15s;51 -webkit-transition-timing-function: ease-out; }
60 unmodified lines
112 margin: 0 auto;113 padding-top: 110px;114 width: 550px; }115116 #toc {117 position: fixed;118 top: 60px;119 left: 0;120 margin: 0 0 0 15px;121 padding: 15px;122 height: 100%;123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }
27 unmodified lines
163 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 164 </a>165 <div id="header"><strong>Sencha</strong> labs</div>166 <div id="wrapper">150 <div id="container">167 <div id="container"><ul id="toc">168<li><a href="#Installation">Installation</a></li>169<li><a href="#Creating-An-Application">Creating An Application</a></li>170<li><a href="#Configuration">Configuration</a></li>171<li><a href="#Settings">Settings</a></li>172<li><a href="#Routing">Routing</a></li>173<li><a href="#Passing-Route-Control">Passing Route Control</a></li>174<li><a href="#Middleware">Middleware</a></li>175<li><a href="#Request-header-key-defaultValue-">Request#header</a></li>176<li><a href="#Request-accepts-type-">Request#accepts</a></li>177<li><a href="#Request-param-name-">Request#param</a></li>178<li><a href="#Request-flash-type-msg-">Request#flash</a></li>179<li><a href="#Request-isXMLHttpRequest">Request#isXMLHttpRequest</a></li>180<li><a href="#Response-header-key-val-">Response#header</a></li>181<li><a href="#Response-contentType-type-">Response#contentType</a></li>182<li><a href="#Response-attachment-filename-">Response#attachment</a></li>183<li><a href="#Response-sendfile-path-">Response#sendfile</a></li>184<li><a href="#Response-download-file-filename-">Response#download</a></li>185<li><a href="#Response-send-body-status-headers-status-status-">Response#send</a></li>186<li><a href="#Response-redirect-url-status-">Response#redirect</a></li>187<li><a href="#Server-redirect-name-val-">Server#redirect</a></li>188</ul>189 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 190 <p id="tagline">191 High performance, high class web development for192 <a href="http://nodejs.org">Node.js</a>
175 unmodified lines
368 connect.bodyDecoder()369);370</code></pre>371334<h3 id="ServerRequest-header-key-defaultValue-">ServerRequest#header(key[, defaultValue])</h3>372<h3 id="Request-header-key-defaultValue-">Request#header(key[, defaultValue])</h3>373374<p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>375376<pre><code>req.header('Host');377req.header('host');378req.header('Accept', '*/*');379</code></pre>380343<h3 id="ServerRequest-accepts-type-">ServerRequest#accepts(type)</h3>381<h3 id="Request-accepts-type-">Request#accepts(type)</h3>382383<p>Check if the <em>Accept</em> header is present, and includes the given <em>type</em>.</p>384385<p>When the <em>Accept</em> header is not present <em>true</em> is returned. Otherwise
16 unmodified lines
402req.accepts('png');403// =&gt; false404</code></pre>405368<h3 id="ServerRequest-param-name-">ServerRequest#param(name)</h3>406<h3 id="Request-param-name-">Request#param(name)</h3>407408<p>Return the value of param <em>name</em> when present.</p>409410<ul>
6 unmodified lines
417<p>To utilize urlencoded request bodies, <em>req.body</em>418should be an object. This can be done by using419the <em>connect.bodyDecoder</em> middleware.</p>420383<h3 id="ServerRequest-flash-type-msg-">ServerRequest#flash(type[, msg])</h3>421<h3 id="Request-flash-type-msg-">Request#flash(type[, msg])</h3>422423<p>Queue flash <em>msg</em> of the given <em>type</em>.</p>424425<pre><code>req.flash('info', 'email sent');
10 unmodified lines
436req.flash();437// =&gt; { error: ['email delivery failed'], info: [] }438</code></pre>439402<h3 id="ServerRequest-isXMLHttpRequest">ServerRequest#isXMLHttpRequest</h3>440<h3 id="Request-isXMLHttpRequest">Request#isXMLHttpRequest</h3>441442<p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header443to see if it was issued by an <em>XMLHttpRequest</em>:</p>444445<pre><code>req.xhr446req.isXMLHttpRequest447</code></pre>448411<h3 id="ServerResponse-header-key-val-">ServerResponse#header(key[, val])</h3>449<h3 id="Response-header-key-val-">Response#header(key[, val])</h3>450451<p>Get or set the response header <em>key</em>.</p>452453<pre><code>res.header('Content-Length');
5 unmodified lines
459res.header('Content-Length');460// =&gt; 123461</code></pre>462425<h3 id="ServerResponse-contentType-type-">ServerResponse#contentType(type)</h3>463<h3 id="Response-contentType-type-">Response#contentType(type)</h3>464465<p>Sets the <em>Content-Type</em> response header to the given <em>type</em>.</p>466467<pre><code> var filename = 'path/to/image.png';468 res.contentType(filename);469 // res.headers['Content-Type'] is now "image/png"470</code></pre>471434<h3 id="ServerResponse-attachment-filename-">ServerResponse#attachment([filename])</h3>472<h3 id="Response-attachment-filename-">Response#attachment([filename])</h3>473474<p>Sets the <em>Content-Disposition</em> response header to "attachment", with optional <em>filename</em>.</p>475476<pre><code> res.attachment('path/to/my/image.png');477</code></pre>478441<h3 id="ServerResponse-sendfile-path-">ServerResponse#sendfile(path)</h3>479<h3 id="Response-sendfile-path-">Response#sendfile(path)</h3>480481<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>482483<pre><code>res.sendfile('path/to/my.file');
1 unmodified line
485486<p><strong>NOTE</strong>: this is <em>not</em> a replacement for Connect's <em>staticProvider</em> middleware,487nor does it perform any security checks, use with caution when using in a dynamic manor.</p>488451<h3 id="ServerResponse-download-file-filename-">ServerResponse#download(file[, filename])</h3>489<h3 id="Response-download-file-filename-">Response#download(file[, filename])</h3>490491<p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>492493<pre><code>res.download('path/to/image.png');
5 unmodified lines
499<pre><code>res.attachment(file);500res.sendfile(file);501</code></pre>502465<h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>503<h3 id="Response-send-body-status-headers-status-status-">Response#send(body|status[, headers|status[, status]])</h3>504505<p>The <code>res.send()</code> method is a high level response utility allowing you to pass506objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status507code based responses. The following are all valid uses:</p>
9 unmodified lines
517<p>By default the <em>Content-Type</em> response header is set, however if explicitly518assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>519it will not be set again.</p>520483<h3 id="ServerResponse-redirect-url-status-">ServerResponse#redirect(url[, status])</h3>521<h3 id="Response-redirect-url-status-">Response#redirect(url[, status])</h3>522523<p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>524525<pre><code>res.redirect('/', 301);
42 unmodified lines
modified:docs/guide.md+12 added-12 removed
153 unmodified lines
154 connect.logger(),155 connect.bodyDecoder()156 );157158### ServerRequest#header(key[, defaultValue])158### Request#header(key[, defaultValue])159160Get the case-insensitive request header _key_, with optional _defaultValue_:161162 req.header('Host');163 req.header('host');164 req.header('Accept', '*/*');165166### ServerRequest#accepts(type)166### Request#accepts(type)167168Check if the _Accept_ header is present, and includes the given _type_.169170When the _Accept_ header is not present _true_ is returned. Otherwise
15 unmodified lines
186 req.accepts('image/png');187 req.accepts('png');188 // => false189190### ServerRequest#param(name)190### Request#param(name)191192Return the value of param _name_ when present.193194 - Checks route placeholders, ex: /user/:id
3 unmodified lines
198To utilize urlencoded request bodies, _req.body_199should be an object. This can be done by using200the _connect.bodyDecoder_ middleware.201202### ServerRequest#flash(type[, msg])202### Request#flash(type[, msg])203204Queue flash _msg_ of the given _type_.205206 req.flash('info', 'email sent');
9 unmodified lines
216217 req.flash();218 // => { error: ['email delivery failed'], info: [] }219220### ServerRequest#isXMLHttpRequest220### Request#isXMLHttpRequest221222Also aliased as _req.xhr_, this getter checks the _X-Requested-With_ header223to see if it was issued by an _XMLHttpRequest_:224225 req.xhr226 req.isXMLHttpRequest227228### ServerResponse#header(key[, val])228### Response#header(key[, val])229230Get or set the response header _key_.231232 res.header('Content-Length');
4 unmodified lines
237238 res.header('Content-Length');239 // => 123240241### ServerResponse#contentType(type)241### Response#contentType(type)242243Sets the _Content-Type_ response header to the given _type_.244245 var filename = 'path/to/image.png';246 res.contentType(filename);247 // res.headers['Content-Type'] is now "image/png"248249### ServerResponse#attachment([filename])249### Response#attachment([filename])250251Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.252253 res.attachment('path/to/my/image.png');254255### ServerResponse#sendfile(path)255### Response#sendfile(path)256257Used by `res.download()` to transfer an arbitrary file. 258259 res.sendfile('path/to/my.file');260261**NOTE**: this is _not_ a replacement for Connect's _staticProvider_ middleware,262nor does it perform any security checks, use with caution when using in a dynamic manor.263264### ServerResponse#download(file[, filename])264### Response#download(file[, filename])265266Transfer the given _file_ as an attachment with optional alternative _filename_.267268 res.download('path/to/image.png');
3 unmodified lines
272273 res.attachment(file);274 res.sendfile(file);275276### ServerRequest#send(body|status[, headers|status[, status]])276### Response#send(body|status[, headers|status[, status]])277278The `res.send()` method is a high level response utility allowing you to pass279objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status280code based responses. The following are all valid uses:
8 unmodified lines
289By default the _Content-Type_ response header is set, however if explicitly290assigned through `res.send()` or previously with `res.header()` or `res.contentType()`291it will not be set again.292293### ServerResponse#redirect(url[, status])293### Response#redirect(url[, status])294295Redirect to the given _url_ with a default response _status_ of 302.296297 res.redirect('/', 301);
32 unmodified lines
modified:docs/index.html+17 added
42 unmodified lines
43 border: none !important; }4445 a {46 font-weight: bold;47 text-decoration: none;48 color: white;49 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;50 -webkit-transition-duration: 0.15s;51 -webkit-transition-timing-function: ease-out; }
60 unmodified lines
112 margin: 0 auto;113 padding-top: 110px;114 width: 550px; }115116 #toc {117 position: fixed;118 top: 60px;119 left: 0;120 margin: 0 0 0 15px;121 padding: 15px;122 height: 100%;123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }
92 unmodified lines
modified:docs/migrate.html+17 added
42 unmodified lines
43 border: none !important; }4445 a {46 font-weight: bold;47 text-decoration: none;48 color: white;49 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;50 -webkit-transition-duration: 0.15s;51 -webkit-transition-timing-function: ease-out; }
60 unmodified lines
112 margin: 0 auto;113 padding-top: 110px;114 width: 550px; }115116 #toc {117 position: fixed;118 top: 60px;119 left: 0;120 margin: 0 0 0 15px;121 padding: 15px;122 height: 100%;123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }
262 unmodified lines
added:support/toc.js+21 added
1#!/usr/bin/env node23var fs = require('fs'),4 file = process.argv[2];56if (file) {7 var js = fs.readFileSync(file, 'utf8'),8 headers = js.match(/<h3 id="(.*?)">(.*?)<\/h3>/g),9 toc = ['<ul id="toc">'];10 if (js.indexOf('id="toc"') < 0) {11 headers.forEach(function(header){12 var captures = header.match(/id="(.*?)">(.*?)</),13 id = captures[1],14 title = captures[2].replace(/\(.*?\)/, '');15 toc.push('<li><a href="#' + id + '">' + title + '</a></li>');16 });17 toc.push('</ul>');18 js = js.replace('<div id="container">', '<div id="container">' + toc.join('\n'));19 fs.writeFileSync(file, js);20 }21}
modified:.pomo-5 removed
21 unmodified lines
22- !ruby/object:Pomo::Task 23 complete: false24 description: 25 length: 2526 name: design mode with browser reloading27- !ruby/object:Pomo::Task 28 complete: false29 description: 30 length: 2526 name: generated TOC for guide
modified:Makefile+4 added-2 removed
45 unmodified lines
46test-cov:47 @TESTFLAGS=--cov $(MAKE) test4849docs: docs/api.html $(MANPAGES) $(HTMLDOCS)50 @ echo "... generating TOC"51 @./support/toc.js docs/guide.html5253docs/api.html: lib/express/*.js54 dox --title Express \55 --desc "High performance web framework for [node](http://nodejs.org)." \56 $(shell find lib/express/* -type f) > $@5758%.1: %.md59 @echo "... $< -> $@"58 @ronn -r --pipe $< > $@ &60 @ronn -r --pipe $< > $@6162%.html: %.md63 @echo "... $< -> $@"64 @ronn -5 --pipe --fragment $< \65 | cat docs/layout/head.html - docs/layout/foot.html \66 | sed 's/NAME/Express/g' \65 > $@ &67 > $@6869docclean:70 rm -f docs/*.{1,html}71
1 unmodified line