Conditional `selected` at runtime #48

dnagir opened this Issue Aug 22, 2011 · 2 comments


None yet
2 participants

dnagir commented Aug 22, 2011

So how do you generate (or not) selected attribute with HAML similar to this:

#something{selected: visible}

When I do:
Haml.compile('#something{selected: visible}')

I get the code generated:

"<div selected=\"" + undefined(visible) + "\" id=\"something\">" + 

This includes undefined(visible) which is invalid JavaScript.
Am I doing something wrong here?


aaronblohowiak commented Aug 22, 2011

the undefined() is a bug and will be fixed (probably later tonight.) -- it will instead output the html escaping function, by default html_escape().

Can I ask why you are using Haml.compile instead of Haml() ? The latter returns the executable function, with the appropriate with(locals){...}.


dnagir commented Aug 22, 2011

Ok. Thanks for the upcoming fix to this.

I was using compile to see what gets generated to understand better how haml-js works.

But I might also use compile to generate JS code on the server
Currently I am using Haml(".content") then execute toString(). And then strip out the function name.

This seems to be a bit crazy to do.

Additionally I don't like that Haml function wraps the template code in catch block. I would rather prefer to see where exactly the error happened instead of silently rendering the default error template.

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