Skip to content

Commit

Permalink
Additions to pull #74.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Sep 13, 2011
1 parent 5d0d79f commit 177bcc3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**v0.3.0edge** (unreleased):

- Fixed #71: indexOf not supported in IE7 (thanks @jaekwon).
- Added better error reporting to express adapter. [benekastah]

**v0.3.0** (2011-09-04):

Expand Down
23 changes: 18 additions & 5 deletions docs/coffeekup.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<span class="nv">coffeekup = </span><span class="nx">exports</span>
<span class="nv">coffee = </span><span class="nx">require</span> <span class="s1">&#39;coffee-script&#39;</span>

<span class="nv">coffeekup.version = </span><span class="s1">&#39;unreleased&#39;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Values available to the <code>doctype</code> function inside a template.
<span class="nv">coffeekup.version = </span><span class="s1">&#39;0.3.0edge&#39;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Values available to the <code>doctype</code> function inside a template.
Ex.: <code>doctype 'strict'</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">coffeekup.doctypes =</span>
<span class="s1">&#39;default&#39;</span><span class="o">:</span> <span class="s1">&#39;&lt;!DOCTYPE html&gt;&#39;</span>
<span class="s1">&#39;5&#39;</span><span class="o">:</span> <span class="s1">&#39;&lt;!DOCTYPE html&gt;&#39;</span>
Expand Down Expand Up @@ -253,11 +253,24 @@
<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-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#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-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#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="nx">data</span><span class="p">.</span><span class="nx">hardcode</span> <span class="o">?=</span> <span class="p">{}</span>

<span class="nv">express:</span>
<span class="nv">TemplateError: </span><span class="k">class</span> <span class="k">extends</span> <span class="nb">Error</span>
<span class="nv">constructor: </span><span class="nf">(@message) -&gt;</span>
<span class="nb">Error</span><span class="p">.</span><span class="nx">call</span> <span class="k">this</span><span class="p">,</span> <span class="nx">@message</span>
<span class="nb">Error</span><span class="p">.</span><span class="nx">captureStackTrace</span> <span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">callee</span>
<span class="nv">name: </span><span class="s1">&#39;TemplateError&#39;</span>

<span class="nv">compile: </span><span class="nf">(template, data) -&gt;</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>Allows <code>partial 'foo'</code> instead of <code>text @partial 'foo'</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">data</span><span class="p">.</span><span class="nx">hardcode</span> <span class="o">?=</span> <span class="p">{}</span>
<span class="nv">data.hardcode.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>

<span class="nv">TemplateError = </span><span class="nx">@TemplateError</span>
<span class="k">try</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="k">catch</span> <span class="nx">e</span> <span class="k">then</span> <span class="k">throw</span> <span class="k">new</span> <span class="nx">TemplateError</span> <span class="s2">&quot;Error compiling #{data.filename}: #{e.message}&quot;</span>

<span class="k">return</span> <span class="o">-&gt;</span>
<span class="k">try</span> <span class="nx">tpl</span> <span class="nx">arguments</span><span class="p">...</span>
<span class="k">catch</span> <span class="nx">e</span> <span class="k">then</span> <span class="k">throw</span> <span class="k">new</span> <span class="nx">TemplateError</span> <span class="s2">&quot;Error rendering #{data.filename}: #{e.message}&quot;</span>

</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Vladimir Dronnikov <dronnikov@gmail.com>",
"James Campos <james.r.campos@gmail.com>",
"Martin Westergaard Lassen <martin@mwl.dk>",
"Paul Harper <benekastah@gmail.com>",
"Esa-Matti Suuronen <esa-matti@suuronen.org>",
"Jason King <jasonk@amcoonline.net>",
"Brandon Bloom <brandon@brandonbloom.name>",
Expand Down
9 changes: 5 additions & 4 deletions src/coffeekup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,23 @@ unless window?
simple: coffeekup.render
meryl: coffeekup.render

# Allows `partial 'foo'` instead of `text @partial 'foo'`.
express:
TemplateError: class extends Error
constructor: (@message) ->
Error.call this, @message
Error.captureStackTrace this, arguments.callee
name: "TemplateError"
name: 'TemplateError'

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

TemplateError = @TemplateError
try tpl = coffeekup.compile(template, data)
catch e then throw new TemplateError "Error compiling #{data.filename}: #{e.message}"

return ->
try tpl arguments...
catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"
catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"

0 comments on commit 177bcc3

Please sign in to comment.