How do I wrap multiline Ruby arguments in HAML?

jhchen picture jhchen · Mar 25, 2013 · Viewed 10.9k times · Source

How can I use multiple lines for a single Ruby statement in HAML? For example, I'd like to write something like the following:

- entries = [{
-   :title => "The Fellowship of the Ring", 
-   :body => "We should walk instead of fly"
- }]

!!! 5
%html
  %head
    %title Blog
  %body
    #content
      - entries.each do |entry|
        .entry
          %h3.title= entry[:title]
          %p.body= entry[:body]

But of course the first four lines produce a syntax error.

Answer

Todd A. Jacobs picture Todd A. Jacobs · Mar 25, 2013

Wrap Arguments with Commas

According to the HAML FAQ:

[W]hen a function has lots of arguments, it’s possible to wrap it across multiple lines as long as each line ends in a comma.

So, the following should be valid HAML:

- entries = [{ :title => "The Fellowship of the Ring", 
               :body  => "We should walk instead of fly" }]