HAML Tip
January 28th, 2008 bySo we were having an issue with haml and using a text-area output. It had indentation when it should not have and double indented after doing a save. A quick google search brought me to Ray Morgan’s Blog for the answer. Basically instead of using the = sign use a ~ and it will preserve whitespace. Thanks Ray. I am posting it here so I will remember where to find it if/when I forget what the answer was in the future.


January 28th, 2008 at 7:11 pm
Just got bit by the same thing a couple days ago. I found someone on the haml mailing list with the same issue. They no longer mention ~ in the manual either,from what the dev said who respond. They are recommending people use the find_and_preserve helper method. It excepts a block. Good tip to spread around though. I think it’s something that bites most people getting used to haml.
January 29th, 2008 at 11:04 am
I had a similar problem because I wanted to output this with Haml:
<pre><code>some multiline code</code></pre>
To avoid indentation problems, all the newlines need to be replaced with character entities, and the code element has to be on the same line as the pre element.
Fiddled around with writing a filter that would accomplish this, but eventually opted for a helper method instead since I realized that I probably would also want to do syntax highlighting.
January 30th, 2008 at 8:30 am
Thanks Greg and Bob for the info. I’ll check out the helpers.