Skip to content

Commit

Permalink
Added the express adapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Jul 19, 2011
1 parent 9314d8f commit b75a24c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
**v0.3.0beta** (2011-07-xx):

- Added an express adapter that allows `partial 'foo'` instead of `text @partial 'foo'` (see /examples/express).

- Added id/class shortcuts (`div '#id.class.class2', 'contents'`).

- Solved express integration issues and eliminated the need for a meryl adapter.
Expand Down
15 changes: 11 additions & 4 deletions docs/coffeekup.html
Expand Up @@ -228,9 +228,16 @@
<span class="k">if</span> <span class="nx">data</span><span class="p">.</span><span class="nx">cache</span> <span class="o">and</span> <span class="nx">cache</span><span class="p">[</span><span class="nx">template</span><span class="p">]</span><span class="o">?</span> <span class="k">then</span> <span class="nv">tpl = </span><span class="nx">cache</span><span class="p">[</span><span class="nx">template</span><span class="p">]</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">data</span><span class="p">.</span><span class="nx">cache</span> <span class="k">then</span> <span class="nv">tpl = </span><span class="nx">cache</span><span class="p">[</span><span class="nx">template</span><span class="p">]</span> <span class="o">=</span> <span class="nx">coffeekup</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">template</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span>
<span class="k">else</span> <span class="nv">tpl = </span><span class="nx">coffeekup</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">template</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span>
<span class="nx">tpl</span><span class="p">(</span><span class="nx">data</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>Legacy adapters for a function signature of yore. <strong>Deprecated</strong>!</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">unless</span> <span class="nb">window</span><span class="o">?</span>
<span class="nv">coffeekup.adapters =</span>
<span class="nv">simple: </span><span class="nf">(template, data) -&gt;</span> <span class="nx">coffeekup</span><span class="p">.</span><span class="nx">render</span> <span class="nx">template</span><span class="p">,</span> <span class="nx">data</span>
<span class="nv">coffeekup.adapters.meryl = </span><span class="nx">coffeekup</span><span class="p">.</span><span class="nx">adapters</span><span class="p">.</span><span class="nx">simple</span>
<span class="nx">tpl</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span>

<span class="nx">unless</span> <span class="nb">window</span><span class="o">?</span>
<span class="nv">coffeekup.adapters =</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>Legacy adapters for when CoffeeKup expected data in the <code>context</code> attribute.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">simple: </span><span class="nx">coffeekup</span><span class="p">.</span><span class="nx">render</span>
<span class="nv">meryl: </span><span class="nx">coffeekup</span><span class="p">.</span><span class="nx">render</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>Allows <code>partial 'foo'</code> instead of <code>text @partial 'foo'</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">express:</span>
<span class="nv">compile: </span><span class="nf">(template, data) -&gt;</span>
<span class="nv">data.hardcode =</span>
<span class="nv">partial: </span><span class="o">-&gt;</span>
<span class="nx">text</span> <span class="nx">@partial</span><span class="p">.</span><span class="nx">apply</span> <span class="err">@</span><span class="p">,</span> <span class="nx">arguments</span>
<span class="nx">coffeekup</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">template</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span>

</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
2 changes: 1 addition & 1 deletion examples/express/app.coffee
Expand Up @@ -2,8 +2,8 @@ app = require('express').createServer()

coffeekup = require '../../src/coffeekup'

app.register '.coffee', coffeekup
app.set 'view engine', 'coffee'
app.register '.coffee', coffeekup.adapters.express

app.get '/', (req, res) ->
res.render 'index'
Expand Down
2 changes: 2 additions & 0 deletions examples/express/views/index.coffee
Expand Up @@ -8,3 +8,5 @@ p 'This is the home page.'
p "Let's count to 10: "

p "#{i}..." for i in [1..10]

partial 'partial', [1..10]
1 change: 1 addition & 0 deletions examples/express/views/partial.coffee
@@ -0,0 +1 @@
p 'Express partial'
14 changes: 11 additions & 3 deletions src/coffeekup.coffee
Expand Up @@ -288,8 +288,16 @@ coffeekup.render = (template, data = {}, options = {}) ->
else tpl = coffeekup.compile(template, data)
tpl(data)

# Legacy adapters for a function signature of yore. **Deprecated**!
unless window?
coffeekup.adapters =
simple: (template, data) -> coffeekup.render template, data
coffeekup.adapters.meryl = coffeekup.adapters.simple
# Legacy adapters for when CoffeeKup expected data in the `context` attribute.
simple: coffeekup.render
meryl: coffeekup.render

# Allows `partial 'foo'` instead of `text @partial 'foo'`.
express:
compile: (template, data) ->
data.hardcode =
partial: ->
text @partial.apply @, arguments
coffeekup.compile(template, data)

0 comments on commit b75a24c

Please sign in to comment.