Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed: `@enable 'serve zappa|jquery|sammy'` replaced by `@use 'zapp…

…a'`. Closes #94.
  • Loading branch information...
commit 928f1ef0c82bec8b0890a87241894ccac61c66af 1 parent c872240
@mauricemach mauricemach authored
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+**v0.3.1edge** (unreleased):
+
+ - Changed: `@enable 'serve zappa|jquery|sammy'` replaced by `@use 'zappa'`. Closes #94.
+
**v0.3.1** (2011-10-06):
- Changed dependency minors to ".x". Closes #98.
View
39 docs/0.3-gumbo/reference.md
@@ -218,7 +218,7 @@ Will `require` the file at the path specified, and run a function exported as `i
Serves `";zappa.run(#{your_function});"` as `/foo.js`, with content-type `application/javascript`.
-To use it, you must also include `/zappa/zappa.js` in your template, before `/foo.js`.
+To use it, you must also include `/zappa/zappa.js` in your page, before `/foo.js`.
### @shared
@@ -307,24 +307,29 @@ The object returned by `express.createServer`.
Shortcut to `@app.use`. It can be used in a number of additional ways:
-It accepts multiple params. Ex.:
+It accepts multiple parameters:
@use express.bodyParser(), @app.router, express.cookies()
-It accepts strings as parameters. This is syntactic sugar to the equivalent express middleware with no arguments. Ex.:
+Strings:
@use 'bodyParser', @app.router, 'cookies'
-You can also specify parameters by using objects. Ex.:
+And objects:
@use 'bodyParser', static: __dirname + '/public', session: {secret: 'fnord'}, 'cookies'
-Finally, when using strings and objects, zappa will intercept some specific middleware and add behaviour, usually default parameters. Ex.:
+When passing strings and objects, zappa's own middleware will be used if available, or express (connect) middleware otherwise.
- @use 'static'
+Currently available zappa middleware are:
- # Syntactic sugar for:
- @app.use @express.static(__dirname + '/public')
+#### 'static'
+
+Same as `@express.static(root + '/public')`, where `root` is the directory of the first file that required zappa.
+
+#### 'zappa'
+
+Serves `/zappa/zappa.js`, `/zappa/jquery.js` and `/zappa/sammy.js`. Automatically added by `@client` and `@shared` if not added before.
### @configure
@@ -344,13 +349,13 @@ Shortcut to `@app.set`. Accepts an object as param. Ex.:
Shortcut to `@app.enable`. Accepts multiple params in one go. Ex.:
- @enable 'serve jquery', 'serve sammy'
+ @enable 'foo', 'bar'
### @disable
Shortcut to `@app.disable`. Accepts multiple params in one go. Ex.:
- @disable 'serve jquery', 'serve sammy'
+ @disable 'foo', 'bar'
### @register
@@ -468,21 +473,9 @@ Same as its server-side counterpart.
You can use the following options with `@set`, `@enable` and `@disable`:
-### 'serve zappa'
-
-Serves `/zappa/zappa.js`, required to use the zappa client API. Automatically enabled by `client` and `shared`.
-
-### 'serve jquery'
-
-Serves `/zappa/jquery.js` (just standard, minified jQuery).
-
-### 'serve sammy'
-
-Serves `/zappa/sammy.js` (just standard, minified Sammy).
-
### 'minify'
-Uses uglify-js to minify the outputs of `serve zappa`, `client`, `shared`, `coffee` and `js`.
+Uses uglify-js to minify the outputs of `/zappa/zappa.js`, `@client`, `@shared`, `@coffee`, `@js`.
### 'default layout'
View
52 docs/zappa.html
@@ -1,6 +1,6 @@
<!DOCTYPE html> <html> <head> <title>zappa.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="client.html"> client.coffee </a> <a class="source" href="zappa.html"> zappa.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> zappa.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>Zappa</strong> is a <a href="http://coffeescript.org">CoffeeScript</a> DSL-ish interface for building web apps on the
<a href="http://nodejs.org">node.js</a> runtime, integrating <a href="http://expressjs.com">express</a>, <a href="http://socket.io">socket.io</a>
-and other best-of-breed libraries.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">zappa = version: </span><span class="s1">&#39;0.3.1&#39;</span>
+and other best-of-breed libraries.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">zappa = version: </span><span class="s1">&#39;0.3.1edge&#39;</span>
<span class="nv">codename = </span><span class="s1">&#39;The Gumbo Variations&#39;</span>
@@ -63,10 +63,11 @@
<span class="nv">postrenders = </span><span class="p">{}</span>
<span class="nv">app = context.app = </span><span class="nx">express</span><span class="p">.</span><span class="nx">createServer</span><span class="p">()</span>
- <span class="nv">io = context.io = </span><span class="nx">socketio</span><span class="p">.</span><span class="nx">listen</span><span class="p">(</span><span class="nx">app</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Reference to the zappa client, the value will be set later.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">client = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Zappa's default settings.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s1">&#39;view engine&#39;</span><span class="p">,</span> <span class="s1">&#39;coffee&#39;</span>
+ <span class="nv">io = context.io = </span><span class="nx">socketio</span><span class="p">.</span><span class="nx">listen</span><span class="p">(</span><span class="nx">app</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Reference to the zappa client, the value will be set later.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">client = </span><span class="kc">null</span>
+ </pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Tracks if the zappa middleware is already mounted (<code>@use 'zappa'</code>).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">zappa_used = </span><span class="kc">no</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Zappa's default settings.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s1">&#39;view engine&#39;</span><span class="p">,</span> <span class="s1">&#39;coffee&#39;</span>
<span class="nx">app</span><span class="p">.</span><span class="nx">register</span> <span class="s1">&#39;.coffee&#39;</span><span class="p">,</span> <span class="nx">zappa</span><span class="p">.</span><span class="nx">adapter</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;coffeekup&#39;</span><span class="p">).</span><span class="nx">adapters</span><span class="p">.</span><span class="nx">express</span><span class="p">,</span>
- <span class="nv">blacklist: </span><span class="p">[</span><span class="s1">&#39;format&#39;</span><span class="p">,</span> <span class="s1">&#39;autoescape&#39;</span><span class="p">,</span> <span class="s1">&#39;locals&#39;</span><span class="p">,</span> <span class="s1">&#39;hardcode&#39;</span><span class="p">,</span> <span class="s1">&#39;cache&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Builds the applications's root scope.</p> </td> <td class="code"> <div class="highlight"><pre> </pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Sets default view dir to @root (<code>path.dirname(module.parent.filename)</code>).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s1">&#39;views&#39;</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">context</span><span class="p">.</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;/views&#39;</span><span class="p">)</span>
-
+ <span class="nv">blacklist: </span><span class="p">[</span><span class="s1">&#39;format&#39;</span><span class="p">,</span> <span class="s1">&#39;autoescape&#39;</span><span class="p">,</span> <span class="s1">&#39;locals&#39;</span><span class="p">,</span> <span class="s1">&#39;hardcode&#39;</span><span class="p">,</span> <span class="s1">&#39;cache&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Sets default view dir to @root (<code>path.dirname(module.parent.filename)</code>).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s1">&#39;views&#39;</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">context</span><span class="p">.</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;/views&#39;</span><span class="p">)</span>
+
<span class="k">for</span> <span class="nx">verb</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;get&#39;</span><span class="p">,</span> <span class="s1">&#39;post&#39;</span><span class="p">,</span> <span class="s1">&#39;put&#39;</span><span class="p">,</span> <span class="s1">&#39;del&#39;</span><span class="p">]</span>
<span class="nx">do</span> <span class="nf">(verb) -&gt;</span>
<span class="nx">context</span><span class="p">[</span><span class="nx">verb</span><span class="p">]</span> <span class="o">=</span> <span class="o">-&gt;</span>
@@ -77,7 +78,7 @@
<span class="nx">route</span> <span class="nv">verb: </span><span class="nx">verb</span><span class="p">,</span> <span class="nv">path: </span><span class="nx">k</span><span class="p">,</span> <span class="nv">handler: </span><span class="nx">v</span>
<span class="nv">context.client = </span><span class="nf">(obj) -&gt;</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">enable</span> <span class="s1">&#39;serve zappa&#39;</span>
+ <span class="nx">context</span><span class="p">.</span><span class="nx">use</span> <span class="s1">&#39;zappa&#39;</span> <span class="nx">unless</span> <span class="nx">zappa_used</span>
<span class="k">for</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">obj</span>
<span class="nv">js = </span><span class="s2">&quot;;zappa.run(#{v});&quot;</span>
<span class="nv">js = </span><span class="nx">minify</span><span class="p">(</span><span class="nx">js</span><span class="p">)</span> <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;minify&#39;</span><span class="p">]</span>
@@ -138,13 +139,27 @@
<span class="nx">app</span><span class="p">.</span><span class="nx">disable</span> <span class="nx">i</span> <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">arguments</span>
<span class="nv">context.use = </span><span class="o">-&gt;</span>
- <span class="nv">wrappers =</span>
+ <span class="nv">zappa_middleware =</span>
<span class="nv">static: </span><span class="p">(</span><span class="nv">p = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">context</span><span class="p">.</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;/public&#39;</span><span class="p">))</span> <span class="o">-&gt;</span>
<span class="nx">express</span><span class="p">.</span><span class="nx">static</span><span class="p">(</span><span class="nx">p</span><span class="p">)</span>
+ <span class="nv">zappa: </span><span class="o">-&gt;</span>
+ <span class="nf">(req, res, next) -&gt;</span>
+ <span class="nv">send = </span><span class="nf">(code) -&gt;</span>
+ <span class="nx">res</span><span class="p">.</span><span class="nx">contentType</span> <span class="s1">&#39;js&#39;</span>
+ <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">code</span>
+ <span class="k">if</span> <span class="nx">req</span><span class="p">.</span><span class="nx">method</span><span class="p">.</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">isnt</span> <span class="s1">&#39;GET&#39;</span> <span class="k">then</span> <span class="nx">next</span><span class="p">()</span>
+ <span class="k">else</span>
+ <span class="k">switch</span> <span class="nx">req</span><span class="p">.</span><span class="nx">url</span>
+ <span class="k">when</span> <span class="s1">&#39;/zappa/zappa.js&#39;</span> <span class="k">then</span> <span class="nx">send</span> <span class="nx">client</span>
+ <span class="k">when</span> <span class="s1">&#39;/zappa/jquery.js&#39;</span> <span class="k">then</span> <span class="nx">send</span> <span class="nx">jquery</span>
+ <span class="k">when</span> <span class="s1">&#39;/zappa/sammy.js&#39;</span> <span class="k">then</span> <span class="nx">send</span> <span class="nx">sammy</span>
+ <span class="k">else</span> <span class="nx">next</span><span class="p">()</span>
<span class="nv">use = </span><span class="nf">(name, arg = null) -&gt;</span>
- <span class="k">if</span> <span class="nx">wrappers</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">wrappers</span><span class="p">[</span><span class="nx">name</span><span class="p">](</span><span class="nx">arg</span><span class="p">)</span>
+ <span class="nv">zappa_used = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">name</span> <span class="o">is</span> <span class="s1">&#39;zappa&#39;</span>
+
+ <span class="k">if</span> <span class="nx">zappa_middleware</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">zappa_middleware</span><span class="p">[</span><span class="nx">name</span><span class="p">](</span><span class="nx">arg</span><span class="p">)</span>
<span class="k">else</span> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">express</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;function&#39;</span>
<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">express</span><span class="p">[</span><span class="nx">name</span><span class="p">](</span><span class="nx">arg</span><span class="p">)</span>
@@ -161,7 +176,7 @@
<span class="nv">context.settings = </span><span class="nx">app</span><span class="p">.</span><span class="nx">settings</span>
<span class="nv">context.shared = </span><span class="nf">(obj) -&gt;</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">enable</span> <span class="s1">&#39;serve zappa&#39;</span>
+ <span class="nx">context</span><span class="p">.</span><span class="nx">use</span> <span class="s1">&#39;zappa&#39;</span> <span class="nx">unless</span> <span class="nx">zappa_used</span>
<span class="k">for</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">obj</span>
<span class="nv">js = </span><span class="s2">&quot;;zappa.run(#{v});&quot;</span>
<span class="nv">js = </span><span class="nx">minify</span><span class="p">(</span><span class="nx">js</span><span class="p">)</span> <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;minify&#39;</span><span class="p">]</span>
@@ -277,23 +292,8 @@
<span class="k">when</span> <span class="s1">&#39;this&#39;</span> <span class="k">then</span> <span class="nx">h</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="p">[</span><span class="nx">ctx</span><span class="p">])</span>
<span class="k">when</span> <span class="s1">&#39;param&#39;</span> <span class="k">then</span> <span class="nx">h</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">ctx</span><span class="p">,</span> <span class="p">[</span><span class="nx">data</span><span class="p">])</span>
<span class="k">else</span> <span class="nx">h</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">ctx</span><span class="p">,</span> <span class="p">[</span><span class="nx">ctx</span><span class="p">])</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Go!</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="p">[</span><span class="nx">context</span><span class="p">])</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>The stringified zappa client.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">client = </span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./client&#39;</span><span class="p">).</span><span class="nx">build</span><span class="p">(</span><span class="nx">zappa</span><span class="p">.</span><span class="nx">version</span><span class="p">,</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">)</span>
-
- <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;serve zappa&#39;</span><span class="p">]</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">get</span> <span class="s1">&#39;/zappa/zappa.js&#39;</span><span class="p">,</span> <span class="nf">(req, res) -&gt;</span>
- <span class="nv">js = </span><span class="s2">&quot;;#{coffeescript_helpers}(#{client})();&quot;</span>
- <span class="nv">js = </span><span class="nx">minify</span><span class="p">(</span><span class="nx">js</span><span class="p">)</span> <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;minify&#39;</span><span class="p">]</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">contentType</span> <span class="s1">&#39;js&#39;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">js</span>
-
- <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;serve jquery&#39;</span><span class="p">]</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">get</span> <span class="s1">&#39;/zappa/jquery.js&#39;</span><span class="p">,</span> <span class="nf">(req, res) -&gt;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">contentType</span> <span class="s1">&#39;js&#39;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">jquery</span>
-
- <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;serve sammy&#39;</span><span class="p">]</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">get</span> <span class="s1">&#39;/zappa/sammy.js&#39;</span><span class="p">,</span> <span class="nf">(req, res) -&gt;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">contentType</span> <span class="s1">&#39;js&#39;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">sammy</span>
+ <span class="nv">client = </span><span class="s2">&quot;;#{coffeescript_helpers}(#{client})();&quot;</span>
+ <span class="nv">client = </span><span class="nx">minify</span><span class="p">(</span><span class="nx">client</span><span class="p">)</span> <span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;minify&#39;</span><span class="p">]</span>
<span class="k">if</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s1">&#39;default layout&#39;</span><span class="p">]</span>
<span class="nx">context</span><span class="p">.</span><span class="nx">view</span> <span class="nv">layout: </span><span class="o">-&gt;</span>
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "zappa",
"description": "CoffeeScript minimalist interface to express, socket.io and others",
- "version": "0.3.1",
+ "version": "0.3.1edge",
"author": "Maurice Machado <maurice@bitbending.com>",
"homepage": "http://zappajs.org",
"repository": {"type": "git", "url": "git://github.com/mauricemach/zappa.git"},
View
52 src/zappa.coffee
@@ -2,7 +2,7 @@
# [node.js](http://nodejs.org) runtime, integrating [express](http://expressjs.com), [socket.io](http://socket.io)
# and other best-of-breed libraries.
-zappa = version: '0.3.1'
+zappa = version: '0.3.1edge'
codename = 'The Gumbo Variations'
@@ -109,17 +109,18 @@ zappa.app = (func) ->
# Reference to the zappa client, the value will be set later.
client = null
+
+ # Tracks if the zappa middleware is already mounted (`@use 'zappa'`).
+ zappa_used = no
# Zappa's default settings.
app.set 'view engine', 'coffee'
app.register '.coffee', zappa.adapter require('coffeekup').adapters.express,
blacklist: ['format', 'autoescape', 'locals', 'hardcode', 'cache']
- # Builds the applications's root scope.
-
# Sets default view dir to @root (`path.dirname(module.parent.filename)`).
app.set 'views', path.join(context.root, '/views')
-
+
for verb in ['get', 'post', 'put', 'del']
do (verb) ->
context[verb] = ->
@@ -130,7 +131,7 @@ zappa.app = (func) ->
route verb: verb, path: k, handler: v
context.client = (obj) ->
- app.enable 'serve zappa'
+ context.use 'zappa' unless zappa_used
for k, v of obj
js = ";zappa.run(#{v});"
js = minify(js) if app.settings['minify']
@@ -191,13 +192,27 @@ zappa.app = (func) ->
app.disable i for i in arguments
context.use = ->
- wrappers =
+ zappa_middleware =
static: (p = path.join(context.root, '/public')) ->
express.static(p)
+ zappa: ->
+ (req, res, next) ->
+ send = (code) ->
+ res.contentType 'js'
+ res.send code
+ if req.method.toUpperCase() isnt 'GET' then next()
+ else
+ switch req.url
+ when '/zappa/zappa.js' then send client
+ when '/zappa/jquery.js' then send jquery
+ when '/zappa/sammy.js' then send sammy
+ else next()
use = (name, arg = null) ->
- if wrappers[name]
- app.use wrappers[name](arg)
+ zappa_used = yes if name is 'zappa'
+
+ if zappa_middleware[name]
+ app.use zappa_middleware[name](arg)
else if typeof express[name] is 'function'
app.use express[name](arg)
@@ -214,7 +229,7 @@ zappa.app = (func) ->
context.settings = app.settings
context.shared = (obj) ->
- app.enable 'serve zappa'
+ context.use 'zappa' unless zappa_used
for k, v of obj
js = ";zappa.run(#{v});"
js = minify(js) if app.settings['minify']
@@ -352,23 +367,8 @@ zappa.app = (func) ->
# The stringified zappa client.
client = require('./client').build(zappa.version, app.settings)
-
- if app.settings['serve zappa']
- app.get '/zappa/zappa.js', (req, res) ->
- js = ";#{coffeescript_helpers}(#{client})();"
- js = minify(js) if app.settings['minify']
- res.contentType 'js'
- res.send js
-
- if app.settings['serve jquery']
- app.get '/zappa/jquery.js', (req, res) ->
- res.contentType 'js'
- res.send jquery
-
- if app.settings['serve sammy']
- app.get '/zappa/sammy.js', (req, res) ->
- res.contentType 'js'
- res.send sammy
+ client = ";#{coffeescript_helpers}(#{client})();"
+ client = minify(client) if app.settings['minify']
if app.settings['default layout']
context.view layout: ->
View
8 tests/assets.coffee
@@ -94,7 +94,7 @@ port = 15200
t.wait 3000
zapp = zappa port++, ->
- @enable 'serve jquery'
+ @use 'zappa'
c = t.client(zapp.app)
c.get '/zappa/jquery.js', (err, res) ->
@@ -106,7 +106,7 @@ port = 15200
t.wait 3000
zapp = zappa port++, ->
- @enable 'serve sammy'
+ @use 'zappa'
c = t.client(zapp.app)
c.get '/zappa/sammy.js', (err, res) ->
@@ -118,7 +118,7 @@ port = 15200
t.wait 3000
zapp = zappa port++, ->
- @enable 'serve zappa'
+ @use 'zappa'
c = t.client(zapp.app)
c.get '/zappa/zappa.js', (err, res) ->
@@ -142,7 +142,7 @@ port = 15200
t.wait 3000
zapp = zappa port++, ->
- @enable 'serve zappa', 'minify'
+ @enable 'minify'
@client '/client.js': -> alert 'foo'
@shared '/shared.js': -> alert 'foo' if window?
@coffee '/coffee.js': -> alert 'foo'
Please sign in to comment.
Something went wrong with that request. Please try again.