Multiline HAML Statement
Update: Haml 2.2 has added native multiline attributes, so the example below is still valid syntax, but unnecessary. The pipe syntax can still be used for other spots where multiline is needed though.
Something I hate is the line that goes off into infinity on the right of my editor. And of course, too often, it’s in my HAML code, where it’s totally non-obvious how to break a line into several parts.
The answer is straight forward though. Just end each line of the statement (first, last, and everything in between!) with a pipe | character.
= { :foo => :bar, | :baz => :foo, | :quux => :zz}.inspect |
February 26th, 2009 at 10:21 am
Thanks for the tip! I’ve been using HAML for over a year, but somehow this feature slipped past me.
February 22nd, 2010 at 3:09 pm
If you put a pipe on every line, how does haml know when it’s at the end of a statement? Could I just select the 79th column in bbedit, and add a pipe to every line in that position? In other words, does this work on two consecutive long lines?