Permalink
Browse files

Rebuilt docs

  • Loading branch information...
1 parent 5297966 commit ba88e48f6acf3642afea8595ad5e8c1b7fa7ffd5 @tj tj committed Jul 26, 2010
Showing with 133 additions and 21 deletions.
  1. +79 −16 docs/api.html
  2. +22 −1 docs/guide.1
  3. +17 −2 docs/guide.html
  4. +15 −2 docs/guide.md
View
95 docs/api.html
@@ -613,6 +613,12 @@
<span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};
<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> || []);
+ <span class="comment">// Default &quot;home&quot; to / </span>
+ <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="string">'/'</span>);
+
+ <span class="comment">// Set &quot;env&quot; to {EXPRESS,CONNECT}_ENV</span>
+ <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>);
+
<span class="comment">// Expose objects to each other</span>
<span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){
<span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};
@@ -632,7 +638,11 @@
});
<span class="comment">// Use router, expose as app.get(), etc</span>
- <span class="this">this</span>.<span class="variable">router</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });
+ <span class="keyword">var</span> <span class="variable">fn</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });
+ <span class="this">this</span>.<span class="variable">__defineGetter__</span>(<span class="string">'router'</span>, <span class="keyword">function</span>(){
+ <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;
+ <span class="keyword">return</span> <span class="variable">fn</span>;
+ });
};</code></pre>
</td>
</tr>
@@ -655,26 +665,76 @@
</td>
<td class="code">
<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span> = <span class="keyword">function</span>(<span class="variable">port</span>, <span class="variable">host</span>){
- <span class="comment">// Default &quot;home&quot; to the mounted route or '/'</span>
- <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>)) {
- <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="this">this</span>.<span class="variable">route</span> || <span class="string">'/'</span>);
- }
-
- <span class="comment">// Set &quot;env&quot; to {EXPRESS,CONNECT}_ENV</span>
- <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>);
- <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>));
-
<span class="comment">// Setup view reloading</span>
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {
<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>));
}
-
<span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">port</span>, <span class="variable">host</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
+<p>Proxy <code>connect.Server#use()</code> to apply settings to
+mounted applications.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String | Function | Server</em> route</p></li><li><p><strong>param</strong>: <em>Function | Server</em> middleware</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">use</span> = <span class="keyword">function</span>(<span class="variable">route</span>, <span class="variable">middleware</span>){
+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">route</span> !== <span class="string">'string'</span>) {
+ <span class="variable">middleware</span> = <span class="variable">route</span>, <span class="variable">route</span> = <span class="string">'/'</span>;
+ }
+
+ <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">use</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">route</span>, <span class="variable">middleware</span>);
+
+ <span class="comment">// Mounted an app</span>
+ <span class="keyword">if</span> (<span class="variable">middleware</span> <span class="variable">instanceof</span> <span class="class">Server</span>) {
+ <span class="comment">// Home is /:route/:home</span>
+ <span class="keyword">var</span> <span class="variable">app</span> = <span class="variable">middleware</span>,
+ <span class="variable">home</span> = <span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>);
+ <span class="keyword">if</span> (<span class="variable">home</span> === <span class="string">'/'</span>) <span class="variable">home</span> = <span class="string">''</span>;
+ <span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>, (<span class="variable">app</span>.<span class="variable">route</span> || <span class="string">''</span>) + <span class="variable">home</span>);
+ <span class="comment">// Mounted hook</span>
+ <span class="keyword">if</span> (<span class="variable">app</span>.<span class="variable">__mounted</span>) <span class="variable">app</span>.<span class="variable">__mounted</span>.<span class="variable">call</span>(<span class="variable">app</span>, <span class="this">this</span>);
+ }
+
+ <span class="keyword">return</span> <span class="this">this</span>;
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assign a callback <code>fn</code> which is called
+when this <code>Server</code> is passed to <code>Server#use()</code>.</p>
+
+<h2>Examples</h2>
+
+<p> var app = express.createServer(),
+ blog = express.createServer();</p>
+
+<p> blog.mounted(function(parent){
+ // parent is app
+ // "this" is blog
+ });</p>
+
+<p> app.use(blog);</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">mounted</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){
+ <span class="this">this</span>.<span class="variable">__mounted</span> = <span class="variable">fn</span>;
+ <span class="keyword">return</span> <span class="this">this</span>;
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
<p>Register the given view helpers <code>obj</code>. This method
can be called several times to apply additional helpers.</p>
@@ -786,16 +846,20 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Disable <code>setting</code>.</p>
+<p>Configure callback for the given <code>env</code>.</p>
<h2></h2>
-<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
+<ul><li><p><strong>param</strong>: <em>String</em> env</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<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>){
- <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>;
- (<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>);
+ <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">'all'</span>;
+ }
+ <span class="keyword">if</span> (<span class="variable">env</span> === <span class="string">'all'</span> || <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="variable">env</span>) {
+ <span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>);
+ }
<span class="keyword">return</span> <span class="this">this</span>;
};
@@ -805,7 +869,6 @@
<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>){
<span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {
<span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);
- <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;
}
<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>);
<span class="keyword">return</span> <span class="this">this</span>;
View
23 docs/guide.1
@@ -134,7 +134,7 @@ Express supports the following settings out of the box:
\fIenv\fR Application environment set internally, use \fIapp\.set(\'env\')\fR on \fIServer#listen()\fR
.
.IP "\(bu" 4
-\fIhome\fR Application base path used with \fIres\.redirect()\fR, when mounted defaults to \fIServer#route\fR, otherwise \"/\"\. Assigned on \fIServer#listen()\fR\.
+\fIhome\fR Application base path used with \fIres\.redirect()\fR, when mounted defaults to \fIServer#route\fR, otherwise \"/\"\.
.
.IP "\(bu" 4
\fIviews\fR Root views directory defaulting to \fBCWD/views\fR
@@ -1059,6 +1059,27 @@ All views would now have \fIsession\fR available so that session data can be acc
.
.IP "" 0
.
+.SS "app\.mounted(fn)"
+Assign a callback \fIfn\fR which is called when this \fIServer\fR is passed to \fIServer#use()\fR\.
+.
+.IP "" 4
+.
+.nf
+
+var app = express\.createServer(),
+ blog = express\.createServer();
+
+blog\.mounted(function(parent){
+ // parent is app
+ // \"this\" is blog
+});
+
+app\.use(blog);
+.
+.fi
+.
+.IP "" 0
+.
.SS "app\.listen([port[, host]])"
Bind the app server to the given \fIport\fR, which defaults to 3000\. When \fIhost\fR is omitted all connections will be accepted via \fIINADDR_ANY\fR\.
.
View
19 docs/guide.html
@@ -212,6 +212,7 @@
<li><a href="#app-error-function-">app.error()</a></li>
<li><a href="#app-helpers-obj-">app.helpers()</a></li>
<li><a href="#app-dynamicHelpers-obj-">app.dynamicHelpers()</a></li>
+<li><a href="#app-mounted-fn-">app.mounted()</a></li>
<li><a href="#app-listen-port-host-">app.listen()</a></li>
</ul>
<a href='http://github.com/visionmedia/express' id='logo'>Express</a>
@@ -312,8 +313,7 @@ <h3 id="Settings">Settings</h3>
<ul>
<li><em>env</em> Application environment set internally, use <em>app.set('env')</em> on <em>Server#listen()</em></li>
-<li><em>home</em> Application base path used with <em>res.redirect()</em>, when mounted defaults
-to <em>Server#route</em>, otherwise "/". Assigned on <em>Server#listen()</em>.</li>
+<li><em>home</em> Application base path used with <em>res.redirect()</em>, when mounted defaults to <em>Server#route</em>, otherwise "/".</li>
<li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li>
<li><em>view engine</em> Default view engine name for views rendered without extensions</li>
<li><em>reload views</em> Reloads altered views, by default watches for <em>mtime</em> changes with
@@ -921,6 +921,21 @@ <h3 id="app-dynamicHelpers-obj-">app.dynamicHelpers(obj)</h3>
<pre><code>&lt;%= session.name %&gt;
</code></pre>
+<h3 id="app-mounted-fn-">app.mounted(fn)</h3>
+
+<p>Assign a callback <em>fn</em> which is called when this <em>Server</em> is passed to <em>Server#use()</em>.</p>
+
+<pre><code>var app = express.createServer(),
+ blog = express.createServer();
+
+blog.mounted(function(parent){
+ // parent is app
+ // "this" is blog
+});
+
+app.use(blog);
+</code></pre>
+
<h3 id="app-listen-port-host-">app.listen([port[, host]])</h3>
<p>Bind the app server to the given <em>port</em>, which defaults to 3000. When <em>host</em> is omitted all
View
17 docs/guide.md
@@ -77,8 +77,7 @@ or more specifically _EXPRESS_ENV_, for example:
Express supports the following settings out of the box:
* _env_ Application environment set internally, use _app.set('env')_ on _Server#listen()_
- * _home_ Application base path used with _res.redirect()_, when mounted defaults
- to _Server#route_, otherwise "/". Assigned on _Server#listen()_.
+ * _home_ Application base path used with _res.redirect()_, when mounted defaults to _Server#route_, otherwise "/".
* _views_ Root views directory defaulting to **CWD/views**
* _view engine_ Default view engine name for views rendered without extensions
* _reload views_ Reloads altered views, by default watches for _mtime_ changes with
@@ -617,6 +616,20 @@ All views would now have _session_ available so that session data can be accesse
<%= session.name %>
+### app.mounted(fn)
+
+Assign a callback _fn_ which is called when this _Server_ is passed to _Server#use()_.
+
+ var app = express.createServer(),
+ blog = express.createServer();
+
+ blog.mounted(function(parent){
+ // parent is app
+ // "this" is blog
+ });
+
+ app.use(blog);
+
### app.listen([port[, host]])
Bind the app server to the given _port_, which defaults to 3000. When _host_ is omitted all

0 comments on commit ba88e48

Please sign in to comment.