Skip to content

Loading…

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

Closed
mitnal opened this Issue · 3 comments

2 participants

@mitnal

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

Because it is the Ruby way :smiley:. 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 :wink:.

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

@netzpirat
Owner

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

@netzpirat netzpirat closed this in 06d1c0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.