problem with attr: 'false' #29

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

Comments

Projects
None yet
4 participants

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 netzpirat closed this in 691c6bd Jun 12, 2012

Owner

netzpirat commented Jun 12, 2012

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

Owner

netzpirat commented Jun 20, 2012

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.

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.

Owner

netzpirat commented Jun 20, 2012

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 commented Sep 18, 2014

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment