Skip to content
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

Closed
aaronjensen opened this issue Jun 11, 2012 · 7 comments
Closed

problem with attr: 'false' #29

aaronjensen opened this issue Jun 11, 2012 · 7 comments

Comments

@aaronjensen
Copy link

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:

%param{ :value => 'false' }
%param{ :value => false }

In haml, this gets rendered to:

<param value='false' />
<param />

hamlc gets rendered to

<param />
<param />

There is no way that I can tell to set value to be 'false' other than to do this:

!= "<param value = 'true' />"
@netzpirat
Copy link
Owner

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.

@coffeebite
Copy link

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.
Do I need to specify some special charset somewhere?

@netzpirat
Copy link
Owner

JavaScript supports Unicode since version 1.3, so there's no need for a special charset.

With this change, checked: 'true' is now seen a plain String literal and no boolean conversion logic is performed:

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 checked: true will be recognized as boolean:

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.

@coffeebite
Copy link

Hi Michael
I'm actually using haml-coffee-assets for my rails project. But I'm guessing this project is responsible for the logic of template generation?

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.

@netzpirat
Copy link
Owner

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?

@mrchess
Copy link

mrchess commented Sep 18, 2014

@aaronjensen @coffeebite did either of you figure out how to actually resolve this issue?

@aaronjensen
Copy link
Author

I don't recall... I haven't been using hamlc recently so I won't be of much help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants