Skip to content

Commit

Permalink
In ck.render, option cache is now false by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Jul 26, 2011
1 parent 99ff120 commit af9cfe5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
- Added IE conditional comments: `ie 'lt IE8', -> 'IE 7 or less specific stuff'` (thanks @aeosynth).

- Using '.call(this);' instead of '();' in js generated by the 'coffeescript' tag.

- In `coffeekup.render`, option `cache` is now `false` by default.

**v0.2.3** (2011-05-06):

Expand Down
22 changes: 14 additions & 8 deletions benchmark.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,21 @@ benchmark = (title, code) ->

@run = ->
benchmark 'CoffeeKup (precompiled)', -> coffeekup_compiled_template data
benchmark 'CoffeeKup (code)', -> coffeekup.render coffeekup_template, data
benchmark 'CoffeeKup (code, cache off)', -> coffeekup.render coffeekup_template, data, cache: off
benchmark 'CoffeeKup (string)', -> coffeekup.render coffeekup_string_template, data, cache: on
benchmark 'CoffeeKup (string, cache off)', -> coffeekup.render coffeekup_string_template, data, cache: off
benchmark 'Jade (precompiled)', -> jade_compiled_template data
benchmark 'Jade (cache off)', -> jade.render jade_template, locals: data
benchmark 'Jade (cache on)', -> jade.render jade_template, locals: data, cache: on, filename: 'test'
benchmark 'haml-js (precompiled)', -> haml_template_compiled data
benchmark 'Eco', -> eco.render eco_template, data
benchmark 'ejs (cache off)', -> ejs.render ejs_template, locals: data

console.log '\n'

benchmark 'CoffeeKup (function, cache on)', -> coffeekup.render coffeekup_template, data, cache: on
benchmark 'CoffeeKup (string, cache on)', -> coffeekup.render coffeekup_string_template, data, cache: on
benchmark 'Jade (cache on)', -> jade.render jade_template, locals: data, cache: on, filename: 'test'
benchmark 'ejs (cache on)', -> ejs.render ejs_template, locals: data, cache: on, filename: 'test'

console.log '\n'

benchmark 'CoffeeKup (function, cache off)', -> coffeekup.render coffeekup_template, data
benchmark 'CoffeeKup (string, cache off)', -> coffeekup.render coffeekup_string_template, data, cache: off
benchmark 'Jade (cache off)', -> jade.render jade_template, locals: data
benchmark 'haml-js', -> haml.render haml_template, locals: data
benchmark 'haml-js (precompiled)', -> haml_template_compiled data
benchmark 'ejs (cache off)', -> ejs.render ejs_template, locals: data
2 changes: 1 addition & 1 deletion docs/coffeekup.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
<code>locals</code> and <code>hardcode</code>), and the template (which understands the options
<code>format</code> and <code>autoescape</code>).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">coffeekup.render = </span><span class="nf">(template, data = {}, options = {}) -&gt;</span>
<span class="nx">data</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="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">options</span>
<span class="nx">data</span><span class="p">.</span><span class="nx">cache</span> <span class="o">?=</span> <span class="kc">on</span>
<span class="nx">data</span><span class="p">.</span><span class="nx">cache</span> <span class="o">?=</span> <span class="kc">off</span>

<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>
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Compiles the template provided, runs it, and returns the resulting HTML string.

Options:

- `cache`: `true` by default. Whether to reuse compiled templates, or re-compile them every time.
- `cache`: `false` by default. Whether to reuse compiled templates, or re-compile them every time.

### version

Expand Down
2 changes: 1 addition & 1 deletion src/coffeekup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ cache = {}
#
coffeekup.render = (template, data = {}, options = {}) ->
data[k] = v for k, v of options
data.cache ?= on
data.cache ?= off

if data.cache and cache[template]? then tpl = cache[template]
else if data.cache then tpl = cache[template] = coffeekup.compile(template, data)
Expand Down

0 comments on commit af9cfe5

Please sign in to comment.