Ruby 1.9 style hash syntax can sometimes cause compiled indentation to be wrong #424

Closed
amarshall opened this Issue Aug 22, 2011 · 6 comments

Comments

Projects
None yet
5 participants
@amarshall

It appears that when using 1.9-style hash syntax for the attributes of a self-closing HTML element which is then, at any point in the file, followed by a = yield, the indentation of the yielded HAML, after the first line, is incorrect. The number of self-closing elements with 1.9-style hash syntax increases the amount of excess indentation. After the yield is complete, the rest of the layout is indented correctly.

Changing the hash syntax back to the 1.8 hashrocket results in correct indentation. The issue does not appear with elements that are not self-closing nor when there is no yield. The element causing the problem need not be immediately followed by the yield; this originally occurred with numerous meta and style tags in the header.

Where the layout is:

%html
  %body
    %img{src: "test"}
    = yield

and the yielded view is:

Test1
Test2
Test3

compiles to:

<html> 
  <body> 
    <img src='test' /> 
    Test
      Test2
      Test3
  </body> 
</html> 

duplicating the img tag results in:

<html> 
  <body> 
    <img src='test' /> 
    <img src='test' /> 
    Test
        Test2
        Test3
  </body> 
</html>

This occurs using Haml 3.1.2 under Sinatra 1.2.6.

@amarshall

This comment has been minimized.

Show comment Hide comment
@amarshall

amarshall Aug 22, 2011

Another case:

%html
  %body
    %img{src: "test"}
    :javascript
      App.init('#{@myvar}');

renders:

<html> 
  <body> 
    <img src='test' /> 
    <script type='text/javascript'> 
        //<![CDATA[
          App.init('myvalue');
        //]]>
    </script> 
  </body> 
</html> 

If there is no 1.9-style hash or if there is no interpolation, it works.

Another case:

%html
  %body
    %img{src: "test"}
    :javascript
      App.init('#{@myvar}');

renders:

<html> 
  <body> 
    <img src='test' /> 
    <script type='text/javascript'> 
        //<![CDATA[
          App.init('myvalue');
        //]]>
    </script> 
  </body> 
</html> 

If there is no 1.9-style hash or if there is no interpolation, it works.

@kj

This comment has been minimized.

Show comment Hide comment
@kj

kj Aug 25, 2011

I can confirm this. I spent hours agonizing over it before trying the last thing I ever thought would cause it... the hash syntax. I didn't consider it earlier as the element in question (a stylesheet link) still worked as normal. I was just on my way to report this when I noticed the very issue I was having was at the top of the list! Thanks for reporting this.

(Sinatra 1.2.6, Haml 3.1.2 and Ruby 1.9.2p180)

kj commented Aug 25, 2011

I can confirm this. I spent hours agonizing over it before trying the last thing I ever thought would cause it... the hash syntax. I didn't consider it earlier as the element in question (a stylesheet link) still worked as normal. I was just on my way to report this when I noticed the very issue I was having was at the top of the list! Thanks for reporting this.

(Sinatra 1.2.6, Haml 3.1.2 and Ruby 1.9.2p180)

@kristianmandrup

This comment has been minimized.

Show comment Hide comment
@kristianmandrup

kristianmandrup Sep 7, 2011

Would be really nice if HAML supported the Ruby 1.9 Hash syntax for HTML element attributes ;)

Would be really nice if HAML supported the Ruby 1.9 Hash syntax for HTML element attributes ;)

@jmacdonald

This comment has been minimized.

Show comment Hide comment
@jmacdonald

jmacdonald Oct 27, 2011

Agreed; it's much easier to type and is more visually appealing, too.

Agreed; it's much easier to type and is more visually appealing, too.

@nex3

This comment has been minimized.

Show comment Hide comment
@nex3

nex3 Nov 28, 2011

Collaborator

Closed by 332401a

Collaborator

nex3 commented Nov 28, 2011

Closed by 332401a

@nex3 nex3 closed this Nov 28, 2011

@amarshall

This comment has been minimized.

Show comment Hide comment
@amarshall

amarshall Nov 28, 2011

Awesome, thanks!

Awesome, thanks!

iHiD pushed a commit to iHiD/haml that referenced this issue Jan 22, 2012

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