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

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

Comments

Projects
None yet
2 participants
@mitnal

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

This comment has been minimized.

Show comment
Hide comment
@netzpirat

netzpirat Apr 6, 2013

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?

Owner

netzpirat commented Apr 6, 2013

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

This comment has been minimized.

Show comment
Hide comment
@mitnal

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

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

This comment has been minimized.

Show comment
Hide comment
@netzpirat

netzpirat Apr 6, 2013

Owner

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

Owner

netzpirat commented Apr 6, 2013

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 Apr 6, 2013

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