Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

publish version 0.4.0

  • Loading branch information...
commit f478417bccf617c18c68aaa55c2236dbf001fec4 1 parent 3b380d0
@shimaore shimaore authored
Showing with 127 additions and 89 deletions.
  1. +4 −0 CHANGELOG.md
  2. +31 −18 docs/reference.md
  3. +90 −69 docs/zappa.html
  4. +2 −2 src/zappa.coffee
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+**v0.4.0** (2012-06-18)
+
+ * Added Express 3 support (#7)
+
**v0.3.9** (2012-06-05):
* Added support for https server.
View
49 docs/reference.md
@@ -1,6 +1,6 @@
---
layout: default
-title: API Reference (v0.3.9)
+title: API Reference (v0.4.0)
permalink: /reference/index.html
---
@@ -12,7 +12,7 @@ permalink: /reference/index.html
### zappa.version
-Version of zappa running. If you're running a version not released on npm (directly from the repo), it will have `-edge` appended to it. Ex.: `0.3.0-edge`.
+Version of zappa running.
### zappa.app
@@ -56,6 +56,8 @@ You can also pass the parameters in the `options` object. The following options
require('zappajs') 3443, https:{ key: ... , cert: ... }, ->
@get '/': 'hi'
+* `export_views`: (experimental) string pointing to a subdirectory of `@get 'views'` where Zappa inline views should be exported. This should allow you to reference them from templates that support including other templates.
+
It will automatically print the equivalent to the following to stdout:
Express server listening on port xxxx in [development/production] mode
@@ -84,13 +86,13 @@ The handler and middleware functions will have access to all variables described
If a handler returns a string, `res.send(string)` will be called automatically.
Ex.:
-
+
@get '/': 'hi'
@get '/', -> 'hi'
-
+
@get /regex/, -> 'hi'
-
+
@get '/': 'hi', '/wiki': 'wiki', '/chat': 'chat'
@get
@@ -151,13 +153,13 @@ Since the parameter is actually an object, you can define any number of helpers
`@view path: contents`
-Define an inline template. For all purposes it's like you had a file on disk at `path`. It will have precedence over a template on disk.
+Define an inline template. It's like you had a file on disk at `path`. It will have precedence over a template on disk.
Ex.:
@view index: ->
h1 @foo
-
+
@view 'index.eco': '''
<h1><%= @foo %></h1>
'''
@@ -169,7 +171,7 @@ By default, the templating engine is CoffeeCup. To use other engines, just use e
Or:
@set 'view engine': 'jade'
-
+
All variables at `@`/`params` (request params + those you created) are automatically made available to templates as `params.foo` (in CoffeeCup, `@params.foo`).
In addition, if you're using the *zappa view adapter* (as is the case by default, with CoffeeCup), they're also made available at the template's "root namespace" (`foo` or CoffeeCup's `@foo`).
@@ -185,6 +187,8 @@ To disable it on default zappa:
@register coffee: require('coffeekup').adapters.express
+Although inline templates defined by `@view` are visible inside Express (and can be used e.g. with `@app.render`), they are not visible to the template engines, which means they cannot be used as `include` in engines that support this. (Although see `export_views`.)
+
### @postrender
`@postrender name: function`
@@ -200,7 +204,7 @@ To use this feature, `npm install jsdom` first.
@get '/postrender': ->
@user = plan: 'staff'
@render index: {postrender: 'plans'}
-
+
It receives an alternative reference to the context as an optional last parameter:
@postrender plans: ($, foo) ->
@@ -218,7 +222,7 @@ Will `require` the file at the path specified, and run a function exported as `i
ping = 'pong'
@get '/': 'main'
@include './sub'
-
+
# sub.coffee
@include = ->
console.log @foo # 'bar'
@@ -233,18 +237,18 @@ Allows to `require` arbitrary modules (using the standard Node.js algorithm). Th
@client '/foo.js': ->
sum = (a, b) -> a + b
-
+
@helper foo: (param) ->
console.log param # 'bar' or 'pong'
sum 1, 2 # 3
console.log @zig # A request or event input param.
if @render? then console.log 'route'
else if @emit? then console.log 'event'
-
+
@get '#/': ->
@foo 'bar'
console.log 'A client-side route.'
-
+
@on welcome: ->
@foo 'pong'
console.log 'A socket.io event.'
@@ -267,10 +271,10 @@ To use it, you must also include `/zappa/zappa.js` in your page, before `/foo.js
@get '/admin': ->
@role 'admin'
# admin stuff
-
+
@on 'delete everything': ->
@role 'admin'
-
+
@client '/index.js': ->
@get '#/admin': ->
@role 'admin'
@@ -424,11 +428,18 @@ Shortcut to `@app.disable`. Accepts multiple params in one go. Ex.:
### @register
-Shortcut to `@app.register`. Accepts an object as param. Ex.:
+Similarly to Express `@app.engine`, allows to register specific template engines.
+
+This is normally not needed unless you want to change the behavior of the engine, for example to benefit from `zappa.adapter`.
+
+Accepts an object as param. Ex.:
@register eco: require 'eco'
-Note that while `@app.register '.eco'` uses a dot, `@register eco` doesn't.
+Note that most template engines do not support the new Express 3.x conventions at this time, if you want to use them with Zappa you should either register them as shown above,
+or use the [consolidate](https://github.com/visionmedia/consolidate.js) package:
+
+ @app.engine 'eco', require('consolidate').eco
## REQUEST HANDLERS SCOPE
@@ -474,7 +485,9 @@ Adds the following features:
- You can use inline views (see `@view`).
- - You can use `postrender`s: `render 'index', postrender: 'foo'`.
+ - You can use post-rendering (see `@postrender`): `render 'index', postrender: 'foo'`.
+
+ - You can use layouts: `render 'index', layout:'layout'`. The default layout is called `layout` and is active by default. To disable layout processing: `render 'index', layout: no`.
- If the setting `databag` is on, the databag will be automatically available to templates as `params`.
View
159 docs/zappa.html
@@ -1,13 +1,12 @@
<!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="s">&#39;0.3.9&#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="s">&#39;0.4.0&#39;</span>
-<span class="nv">codename = </span><span class="s">&#39;Overture to a Holiday in Berlin&#39;</span>
+<span class="nv">codename = </span><span class="s">&#39;Wowie Zowie&#39;</span>
<span class="nv">log = </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span>
<span class="nv">fs = </span><span class="nx">require</span> <span class="s">&#39;fs&#39;</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s">&#39;path&#39;</span>
-<span class="nv">uuid = </span><span class="nx">require</span> <span class="s">&#39;node-uuid&#39;</span>
<span class="nv">express = </span><span class="nx">require</span> <span class="s">&#39;express&#39;</span>
<span class="nv">socketio = </span><span class="nx">require</span> <span class="s">&#39;socket.io&#39;</span>
<span class="nv">jquery = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s">&#39;/../vendor/jquery-1.7.2.min.js&#39;</span><span class="p">).</span><span class="nx">toString</span><span class="p">()</span>
@@ -38,46 +37,32 @@
Does NOT overwrite attributes already present in <code>recipient</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">copy_data_to = </span><span class="nf">(recipient, sources) -&gt;</span>
<span class="k">for</span> <span class="nx">obj</span> <span class="k">in</span> <span class="nx">sources</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="nx">recipient</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="nx">unless</span> <span class="nx">recipient</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Keep inline views at the module level and namespaced by app id
-so that the monkeypatched express can look them up.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">views = </span><span class="p">{}</span>
- </pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Monkeypatch express to support lookup of inline templates. Such is life.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">express</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span> <span class="s">&#39;exists&#39;</span><span class="p">,</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Path given by zappa: /path/to/appid/foo.bar.</p> </td> <td class="code"> <div class="highlight"><pre> </pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Try appid/foo.bar in memory.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">@path</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">@root</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span>
- <span class="nv">id = </span><span class="nx">p</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
- <span class="k">return</span> <span class="kc">true</span> <span class="k">if</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Try appid/foo in memory.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">p</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">p</span><span class="p">),</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
- <span class="k">return</span> <span class="kc">true</span> <span class="k">if</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Try /path/to/foo.bar in filesystem (normal express behaviour).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">@path</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">id</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span>
- <span class="k">try</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="nx">p</span><span class="p">)</span>
- <span class="k">return</span> <span class="kc">true</span>
- <span class="k">catch</span> <span class="nx">err</span>
- <span class="nv">p = </span><span class="nx">@path</span>
- <span class="k">try</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="nx">p</span><span class="p">)</span>
- <span class="k">return</span> <span class="kc">true</span>
- <span class="k">catch</span> <span class="nx">err</span>
- <span class="k">return</span> <span class="kc">false</span>
-
-<span class="nx">express</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span> <span class="s">&#39;contents&#39;</span><span class="p">,</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Path given by zappa: /path/to/appid/foo.bar.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Try appid/foo.bar in memory.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">@path</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">@root</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span>
- <span class="nv">id = </span><span class="nx">p</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
- <span class="k">return</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="k">if</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Try appid/foo in memory.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">p</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">p</span><span class="p">),</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
- <span class="k">return</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="k">if</span> <span class="nx">views</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Try /path/to/foo.bar in filesystem (normal express behaviour).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">p = </span><span class="nx">@path</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">id</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span>
- <span class="k">try</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">p</span><span class="p">,</span> <span class="s">&#39;utf8&#39;</span>
- <span class="k">catch</span> <span class="nx">err</span>
- <span class="nv">p = </span><span class="nx">@path</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">p</span><span class="p">,</span> <span class="s">&#39;utf8&#39;</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Takes in a function and builds express/socket.io apps based on the rules contained in it.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">zappa.app = </span><span class="nf">(func,options) -&gt;</span>
- <span class="nv">context = </span><span class="p">{</span><span class="nv">id: </span><span class="nx">uuid</span><span class="p">(),</span> <span class="nx">zappa</span><span class="p">,</span> <span class="nx">express</span><span class="p">}</span>
-
- <span class="nv">context.root = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">module</span><span class="p">.</span><span class="nx">parent</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Storage for user-provided stuff.
+ <span class="nx">recipient</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="nx">unless</span> <span class="nx">recipient</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Takes in a function and builds express/socket.io apps based on the rules contained in it.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">zappa.app = </span><span class="nf">(func,options) -&gt;</span>
+ <span class="nv">context = </span><span class="p">{</span><span class="nx">zappa</span><span class="p">,</span> <span class="nx">express</span><span class="p">}</span>
+
+ <span class="nv">context.root = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">module</span><span class="p">.</span><span class="nx">parent</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Storage for user-provided stuff.
Views are kept at the module level.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">ws_handlers = </span><span class="p">{}</span>
<span class="nv">helpers = </span><span class="p">{}</span>
<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="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">https</span><span class="o">?</span>
- <span class="nv">app = context.app = </span><span class="nx">express</span><span class="p">.</span><span class="nx">createServer</span> <span class="nx">options</span><span class="p">.</span><span class="nx">https</span>
+ <span class="nv">app.server = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;https&#39;</span><span class="p">).</span><span class="nx">createServer</span> <span class="nx">options</span><span class="p">.</span><span class="nx">https</span><span class="p">,</span> <span class="nx">app</span>
<span class="k">else</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 = </span><span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">disable_io</span> <span class="k">then</span> <span class="kc">null</span> <span class="k">else</span> <span class="nv">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="s">&#39;view engine&#39;</span><span class="p">,</span> <span class="s">&#39;coffee&#39;</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">register</span> <span class="s">&#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="s">&#39;coffeecup&#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="s">&#39;format&#39;</span><span class="p">,</span> <span class="s">&#39;autoescape&#39;</span><span class="p">,</span> <span class="s">&#39;locals&#39;</span><span class="p">,</span> <span class="s">&#39;hardcode&#39;</span><span class="p">,</span> <span class="s">&#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="s">&#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="s">&#39;/views&#39;</span><span class="p">)</span>
+ <span class="nv">app.server = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;http&#39;</span><span class="p">).</span><span class="nx">createServer</span> <span class="nx">app</span>
+ <span class="nv">io = </span><span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">disable_io</span> <span class="k">then</span> <span class="kc">null</span> <span class="k">else</span> <span class="nv">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><span class="nx">server</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#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-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#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-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Force view-cache (so that we can populate it).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unless</span> <span class="nx">options</span><span class="p">.</span><span class="nx">export_views</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">enable</span> <span class="s">&#39;view cache&#39;</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Provide register (as in Express 2)</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">compilers = </span><span class="p">{}</span>
+ <span class="nv">register = </span><span class="nf">(ext,obj) -&gt;</span>
+ <span class="k">if</span> <span class="nx">ext</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s">&#39;.&#39;</span>
+ <span class="nv">ext = </span><span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="nx">ext</span>
+ <span class="nv">compile = </span><span class="nx">obj</span><span class="p">.</span><span class="nx">compile</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">compile</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;register </span><span class="si">#{</span><span class="nx">ext</span><span class="si">}</span><span class="s"> must provide a .compile&quot;</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Register the compiler so that context.view may use it.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compilers</span><span class="p">[</span><span class="nx">ext</span><span class="p">]</span> <span class="o">=</span> <span class="nx">compile</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Register it with Express natively.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">renderFile = </span><span class="nf">(path,options,next) -&gt;</span>
+ <span class="nx">renderFile</span><span class="p">[</span><span class="nx">path</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">compile</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">path</span><span class="p">,</span><span class="nx">options</span><span class="p">.</span><span class="nx">encoding</span> <span class="o">?</span> <span class="s">&#39;utf8&#39;</span><span class="p">),</span> <span class="nx">options</span>
+ <span class="nx">next</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">renderFile</span><span class="p">[</span><span class="nx">path</span><span class="p">]</span> <span class="nx">options</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">engine</span> <span class="nx">ext</span><span class="p">,</span> <span class="nx">renderFile</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#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="s">&#39;view engine&#39;</span><span class="p">,</span> <span class="s">&#39;coffee&#39;</span>
+ <span class="nx">register</span> <span class="s">&#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="s">&#39;coffeecup&#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="s">&#39;format&#39;</span><span class="p">,</span> <span class="s">&#39;autoescape&#39;</span><span class="p">,</span> <span class="s">&#39;locals&#39;</span><span class="p">,</span> <span class="s">&#39;hardcode&#39;</span><span class="p">,</span> <span class="s">&#39;cache&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#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="s">&#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="s">&#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="s">&#39;get&#39;</span><span class="p">,</span> <span class="s">&#39;post&#39;</span><span class="p">,</span> <span class="s">&#39;put&#39;</span><span class="p">,</span> <span class="s">&#39;del&#39;</span><span class="p">]</span>
<span class="nx">do</span> <span class="nf">(verb) -&gt;</span>
@@ -141,16 +126,37 @@
<span class="nv">context.view = </span><span class="nf">(obj) -&gt;</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="nx">views</span><span class="p">[</span><span class="s">&quot;</span><span class="si">#{</span><span class="nx">context</span><span class="p">.</span><span class="nx">id</span><span class="si">}</span><span class="s">/</span><span class="si">#{</span><span class="nx">k</span><span class="si">}</span><span class="s">&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span>
+ <span class="nv">ext = </span><span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">k</span><span class="p">)</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">ext</span>
+ <span class="nv">ext = </span><span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="nx">app</span><span class="p">.</span><span class="nx">get</span> <span class="s">&#39;view engine&#39;</span>
+ <span class="nv">kl = </span><span class="nx">k</span> <span class="o">+</span> <span class="nx">ext</span>
+
+ <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">export_views</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Support both foo.bar and foo</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">loc = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span> <span class="nx">app</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">),</span> <span class="nx">options</span><span class="p">.</span><span class="nx">export_views</span><span class="p">,</span> <span class="nx">k</span> <span class="p">)</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">writeFileSync</span> <span class="nx">loc</span><span class="p">,</span> <span class="nx">v</span>
+ <span class="k">if</span> <span class="nx">kl</span>
+ <span class="nv">loc = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span> <span class="nx">app</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">),</span> <span class="nx">options</span><span class="p">.</span><span class="nx">export_views</span><span class="p">,</span> <span class="nx">kl</span> <span class="p">)</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">writeFileSync</span> <span class="nx">loc</span><span class="p">,</span> <span class="nx">v</span>
+ <span class="k">else</span>
+ <span class="nv">compile = </span><span class="nx">compilers</span><span class="p">[</span><span class="nx">ext</span><span class="p">]</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">compile</span><span class="o">?</span>
+ <span class="nv">compile = </span><span class="nx">compilers</span><span class="p">[</span><span class="nx">ext</span><span class="p">]</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="nx">ext</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">1</span><span class="p">).</span><span class="nx">compile</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">compile</span><span class="o">?</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Cannot find a compiler for </span><span class="si">#{</span><span class="nx">ext</span><span class="si">}</span><span class="s">&quot;</span>
+ <span class="nv">r =</span>
+ <span class="nv">render: </span><span class="nf">(options,next) -&gt;</span>
+ <span class="nx">r</span><span class="p">.</span><span class="nx">cache</span> <span class="o">?=</span> <span class="nx">compile</span> <span class="nx">v</span><span class="p">,</span> <span class="nx">options</span>
+ <span class="nx">next</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">r</span><span class="p">.</span><span class="nx">cache</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Support both foo.bar and foo</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">app</span><span class="p">.</span><span class="nx">cache</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">r</span>
+ <span class="k">if</span> <span class="nx">kl</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">cache</span><span class="p">[</span><span class="nx">kl</span><span class="p">]</span> <span class="o">=</span> <span class="nx">r</span>
<span class="nv">context.register = </span><span class="nf">(obj) -&gt;</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="nx">app</span><span class="p">.</span><span class="nx">register</span> <span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span>
+ <span class="nx">register</span> <span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span>
<span class="nv">context.set = </span><span class="nf">(obj) -&gt;</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="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span>
-
+
<span class="nv">context.enable = </span><span class="o">-&gt;</span>
<span class="nx">app</span><span class="p">.</span><span class="nx">enable</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>
@@ -195,7 +201,7 @@
<span class="nv">context.configure = </span><span class="nf">(p) -&gt;</span>
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">p</span> <span class="o">is</span> <span class="s">&#39;function&#39;</span> <span class="k">then</span> <span class="nx">app</span><span class="p">.</span><span class="nx">configure</span> <span class="nx">p</span>
<span class="k">else</span> <span class="nx">app</span><span class="p">.</span><span class="nx">configure</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</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">p</span>
-
+
<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>
@@ -219,8 +225,8 @@
<span class="nx">helper</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">ctx</span><span class="p">,</span> <span class="nx">args</span>
<span class="k">else</span>
<span class="nx">ctx</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">helper</span>
- <span class="nx">ctx</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Register a route with express.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">route = </span><span class="nf">(r) -&gt;</span>
- <span class="nx">r</span><span class="p">.</span><span class="nx">middleware</span> <span class="o">?=</span> <span class="p">[]</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Rewrite middleware</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">r.middleware = </span><span class="nx">r</span><span class="p">.</span><span class="nx">middleware</span><span class="p">.</span><span class="nx">map</span> <span class="nf">(f) -&gt;</span>
+ <span class="nx">ctx</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>Register a route with express.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">route = </span><span class="nf">(r) -&gt;</span>
+ <span class="nx">r</span><span class="p">.</span><span class="nx">middleware</span> <span class="o">?=</span> <span class="p">[]</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>Rewrite middleware</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">r.middleware = </span><span class="nx">r</span><span class="p">.</span><span class="nx">middleware</span><span class="p">.</span><span class="nx">map</span> <span class="nf">(f) -&gt;</span>
<span class="nf">(req,res,next) -&gt;</span>
<span class="nv">ctx =</span>
<span class="nv">app: </span><span class="nx">app</span>
@@ -270,41 +276,54 @@
<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">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="nx">render</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">@</span><span class="p">,</span> <span class="p">[</span><span class="nx">k</span><span class="p">,</span> <span class="nx">v</span><span class="p">]</span>
- <span class="nv">render = </span><span class="nf">(args...) -&gt;</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Adds the app id to the view name so that the monkeypatched
-express.View.exists and express.View.contents can lookup
-this app's inline templates.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">context</span><span class="p">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span> <span class="o">+</span> <span class="nx">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
- </pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Make sure the second arg is an object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">?=</span> <span class="p">{}</span>
- <span class="nx">args</span><span class="p">.</span><span class="nx">splice</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">{}</span> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s">&#39;function&#39;</span>
-
+ <span class="nv">render = </span><span class="nf">(name,opts,next) -&gt;</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>Make sure the second arg is an object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">opts</span> <span class="o">is</span> <span class="s">&#39;function&#39;</span>
+ <span class="nv">next = </span><span class="nx">opts</span>
+ <span class="nv">opts = </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="s">&#39;databag&#39;</span><span class="p">]</span>
- <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nv">params = </span><span class="nx">data</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Don't change layout: false</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unless</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">layout</span> <span class="o">is</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Use the default layout if one isn't given, or layout: true</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">layout</span> <span class="o">is</span> <span class="kc">true</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">layout</span><span class="o">?</span>
- <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nv">layout = </span><span class="s">&#39;layout&#39;</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Don't add id if it's there already</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">layout</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="o">not</span> <span class="nx">context</span><span class="p">.</span><span class="nx">id</span>
- <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nv">layout = </span><span class="nx">context</span><span class="p">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s">&#39;/&#39;</span> <span class="o">+</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">layout</span>
+ <span class="nv">opts.params = </span><span class="nx">data</span>
- <span class="k">if</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">postrender</span><span class="o">?</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>Apply postrender before sending response.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">res</span><span class="p">.</span><span class="nx">render</span> <span class="nx">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nf">(err, str) -&gt;</span>
- <span class="nx">jsdom</span><span class="p">.</span><span class="nx">env</span> <span class="nv">html: </span><span class="nx">str</span><span class="p">,</span> <span class="nv">src: </span><span class="p">[</span><span class="nx">jquery</span><span class="p">],</span> <span class="nv">done: </span><span class="nf">(err, window) -&gt;</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">postrender</span><span class="o">?</span>
+ <span class="nv">postrender = </span><span class="nx">next</span>
+ <span class="k">else</span>
+ <span class="nv">postrender = </span><span class="nf">(err, str) -&gt;</span>
+ <span class="k">if</span> <span class="nx">err</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">next</span> <span class="nx">err</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>Apply postrender before sending response.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">jsdom</span><span class="p">.</span><span class="nx">env</span> <span class="nv">html: </span><span class="nx">str</span><span class="p">,</span> <span class="nv">src: </span><span class="p">[</span><span class="nx">jquery</span><span class="p">],</span> <span class="nv">done: </span><span class="nf">(err, window) -&gt;</span>
+ <span class="k">if</span> <span class="nx">err</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">next</span> <span class="nx">err</span>
<span class="nv">ctx.window = </span><span class="nb">window</span>
- <span class="nv">rendered = </span><span class="nx">postrenders</span><span class="p">[</span><span class="nx">args</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">postrender</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="nb">window</span><span class="p">.</span><span class="nx">$</span><span class="p">,</span> <span class="nx">ctx</span><span class="p">])</span>
+ <span class="nv">rendered = </span><span class="nx">postrenders</span><span class="p">[</span><span class="nx">opts</span><span class="p">.</span><span class="nx">postrender</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="nb">window</span><span class="p">.</span><span class="nx">$</span><span class="p">,</span> <span class="nx">ctx</span><span class="p">])</span>
<span class="nv">doctype = </span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nb">document</span><span class="p">.</span><span class="nx">doctype</span> <span class="o">or</span> <span class="s">&#39;&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;\n&quot;</span>
- <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">doctype</span> <span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nb">document</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">.</span><span class="nx">outerHTML</span>
- <span class="k">else</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>Just forward params to express.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">res</span><span class="p">.</span><span class="nx">render</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">args</span>
+ <span class="nv">html = </span><span class="nx">doctype</span> <span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nb">document</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">.</span><span class="nx">outerHTML</span>
+ <span class="k">if</span> <span class="nx">next</span><span class="o">?</span>
+ <span class="nx">next</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">html</span>
+ <span class="k">else</span>
+ <span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">.</span><span class="nx">call</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">html</span>
+
+ <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">layout</span> <span class="o">is</span> <span class="kc">false</span>
+ <span class="nv">layout = </span><span class="nx">postrender</span>
+ <span class="k">else</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Use the default layout if one isn't given, or layout: true</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">layout</span> <span class="o">is</span> <span class="kc">true</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">layout</span><span class="o">?</span>
+ <span class="nv">opts.layout = </span><span class="s">&#39;layout&#39;</span>
+ <span class="nv">layout = </span><span class="nf">(err,str) -&gt;</span>
+ <span class="k">if</span> <span class="nx">err</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">next</span> <span class="nx">err</span>
+ <span class="nv">opts.body = </span><span class="nx">str</span>
+ <span class="nx">res</span><span class="p">.</span><span class="nx">render</span><span class="p">.</span><span class="nx">call</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">layout</span><span class="p">,</span> <span class="nx">opts</span><span class="p">,</span> <span class="nx">postrender</span>
+
+ <span class="nx">res</span><span class="p">.</span><span class="nx">render</span><span class="p">.</span><span class="nx">call</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">opts</span><span class="p">,</span> <span class="nx">layout</span>
<span class="nx">apply_helpers</span> <span class="nx">ctx</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="s">&#39;databag&#39;</span><span class="p">]</span>
<span class="nv">data = </span><span class="p">{}</span>
- <span class="nx">copy_data_to</span> <span class="nx">data</span><span class="p">,</span> <span class="p">[</span><span class="nx">req</span><span class="p">.</span><span class="nx">query</span><span class="p">,</span> <span class="nx">req</span><span class="p">.</span><span class="nx">params</span><span class="p">,</span> <span class="nx">req</span><span class="p">.</span><span class="nx">body</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Go!</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">switch</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s">&#39;databag&#39;</span><span class="p">]</span>
+ <span class="nx">copy_data_to</span> <span class="nx">data</span><span class="p">,</span> <span class="p">[</span><span class="nx">req</span><span class="p">.</span><span class="nx">query</span><span class="p">,</span> <span class="nx">req</span><span class="p">.</span><span class="nx">params</span><span class="p">,</span> <span class="nx">req</span><span class="p">.</span><span class="nx">body</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Go!</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">switch</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s">&#39;databag&#39;</span><span class="p">]</span>
<span class="k">when</span> <span class="s">&#39;this&#39;</span> <span class="k">then</span> <span class="nv">result = </span><span class="nx">r</span><span class="p">.</span><span class="nx">handler</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="s">&#39;param&#39;</span> <span class="k">then</span> <span class="nv">result = </span><span class="nx">r</span><span class="p">.</span><span class="nx">handler</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="nv">result = </span><span class="nx">r</span><span class="p">.</span><span class="nx">handler</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>
-
+
<span class="nx">res</span><span class="p">.</span><span class="nx">contentType</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">contentType</span><span class="p">)</span> <span class="k">if</span> <span class="nx">r</span><span class="p">.</span><span class="nx">contentType</span><span class="o">?</span>
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">result</span> <span class="o">is</span> <span class="s">&#39;string&#39;</span> <span class="k">then</span> <span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="nx">result</span>
- <span class="k">else</span> <span class="k">return</span> <span class="nx">result</span>
- </pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Register socket.io handlers.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">io</span><span class="o">?</span><span class="p">.</span><span class="nx">sockets</span><span class="p">.</span><span class="kc">on</span> <span class="s">&#39;connection&#39;</span><span class="p">,</span> <span class="nf">(socket) -&gt;</span>
+ <span class="k">else</span> <span class="k">return</span> <span class="nx">result</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Register socket.io handlers.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">io</span><span class="o">?</span><span class="p">.</span><span class="nx">sockets</span><span class="p">.</span><span class="kc">on</span> <span class="s">&#39;connection&#39;</span><span class="p">,</span> <span class="nf">(socket) -&gt;</span>
<span class="nv">c = </span><span class="p">{}</span>
-
+
<span class="nv">build_ctx = </span><span class="o">-&gt;</span>
<span class="nv">ctx =</span>
<span class="nv">app: </span><span class="nx">app</span>
@@ -364,7 +383,7 @@
<span class="k">switch</span> <span class="nx">app</span><span class="p">.</span><span class="nx">settings</span><span class="p">[</span><span class="s">&#39;databag&#39;</span><span class="p">]</span>
<span class="k">when</span> <span class="s">&#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="s">&#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-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#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-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#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="s">&#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">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-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#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-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#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="s">&#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="nv">client = </span><span class="s">&quot;;</span><span class="si">#{</span><span class="nx">coffeescript_helpers</span><span class="si">}</span><span class="s">(</span><span class="si">#{</span><span class="nx">client</span><span class="si">}</span><span class="s">)();&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="s">&#39;minify&#39;</span><span class="p">]</span>
@@ -385,7 +404,7 @@
<span class="nx">style</span> <span class="nx">@style</span> <span class="k">if</span> <span class="nx">@style</span>
<span class="nx">body</span> <span class="nx">@body</span>
- <span class="nx">context</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>zappa.run [host,] [port,] [{options},] root_function
+ <span class="nx">context</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>zappa.run [host,] [port,] [{options},] root_function
Takes a function and runs it as a zappa app. Optionally accepts a port number, and/or
a hostname (any order). The hostname must be a string, and the port number must be
castable as a number.
@@ -416,16 +435,18 @@
<span class="nv">zapp = </span><span class="nx">zappa</span><span class="p">.</span><span class="nx">app</span><span class="p">(</span><span class="nx">root_function</span><span class="p">,</span><span class="nx">options</span><span class="p">)</span>
<span class="nv">app = </span><span class="nx">zapp</span><span class="p">.</span><span class="nx">app</span>
- <span class="k">if</span> <span class="nx">host</span> <span class="k">then</span> <span class="nx">app</span><span class="p">.</span><span class="nx">listen</span> <span class="nx">port</span><span class="p">,</span> <span class="nx">host</span>
- <span class="k">else</span> <span class="nx">app</span><span class="p">.</span><span class="nx">listen</span> <span class="nx">port</span>
+ <span class="k">if</span> <span class="nx">host</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">server</span><span class="p">.</span><span class="nx">listen</span> <span class="nx">port</span><span class="p">,</span> <span class="nx">host</span>
+ <span class="k">else</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">server</span><span class="p">.</span><span class="nx">listen</span> <span class="nx">port</span>
<span class="nx">log</span> <span class="s">&#39;Express server listening on port %d in %s mode&#39;</span><span class="p">,</span>
- <span class="nx">app</span><span class="p">.</span><span class="nx">address</span><span class="p">()</span><span class="o">?</span><span class="p">.</span><span class="nx">port</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="nx">env</span>
+ <span class="nx">app</span><span class="p">.</span><span class="nx">server</span><span class="p">.</span><span class="nx">address</span><span class="p">()</span><span class="o">?</span><span class="p">.</span><span class="nx">port</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="nx">env</span>
<span class="nx">log</span> <span class="s">&quot;Zappa </span><span class="si">#{</span><span class="nx">zappa</span><span class="p">.</span><span class="nx">version</span><span class="si">}</span><span class="s"> \&quot;</span><span class="si">#{</span><span class="nx">codename</span><span class="si">}</span><span class="s">\&quot; orchestrating the show&quot;</span>
- <span class="nx">zapp</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Creates a zappa view adapter for templating engine <code>engine</code>. This adapter
-can be used with <code>app.register</code> and creates params "shortcuts".</p>
+ <span class="nx">zapp</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Creates a zappa view adapter for templating engine <code>engine</code>. This adapter
+can be used with <code>context.register</code> and creates params "shortcuts".</p>
<p>Zappa, by default, automatically sends all request params to templates,
but inside the <code>params</code> local.</p>
View
4 src/zappa.coffee
@@ -2,9 +2,9 @@
# [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.9'
+zappa = version: '0.4.0'
-codename = 'Overture to a Holiday in Berlin'
+codename = 'Wowie Zowie'
log = console.log
fs = require 'fs'
Please sign in to comment.
Something went wrong with that request. Please try again.