Rebuilt docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent cc27ee0 · Browse files · 8 files·+220 added−62 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+220 added−62 removed
- other:+220 added−62 removed
Provenance
- Commit
d017c3e- Tree
6a3b023- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
cc27ee0
8 files changed+220 added−62 removed
modified:docs/api.htmlbinary
A binary file, modified.
modified:docs/guide.1+125 added-3 removed
1 .\" generated with Ronn/v0.7.32 .\" http://github.com/rtomayko/ronn/tree/0.7.33 .4-.TH "GUIDE" "" "October 2010" "" ""4+.TH "GUIDE" "" "November 2010" "" ""5 .6 .SH "NAME"7 \fBguide\fR8 .252 unmodified lines261 .fi262 .263 .IP "" 0264 .265+.P266+For example we can \fBPOST\fR some json, and echo the json back using the \fIbodyDecoder\fR middleware which will parse json request bodies (as well as others), and place the result in \fIreq\.body\fR:267+.268+.IP "" 4269+.270+.nf271+272+var express = require(\'express\')273+ , app = express\.createServer();274+275+app\.use(express\.bodyDecoder());276+277+app\.post(\'/\', function(req, res){278+ res\.send(req\.body);279+});280+281+app\.listen(3000);282+.283+.fi284+.285+.IP "" 0286+.287 .SS "Passing Route Control"288 We may pass control to the next \fImatching\fR route, by calling the \fIthird\fR argument, the \fInext()\fR function\. When a match cannot be made, control is passed back to Connect, and middleware continue to be invoked\. The same is true for several routes which have the same path defined, they will simply be executed in order until one does \fInot\fR call \fInext()\fR\.289 .290 .IP "" 416 unmodified lines307 .fi308 .309 .IP "" 0310 .311+.P312+Express 1\.0 also introduces the \fIall()\fR method, which provides a route callback matching any HTTP method\. This is useful in many ways, one example being the loading of resources before executing subsequent routes as shown below:313+.314+.IP "" 4315+.316+.nf317+318+var express = require(\'express\')319+ , app = express\.createServer();320+321+var users = [{ name: \'tj\' }];322+323+app\.all(\'/user/:id/:op?\', function(req, res, next){324+ req\.user = users[req\.params\.id];325+ if (req\.user) {326+ next();327+ } else {328+ next(new Error(\'cannot find user \' + req\.params\.id));329+ }330+});331+332+app\.get(\'/user/:id\', function(req, res){333+ res\.send(\'viewing \' + req\.user\.name);334+});335+336+app\.get(\'/user/:id/edit\', function(req, res){337+ res\.send(\'editing \' + req\.user\.name);338+});339+340+app\.put(\'/user/:id\', function(req, res){341+ res\.send(\'updating \' + req\.user\.name);342+});343+344+app\.get(\'*\', function(req, res){345+ res\.send(\'what???\', 404);346+});347+348+app\.listen(3000);349+.350+.fi351+.352+.IP "" 0353+.354 .SS "Middleware"355 Middleware via Connect \fIhttp://github\.com/senchalabs/connect\fR can be passed to \fIexpress\.createServer()\fR as you would with a regular Connect server\. For example:356 .357 .IP "" 4578 unmodified lines936 .937 .IP "\(bu" 4938 CoffeeKup \fIhttp://github\.com/mauricemach/coffeekup\fR CoffeeScript based templating939 .940+.IP "\(bu" 4941+jQuery Templates \fIhttps://github\.com/kof/node\-jqtpl\fR for node942+.943 .IP "" 0944 .945 .SS "Session Support"946 Sessions support can be added by using Connect\'s \fIsession\fR middleware\. To do so we also need the \fIcookieDecoder\fR middleware place above it, which will parse and populate cookie data to \fIreq\.cookies\fR\.487 unmodified lines1434 .SS "res\.partial(view[, options])"1435 Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.1436 .1437 .IP "\(bu" 41370-\fIas\fR Variable name for each \fIcollection\fR value, defaults to the view name\.1438+\fIobject\fR the object named by \fIas\fR or derived from the view name1439 .1440 .IP "\(bu" 41441+\fIas\fR Variable name for each \fIcollection\fR or \fIobject\fR value, defaults to the view name\.1442+.1443+.IP "\(bu" 41444 as: \'something\' will add the \fIsomething\fR local variable1445 .1446 .IP "\(bu" 41447 as: this will use the collection value as the template context61 unmodified lines1509 .IP "" 41510 .1511 .nf1512 1442-partials(\'movie\', { collection: movies, as: global });1513+partial(\'movie\', { collection: movies, as: global });1514 // In view: director1515 .1516 .fi1517 .1518 .IP "" 01519 .1520+.P1521+This same logic applies to a single partial object usage:1522+.1523+.IP "" 41524+.1525+.nf1526+1527+partial(\'movie\', { object: movie, as: this });1528+// In view: this\.director1529+1530+partial(\'movie\', { object: movie, as: global });1531+// In view: director1532+1533+partial(\'movie\', { object: movie, as: \'video\' });1534+// In view: video\.director1535+1536+partial(\'movie\', { object: movie });1537+// In view: movie\.director1538+.1539+.fi1540+.1541+.IP "" 01542+.1543+.P1544+When a non\-collection (does \fInot\fR have \fI\.length\fR) is passed as the second argument, it is assumed to be the \fIobject\fR, after which the object\'s local variable name is derived from the view name:1545+.1546+.IP "" 41547+.1548+.nf1549+1550+partial(\'movie\', movie);1551+// => In view: movie\.director1552+.1553+.fi1554+.1555+.IP "" 01556+.1557 .SS "app\.set(name[, val])"1558 Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:1559 .1560 .IP "" 47 unmodified lines1568 .fi1569 .1570 .IP "" 01571 .1572+.P1573+Alternatively you may simply access the settings via \fIapp\.settings\fR:1574+.1575+.IP "" 41576+.1577+.nf1578+1579+app\.settings\.views1580+// => \.\.\.path\.\.\.1581+.1582+.fi1583+.1584+.IP "" 01585+.1586 .SS "app\.enable(name)"1587 Enable the given setting \fIname\fR:1588 .1589 .IP "" 4282 unmodified linesmodified:docs/guide.html+80 added-2 removed
412 unmodified lines413 /products.xml414 /products415 </code></pre>416 417+<p>For example we can <strong>POST</strong> some json, and echo the json back using the <em>bodyDecoder</em> middleware which will parse json request bodies (as well as others), and place the result in <em>req.body</em>:</p>418+419+<pre><code>var express = require('express')420+ , app = express.createServer();421+422+app.use(express.bodyDecoder());423+424+app.post('/', function(req, res){425+ res.send(req.body);426+});427+428+app.listen(3000);429+</code></pre>430+431 <h3 id="Passing-Route-Control">Passing Route Control</h3>432 433 <p>We may pass control to the next <em>matching</em> route, by calling the <em>third</em> argument,434 the <em>next()</em> function. When a match cannot be made, control is passed back to Connect,12 unmodified lines447 // do something else448 });449 </code></pre>450 451+<p>Express 1.0 also introduces the <em>all()</em> method, which provides a route callback matching any HTTP method. This is useful in many ways, one example being the loading of resources before executing subsequent routes as shown below:</p>452+453+<pre><code>var express = require('express')454+ , app = express.createServer();455+456+var users = [{ name: 'tj' }];457+458+app.all('/user/:id/:op?', function(req, res, next){459+ req.user = users[req.params.id];460+ if (req.user) {461+ next();462+ } else {463+ next(new Error('cannot find user ' + req.params.id));464+ }465+});466+467+app.get('/user/:id', function(req, res){468+ res.send('viewing ' + req.user.name);469+});470+471+app.get('/user/:id/edit', function(req, res){472+ res.send('editing ' + req.user.name);473+});474+475+app.put('/user/:id', function(req, res){476+ res.send('updating ' + req.user.name);477+});478+479+app.get('*', function(req, res){480+ res.send('what???', 404);481+});482+483+app.listen(3000); 484+</code></pre>485+486 <h3 id="Middleware">Middleware</h3>487 488 <p>Middleware via <a href="http://github.com/senchalabs/connect">Connect</a> can be489 passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>331 unmodified lines821 <li><a href="http://jade-lang.com">Jade</a> haml.js successor</li>822 <li><a href="http://github.com/visionmedia/haml.js">Haml</a> pythonic indented templates</li>823 <li><a href="http://github.com/visionmedia/ejs">EJS</a> Embedded JavaScript</li>824 <li><a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a> CoffeeScript based templating</li>825+<li><a href="https://github.com/kof/node-jqtpl">jQuery Templates</a> for node</li>826 </ul>827 828 829 <h3 id="Session-Support">Session Support</h3>324 unmodified lines1154 <p>Render <em>view</em> partial with the given <em>options</em>. This method is always available1155 to the view as a local variable.</p>1156 1157 <ul>1158+<li><em>object</em> the object named by <em>as</em> or derived from the view name</li>1108-<li><p><em>as</em> Variable name for each <em>collection</em> value, defaults to the view name.</p>1159+<li><p><em>as</em> Variable name for each <em>collection</em> or <em>object</em> value, defaults to the view name.</p>1160 1161 <ul>1162 <li>as: 'something' will add the <em>something</em> local variable</li>1163 <li>as: this will use the collection value as the template context</li>31 unmodified lines1195 1196 <p>Another alternative is to "explode" the properties of the collection item into1197 pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>1198 1148-<pre><code>partials('movie', { collection: movies, as: global });1199+<pre><code>partial('movie', { collection: movies, as: global });1200 // In view: director1201 </code></pre>1202 1203+<p>This same logic applies to a single partial object usage:</p>1204+1205+<pre><code>partial('movie', { object: movie, as: this });1206+// In view: this.director1207+1208+partial('movie', { object: movie, as: global });1209+// In view: director1210+1211+partial('movie', { object: movie, as: 'video' });1212+// In view: video.director1213+1214+partial('movie', { object: movie });1215+// In view: movie.director1216+</code></pre>1217+1218+<p>When a non-collection (does <em>not</em> have <em>.length</em>) is passed as the second argument, it is assumed to be the <em>object</em>, after which the object's local variable name is derived from the view name:</p>1219+1220+<pre><code>partial('movie', movie);1221+// => In view: movie.director1222+</code></pre>1223+1224 <h3 id="app-set-name-val-">app.set(name[, val])</h3>1225 1226 <p>Apply an application level setting <em>name</em> to <em>val</em>, or1227 get the value of <em>name</em> when <em>val</em> is not present:</p>2 unmodified lines1230 app.set('views');1231 // => ...path...1232 </code></pre>1233 1234+<p>Alternatively you may simply access the settings via <em>app.settings</em>:</p>1235+1236+<pre><code>app.settings.views1237+// => ...path...1238+</code></pre>1239+1240 <h3 id="app-enable-name-">app.enable(name)</h3>1241 1242 <p>Enable the given setting <em>name</em>:</p>1243 176 unmodified linesmodified:docs/index.1-37 removed
101 unmodified lines102 .IP "\(bu" 4103 View the source \fIhttp://github\.com/visionmedia/express\fR104 .105 .IP "" 0106-.107-.SH "Apps Using Express"108-.109-.IP "\(bu" 4110-LearnBoost \fIhttp://learnboost\.com\fR \- Online gradebook software111-.112-.IP "\(bu" 4113-Markup\.IO \fIhttp://markup\.io/\fR \- Draw on any website to share ideas114-.115-.IP "\(bu" 4116-wtfjs \fIhttp://wtfjs\.com/\fR \- JavaScript WTFs :)117-.118-.IP "\(bu" 4119-Node Knockout \fIhttp://nodeknockout\.com/\fR \- node knockout competition site120-.121-.IP "\(bu" 4122-Node News \fIhttp://nodejs\.se/\fR \- node news aggregator123-.124-.IP "\(bu" 4125-Code Shelver \fIhttp://codeshelver\.com/\fR \- GitHub watch list app126-.127-.IP "\(bu" 4128-Clickdummy \fIhttp://clickdummy\.net/\fR \- Fast prototyping for designers129-.130-.IP "\(bu" 4131-E\-Resistible \fIhttp://e\-resistible\.co\.uk\fR \- Online takeaway ordering app132-.133-.IP "\(bu" 4134-Storify \fIhttp://storify\.com\fR \- The future of publishing135-.136-.IP "\(bu" 4137-Ogre \fIhttp://ogre\.adc4gis\.com/\fR \- Translates spatial files into GeoJSON138-.139-.IP "\(bu" 4140-Widescript \fIhttp://widescript\.com/\fR \- A digital reading app targeted to people who study or make use of reference material141-.142-.IP "" 0106 modified:docs/index.html-17 removed
245 unmodified lines246 <li>View the <a href="http://github.com/visionmedia/express">source</a></li>247 </ul>248 249 250-<h2 id="Apps-Using-Express">Apps Using Express</h2>251-252-<ul>253-<li><a href="http://learnboost.com">LearnBoost</a> - Online gradebook software</li>254-<li><a href="http://markup.io/">Markup.IO</a> - Draw on any website to share ideas</li>255-<li><a href="http://wtfjs.com/">wtfjs</a> - JavaScript WTFs :)</li>256-<li><a href="http://nodeknockout.com/">Node Knockout</a> - node knockout competition site</li>257-<li><a href="http://nodejs.se/">Node News</a> - node news aggregator</li>258-<li><a href="http://codeshelver.com/">Code Shelver</a> - GitHub watch list app</li>259-<li><a href="http://clickdummy.net/">Clickdummy</a> - Fast prototyping for designers</li>260-<li><a href="http://e-resistible.co.uk">E-Resistible</a> - Online takeaway ordering app</li>261-<li><a href="http://storify.com">Storify</a> - The future of publishing</li>262-<li><a href="http://ogre.adc4gis.com/">Ogre</a> - Translates spatial files into GeoJSON</li>263-<li><a href="http://widescript.com/">Widescript</a> - A digital reading app targeted to people who study or make use of reference material</li>264-</ul>265-266-250 </div>251 </div>252 </div>253 </body>1 unmodified linemodified:lib/express/index.js+11 added-1 removed
17 unmodified lines1819202122222324252616 unmodified lines4344454647484950515253545556575817 unmodified lines/** * Framework version. */
exports.version = '1.0.0rc4';exports.version = '1.0.0';
/** * Module dependencies. */16 unmodified lines * View extensions. */
require('./view');
/** * Response extensions. */
require('./response');
/** * Request extensions. */
require('./request');modified:package.json+1 added-1 removed
12344567810 unmodified lines{ "name": "express", "description": "Sinatra inspired web development framework", "version": "1.0.0rc4", "version": "1.0.0", "author": "TJ Holowaychuk <tj@vision-media.ca>", "contributors": [ { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" }, { "name": "Aaron Heckmann", "email": "aaron.heckmann+github@gmail.com" },10 unmodified linesmodified:Readme.md+3 added-1 removed
71 unmodified lines7273747576767778798081828320 unmodified lines71 unmodified lines v0.2.4
and connect --version:
0.2.6 0.3.0
Express 1.x is maintained in the _1.x_ branch.
## License
(The MIT License)
20 unmodified lines