Multiple multi-line HAML blocks

后端 未结 4 1819
野的像风
野的像风 2021-01-01 15:43

Using the (intentionally) strange multi-line format for HAML, I\'d like to have the following lines in my template:

= call_to_helper :foo1 => \'bar1\', :f         


        
4条回答
  •  既然无缘
    2021-01-01 16:13

    This is a feature, not a bug. Haml multiline blocks are intentionally unwieldy - including hard to follow one after another - because almost all the time it's better to put that Ruby code into a helper. Even if the helper is only called once, it will make your template much easier to read. For instance:

    def blatz_link
      call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3',
        :foo4 => 'bar4', :foo5 => 'bar5'
    end
    
    def blootz_link
      call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3',
        :foo4 => 'bar4', :foo5 => 'bar5'
    end
    

    Then in your Haml, just do

    = blatz_link
    = blootz_link
    

    which will be much more readable and easier to understand.


    If you absolutely must follow one multiline block with another, just add a comment in between:

    = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
      :foo4 => 'bar4', :foo5 => 'bar5' |
    -#
    = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
      :foo4 => 'bar4', :foo5 => 'bar5' |
    

提交回复
热议问题