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

Remove nil values from hash attributes #84

Open
marnen opened this issue Mar 19, 2018 · 1 comment
Open

Remove nil values from hash attributes #84

marnen opened this issue Mar 19, 2018 · 1 comment

Comments

@marnen
Copy link

marnen commented Mar 19, 2018

In the original Ruby Haml implementation, when hash attributes are nil, they're removed from the hash. That is,

- null_var = nil
#test{string: "a string", null: nil, null_var: null_var}

becomes

<div id="test" string="a string"></div>

(see https://codepen.io/marnen/pen/eMgNRN/). null and null_var are both omitted.

Calliope doesn't do this: instead, the same Haml renders to

<div id="test" string="a string" null='' null_var=''></div>

so that there is an extraneous attribute.

I was hoping to be able to make a pull request to add this behavior to Calliope, but it seems like it will be quite difficult: it looks like the reason that Calliope doesn't remove null values is that it simply translates Haml to EEx without doing any variable evaluation, and EEx has no corresponding feature to Haml's hash attributes (other than name="<%= value %>", which doesn't really do the trick in this case).

I think this points to an inconvenient fact: if Calliope is going to achieve feature parity with Haml, it probably needs to render directly to Elixir (AST, perhaps), rather than simply acting as an EEx preprocessor (just as Ruby Haml doesn't render to ERb). But that's a longer-term solution. In the shorter term, what would be a good way of achieving null attribute removal in Calliope? Or should we just bite the bullet and get rid of the EEx intermediate layer?

@marnen
Copy link
Author

marnen commented Mar 20, 2018

I'm starting to work on an EEx-free Haml implementation at https://github.com/marnen/hamlex. I'd be happy to merge that into Calliope if there's interest (and if I manage to implement anything :) ).

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

1 participant