Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into 1.x

  • Loading branch information...
commit 6ddacb6302240e5275f5b083372c5e914549d367 2 parents e1d3399 + 0e0cc30
@tj tj authored
View
38 History.md
@@ -1,4 +1,42 @@
+1.0.0 / 2010-11-16
+==================
+
+ * Added; deduce partial object names from the last segment.
+ For example by default `partial('forum/post', postObject)` will
+ give you the _post_ object, providing a meaningful default.
+
+ * Added http status code string representation to `res.redirect()` body
+ * Added; `res.redirect()` supporting _text/plain_ and _text/html_ via __Accept__.
+
+ * Added `req.is()` to aid in content negotiation
+
+ * Added partial local inheritance [suggested by masylum]. Closes #102
+ providing access to parent template locals.
+
+ * Added _-s, --session[s]_ flag to express(1) to add session related middleware
+ * Added _--template_ flag to express(1) to specify the
+ template engine to use.
+
+ * Added _--css_ flag to express(1) to specify the
+ stylesheet engine to use (or just plain css by default).
+
+ * Added `app.all()` support [thanks aheckmann]
+
+ * Added partial direct object support.
+ You may now `partial('user', user)` providing the "user" local,
+ vs previously `partial('user', { object: user })`.
+
+ * Added _route-separation_ example since many people question ways
+ to do this with CommonJS modules. Also view the _blog_ example for
+ an alternative.
+
+ * Performance; caching view path derived partial object names
+
+ * Fixed partial local inheritance precedence. [reported by Nick Poulden] Closes #454
+
+ * Fixed jsonp support; _text/javascript_ as per mailinglist discussion
+
1.0.0rc4 / 2010-10-14
==================
View
4 Makefile
@@ -1,5 +1,5 @@
-PREFIX = /usr/local
+PREFIX ?= /usr/local
LIB_PREFIX = ~/.node_libraries
DOCS = docs/index.md \
@@ -24,11 +24,9 @@ uninstall: uninstall-docs
install-support:
cd support/connect && $(MAKE) install
- cd support/jade && $(MAKE) install
uninstall-support:
cd support/connect && $(MAKE) uninstall
- cd support/jade && $(MAKE) uninstall
install-docs:
@mkdir -p $(PREFIX)/share/man/man1
View
10 Readme.md
@@ -22,12 +22,6 @@ curl:
$ curl -# http://expressjs.com/install.sh | sh
-git clone, first update the submodules:
-
- $ git submodule update --init
- $ make install
- $ make install-support
-
## Features
* Robust routing
@@ -79,7 +73,9 @@ The latest release of Express is compatible with node --version:
and connect --version:
- 0.2.6
+ 0.3.0
+
+Express 1.x is maintained in the _1.x_ branch.
## License
View
2  bin/express
@@ -12,7 +12,7 @@ var fs = require('fs')
* Framework version.
*/
-var version = '1.0.0rc4';
+var version = '1.0.0';
/**
* stdin stream.
View
BIN  docs/api.html
Binary file not shown
View
128 docs/guide.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "GUIDE" "" "October 2010" "" ""
+.TH "GUIDE" "" "November 2010" "" ""
.
.SH "NAME"
\fBguide\fR
@@ -262,6 +262,28 @@ Below are some route examples, and the associated paths that they may consume:
.
.IP "" 0
.
+.P
+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:
+.
+.IP "" 4
+.
+.nf
+
+var express = require(\'express\')
+ , app = express\.createServer();
+
+app\.use(express\.bodyDecoder());
+
+app\.post(\'/\', function(req, res){
+ res\.send(req\.body);
+});
+
+app\.listen(3000);
+.
+.fi
+.
+.IP "" 0
+.
.SS "Passing Route Control"
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\.
.
@@ -286,6 +308,49 @@ app\.get(\'/users\', function(req, res){
.
.IP "" 0
.
+.P
+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:
+.
+.IP "" 4
+.
+.nf
+
+var express = require(\'express\')
+ , app = express\.createServer();
+
+var users = [{ name: \'tj\' }];
+
+app\.all(\'/user/:id/:op?\', function(req, res, next){
+ req\.user = users[req\.params\.id];
+ if (req\.user) {
+ next();
+ } else {
+ next(new Error(\'cannot find user \' + req\.params\.id));
+ }
+});
+
+app\.get(\'/user/:id\', function(req, res){
+ res\.send(\'viewing \' + req\.user\.name);
+});
+
+app\.get(\'/user/:id/edit\', function(req, res){
+ res\.send(\'editing \' + req\.user\.name);
+});
+
+app\.put(\'/user/:id\', function(req, res){
+ res\.send(\'updating \' + req\.user\.name);
+});
+
+app\.get(\'*\', function(req, res){
+ res\.send(\'what???\', 404);
+});
+
+app\.listen(3000);
+.
+.fi
+.
+.IP "" 0
+.
.SS "Middleware"
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:
.
@@ -872,6 +937,9 @@ EJS \fIhttp://github\.com/visionmedia/ejs\fR Embedded JavaScript
.IP "\(bu" 4
CoffeeKup \fIhttp://github\.com/mauricemach/coffeekup\fR CoffeeScript based templating
.
+.IP "\(bu" 4
+jQuery Templates \fIhttps://github\.com/kof/node\-jqtpl\fR for node
+.
.IP "" 0
.
.SS "Session Support"
@@ -1367,7 +1435,10 @@ Most engines accept one or more of the following options, both haml \fIhttp://gi
Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.
.
.IP "\(bu" 4
-\fIas\fR Variable name for each \fIcollection\fR value, defaults to the view name\.
+\fIobject\fR the object named by \fIas\fR or derived from the view name
+.
+.IP "\(bu" 4
+\fIas\fR Variable name for each \fIcollection\fR or \fIobject\fR value, defaults to the view name\.
.
.IP "\(bu" 4
as: \'something\' will add the \fIsomething\fR local variable
@@ -1439,13 +1510,50 @@ Another alternative is to "explode" the properties of the collection item into p
.
.nf
-partials(\'movie\', { collection: movies, as: global });
+partial(\'movie\', { collection: movies, as: global });
// In view: director
.
.fi
.
.IP "" 0
.
+.P
+This same logic applies to a single partial object usage:
+.
+.IP "" 4
+.
+.nf
+
+partial(\'movie\', { object: movie, as: this });
+// In view: this\.director
+
+partial(\'movie\', { object: movie, as: global });
+// In view: director
+
+partial(\'movie\', { object: movie, as: \'video\' });
+// In view: video\.director
+
+partial(\'movie\', { object: movie });
+// In view: movie\.director
+.
+.fi
+.
+.IP "" 0
+.
+.P
+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:
+.
+.IP "" 4
+.
+.nf
+
+partial(\'movie\', movie);
+// => In view: movie\.director
+.
+.fi
+.
+.IP "" 0
+.
.SS "app\.set(name[, val])"
Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:
.
@@ -1461,6 +1569,20 @@ app\.set(\'views\');
.
.IP "" 0
.
+.P
+Alternatively you may simply access the settings via \fIapp\.settings\fR:
+.
+.IP "" 4
+.
+.nf
+
+app\.settings\.views
+// => \.\.\.path\.\.\.
+.
+.fi
+.
+.IP "" 0
+.
.SS "app\.enable(name)"
Enable the given setting \fIname\fR:
.
View
82 docs/guide.html
@@ -414,6 +414,20 @@ <h3 id="Routing">Routing</h3>
/products
</code></pre>
+<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>
+
+<pre><code>var express = require('express')
+ , app = express.createServer();
+
+app.use(express.bodyDecoder());
+
+app.post('/', function(req, res){
+ res.send(req.body);
+});
+
+app.listen(3000);
+</code></pre>
+
<h3 id="Passing-Route-Control">Passing Route Control</h3>
<p>We may pass control to the next <em>matching</em> route, by calling the <em>third</em> argument,
@@ -434,6 +448,41 @@ <h3 id="Passing-Route-Control">Passing Route Control</h3>
});
</code></pre>
+<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>
+
+<pre><code>var express = require('express')
+ , app = express.createServer();
+
+var users = [{ name: 'tj' }];
+
+app.all('/user/:id/:op?', function(req, res, next){
+ req.user = users[req.params.id];
+ if (req.user) {
+ next();
+ } else {
+ next(new Error('cannot find user ' + req.params.id));
+ }
+});
+
+app.get('/user/:id', function(req, res){
+ res.send('viewing ' + req.user.name);
+});
+
+app.get('/user/:id/edit', function(req, res){
+ res.send('editing ' + req.user.name);
+});
+
+app.put('/user/:id', function(req, res){
+ res.send('updating ' + req.user.name);
+});
+
+app.get('*', function(req, res){
+ res.send('what???', 404);
+});
+
+app.listen(3000);
+</code></pre>
+
<h3 id="Middleware">Middleware</h3>
<p>Middleware via <a href="http://github.com/senchalabs/connect">Connect</a> can be
@@ -773,6 +822,7 @@ <h3 id="Template-Engines">Template Engines</h3>
<li><a href="http://github.com/visionmedia/haml.js">Haml</a> pythonic indented templates</li>
<li><a href="http://github.com/visionmedia/ejs">EJS</a> Embedded JavaScript</li>
<li><a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a> CoffeeScript based templating</li>
+<li><a href="https://github.com/kof/node-jqtpl">jQuery Templates</a> for node</li>
</ul>
@@ -1105,7 +1155,8 @@ <h3 id="res-partial-view-options-">res.partial(view[, options])</h3>
to the view as a local variable.</p>
<ul>
-<li><p><em>as</em> Variable name for each <em>collection</em> value, defaults to the view name.</p>
+<li><em>object</em> the object named by <em>as</em> or derived from the view name</li>
+<li><p><em>as</em> Variable name for each <em>collection</em> or <em>object</em> value, defaults to the view name.</p>
<ul>
<li>as: 'something' will add the <em>something</em> local variable</li>
@@ -1145,10 +1196,31 @@ <h3 id="res-partial-view-options-">res.partial(view[, options])</h3>
<p>Another alternative is to "explode" the properties of the collection item into
pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>
-<pre><code>partials('movie', { collection: movies, as: global });
+<pre><code>partial('movie', { collection: movies, as: global });
// In view: director
</code></pre>
+<p>This same logic applies to a single partial object usage:</p>
+
+<pre><code>partial('movie', { object: movie, as: this });
+// In view: this.director
+
+partial('movie', { object: movie, as: global });
+// In view: director
+
+partial('movie', { object: movie, as: 'video' });
+// In view: video.director
+
+partial('movie', { object: movie });
+// In view: movie.director
+</code></pre>
+
+<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>
+
+<pre><code>partial('movie', movie);
+// =&gt; In view: movie.director
+</code></pre>
+
<h3 id="app-set-name-val-">app.set(name[, val])</h3>
<p>Apply an application level setting <em>name</em> to <em>val</em>, or
@@ -1159,6 +1231,12 @@ <h3 id="app-set-name-val-">app.set(name[, val])</h3>
// =&gt; ...path...
</code></pre>
+<p>Alternatively you may simply access the settings via <em>app.settings</em>:</p>
+
+<pre><code>app.settings.views
+// =&gt; ...path...
+</code></pre>
+
<h3 id="app-enable-name-">app.enable(name)</h3>
<p>Enable the given setting <em>name</em>:</p>
View
6 docs/guide.md
@@ -9,12 +9,6 @@ npm:
$ npm install express
-git clone, first update the submodules:
-
- $ git submodule update --init
- $ make install
- $ make install-support
-
### Creating An Application
The _express.Server_ now inherits from _http.Server_, however
View
37 docs/index.1
@@ -103,41 +103,4 @@ View the examples \fIhttp://github\.com/visionmedia/express/tree/master/examples
View the source \fIhttp://github\.com/visionmedia/express\fR
.
.IP "" 0
-.
-.SH "Apps Using Express"
-.
-.IP "\(bu" 4
-LearnBoost \fIhttp://learnboost\.com\fR \- Online gradebook software
-.
-.IP "\(bu" 4
-Markup\.IO \fIhttp://markup\.io/\fR \- Draw on any website to share ideas
-.
-.IP "\(bu" 4
-wtfjs \fIhttp://wtfjs\.com/\fR \- JavaScript WTFs :)
-.
-.IP "\(bu" 4
-Node Knockout \fIhttp://nodeknockout\.com/\fR \- node knockout competition site
-.
-.IP "\(bu" 4
-Node News \fIhttp://nodejs\.se/\fR \- node news aggregator
-.
-.IP "\(bu" 4
-Code Shelver \fIhttp://codeshelver\.com/\fR \- GitHub watch list app
-.
-.IP "\(bu" 4
-Clickdummy \fIhttp://clickdummy\.net/\fR \- Fast prototyping for designers
-.
-.IP "\(bu" 4
-E\-Resistible \fIhttp://e\-resistible\.co\.uk\fR \- Online takeaway ordering app
-.
-.IP "\(bu" 4
-Storify \fIhttp://storify\.com\fR \- The future of publishing
-.
-.IP "\(bu" 4
-Ogre \fIhttp://ogre\.adc4gis\.com/\fR \- Translates spatial files into GeoJSON
-.
-.IP "\(bu" 4
-Widescript \fIhttp://widescript\.com/\fR \- A digital reading app targeted to people who study or make use of reference material
-.
-.IP "" 0
View
17 docs/index.html
@@ -247,23 +247,6 @@ <h2 id="More-Information">More Information</h2>
</ul>
-<h2 id="Apps-Using-Express">Apps Using Express</h2>
-
-<ul>
-<li><a href="http://learnboost.com">LearnBoost</a> - Online gradebook software</li>
-<li><a href="http://markup.io/">Markup.IO</a> - Draw on any website to share ideas</li>
-<li><a href="http://wtfjs.com/">wtfjs</a> - JavaScript WTFs :)</li>
-<li><a href="http://nodeknockout.com/">Node Knockout</a> - node knockout competition site</li>
-<li><a href="http://nodejs.se/">Node News</a> - node news aggregator</li>
-<li><a href="http://codeshelver.com/">Code Shelver</a> - GitHub watch list app</li>
-<li><a href="http://clickdummy.net/">Clickdummy</a> - Fast prototyping for designers</li>
-<li><a href="http://e-resistible.co.uk">E-Resistible</a> - Online takeaway ordering app</li>
-<li><a href="http://storify.com">Storify</a> - The future of publishing</li>
-<li><a href="http://ogre.adc4gis.com/">Ogre</a> - Translates spatial files into GeoJSON</li>
-<li><a href="http://widescript.com/">Widescript</a> - A digital reading app targeted to people who study or make use of reference material</li>
-</ul>
-
-
</div>
</div>
</div>
View
12 lib/express/index.js
@@ -19,7 +19,7 @@ var exports = module.exports = require('connect').middleware;
* Framework version.
*/
-exports.version = '1.0.0rc4';
+exports.version = '1.0.0';
/**
* Module dependencies.
@@ -44,5 +44,15 @@ exports.createServer = function(){
*/
require('./view');
+
+/**
+ * Response extensions.
+ */
+
require('./response');
+
+/**
+ * Request extensions.
+ */
+
require('./request');
View
2  package.json
@@ -1,7 +1,7 @@
{
"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" },
Please sign in to comment.
Something went wrong with that request. Please try again.