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

Attributes keys do not behave like current (4.0.0) haml version #65

Closed
mitnal opened this issue Apr 6, 2013 · 3 comments
Closed

Attributes keys do not behave like current (4.0.0) haml version #65

mitnal opened this issue Apr 6, 2013 · 3 comments

Comments

@mitnal
Copy link

mitnal commented Apr 6, 2013

The current haml version converts underscores in attribute keys to dashes:

Source:

%p{ data: { my_attr: 'content' }}

Current output:

<p data-my_attr='content'></p>

Expected output (from Haml 4.0.0):

<p data-my-attr="content"></p>

More Info: http://haml.info/docs/yardoc/file.REFERENCE.html#html5_custom_data_attributes

@netzpirat
Copy link
Owner

The reason why Haml has this feature is that the Hash syntax needs to be a valid Ruby Hash, thus

%p{ data: { my-attr: 'content' }}

will produce a syntax error. But this is not true for Haml Coffe, where the above template compiles fine and results in the expected HTML.

So why do you want to write the attribute with an underscore and have Haml Coffe convert it for you, when you simply can write it in the desired way from the beginning?

@mitnal
Copy link
Author

mitnal commented Apr 6, 2013

Because it is the Ruby way 😃. As you point out the above is not valid Ruby and so it is not valid Haml.

See: http://haml.info/docs/yardoc/file.REFERENCE.html#attributes

Brackets represent a Ruby hash that is used for specifying the attributes of an element. It is literally evaluated as a Ruby hash, so logic will work in it and local variables may be used.

And why would I want to write Haml in two different ways, from which one is not even valid Haml? I always have to remember if I am in an haml-coffee file or in a regular haml file. I can not simple copy paste 'static' haml from one file to the other. And I think it is inconsistent behavior.

I also could write it as:

%p( data-my-attr: "content")

But I just do not want to write my Haml this way 😉.

That said: I really linke this project and you done a great job! Thx!

@netzpirat
Copy link
Owner

Agree, those are valid arguments. Thanks for coming up with the issue and pointing me to the right direction.

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