-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problem with attr: 'false' #29
Comments
Thanks for reporting, the boolean attributes behaved in fact different than Ruby HAML. The challenge for haml-coffee is that we have two different phases for processing Boolean logic: compile time (easy) and render time (tricky). The render time conversion was not able to differentiate between real booleans and boolean-like string. I found a nifty little trick to finally be able to distinguish between these, so with version 1.1.0 haml-coffee should behave correct for both, compile and render time boolean attributes. |
With this update, my regular checked='true' has stopped working. I have restarted my rails server, updated my file so that it is certainly recompiled. The hidden unicode is in the hamlc javascript but not in my templates. |
JavaScript supports Unicode since version 1.3, so there's no need for a special charset. With this change, coffee> hc = require 'haml-coffee'
{ compile: [Function],
template: [Function] }
coffee> t = hc.compile "%input{ type: 'checkbox', checked: 'true' }"
[Function]
coffee> t()
'<input type=\'checkbox\' checked=\'true\'>' whereas coffee> hc = require 'haml-coffee'
{ compile: [Function],
template: [Function] }
coffee> t = hc.compile "%input{ type: 'checkbox', checked: true }"
[Function]
coffee> t()
'<input type=\'checkbox\' checked>' As you see, I cannot reproduce it currently. There are currently quite some integration tests that covers booleans: This template will be converted to this HTML5 and this XHTML result. Also the Haml Specs covers some boolean conversions. Can you please give me some information about your runtime and provide the failing code snippet? Thanks. |
Hi Michael The problem lies here in the generated template file: $o.push("<input name='privacy' type='radio' value='onlyme' checked='" + privacy + "'>"); As you can see, single quotes are being forced around the checked value without any unicode in them. |
Yep, haml-coffee is the template engine, whereas haml_coffee_assets is only the Rails asset pipeline integration. I'm still not able to reproduce it: coffee> hc = require 'haml-coffee'
{ compile: [Function],
template: [Function] }
coffee> t = hc.compile "- privacy = true\n%input{ name: 'privacy', type: 'radio', value: 'onlyme', checked: privacy }"
[Function]
coffee> t()
'<input name=\'privacy\' type=\'radio\' value=\'onlyme\' checked>'
coffee> t = hc.compile "- privacy = false\n%input{ name: 'privacy', type: 'radio', value: 'onlyme', checked: privacy }"
[Function]
coffee> t()
'<input name=\'privacy\' type=\'radio\' value=\'onlyme\'>' or with a context variable: coffee> hc = require 'haml-coffee'
{ compile: [Function],
template: [Function] }
coffee> t = hc.compile "%input{ name: 'privacy', type: 'radio', value: 'onlyme', checked: @privacy }"
[Function]
coffee> t({ privacy: true })
'<input name=\'privacy\' type=\'radio\' value=\'onlyme\' checked>'
coffee> t({ privacy: false })
'<input name=\'privacy\' type=\'radio\' value=\'onlyme\'>' Can you please provide the actual haml-coffee snippet instead of the generated template code? |
@aaronjensen @coffeebite did either of you figure out how to actually resolve this issue? |
I don't recall... I haven't been using hamlc recently so I won't be of much help. |
I've seen a couple bugs about this that say its fixed, but I can't get it working.
Haml behaves differently than hamlc in this case:
In haml, this gets rendered to:
hamlc gets rendered to
There is no way that I can tell to set value to be 'false' other than to do this:
!= "<param value = 'true' />"
The text was updated successfully, but these errors were encountered: