Permalink
Browse files

Added the express adapter.

  • Loading branch information...
1 parent 9314d8f commit b75a24c3015a6c7f1e53bc048fce26a8071f2df6 @mauricemach committed Jul 19, 2011
View
@@ -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.
View
@@ -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,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'
@@ -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]
@@ -0,0 +1 @@
+p 'Express partial'
View
@@ -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.