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

Conditional selected at runtime #48

Open
dnagir opened this issue Aug 22, 2011 · 2 comments
Open

Conditional selected at runtime #48

dnagir opened this issue Aug 22, 2011 · 2 comments

Comments

@dnagir
Copy link

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\">" + 
"</div>"

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

@aaronblohowiak
Copy link
Collaborator

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){...}.

Thanks!

@dnagir
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants