Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Put helpers inside coffeescript closure
  • Loading branch information
wmertens committed Aug 22, 2012
1 parent 272d8af commit b064cc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/coffeemugg.coffee
Expand Up @@ -279,8 +279,8 @@ HTMLPlugin = (context) ->
if t.indexOf(k) >= 0
helpers += ',' if helpers
helpers += "#{k}=#{v}"
helpers = "var #{helpers};" if helpers
"#{helpers}(#{t}).call(this);"
t = t.replace(/^[^{]+{/, "function(){var #{helpers};") if helpers
"(#{t}).call(this);"

context.coffeescript = (param) ->
switch typeof param
Expand Down
10 changes: 8 additions & 2 deletions test.coffee
Expand Up @@ -103,7 +103,7 @@ tests =
'Attribute values':
template: ->
@br vrai: yes, faux: no, undef: @foo, nil: null, str: 'str', num: 42, arr: [1, 2, 3], obj: {foo: 'bar'}, func: ->,
expected: '<br vrai="vrai" str="str" num="42" arr="1,2,3" obj="[object Object]" func="function () {}" />'
expected: '<br vrai="vrai" str="str" num="42" arr="1,2,3" obj="[object Object]" func="(function () {}).call(this);" />'

'IE conditionals':
template: ->
Expand All @@ -129,10 +129,16 @@ tests =
template: ->
@coffeescript ->
f a, b...
expected: '<script>var __slice=[].slice;(function () {\n return f.apply(null, [a].concat(__slice.call(b)));\n }).call(this);</script>'
expected: '<script>(function(){var __slice=[].slice;\n return f.apply(null, [a].concat(__slice.call(b)));\n }).call(this);</script>'
# This gets retained somehow?
options: {format: no}

'CoffeeScript function in tag':
template: ->
@div onmouseover: ->
f "&&a", b...
expected: '<div onmouseover="(function(){var __slice=[].slice;\n return f.apply(null, [&quot;&amp;&amp;a&quot;].concat(__slice.call(b)));\n }).call(this);"></div>'

'CoffeeScript string':
template: ->
@coffeescript "alert 'hi'"
Expand Down

0 comments on commit b064cc3

Please sign in to comment.