ruby-on-rails – 多个多行HAML块

使用(有意)奇怪的多行格式的HAML,我想在我的模板中有以下几行:
= call_to_helper :foo1 => 'bar1',:foo2 => 'bar2',:foo3 => 'bar3',|
  :foo4 => 'bar4',:foo5 => 'bar5' |

-# and

= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

但是,它们不能相互竞争,或者被看作是一个单独的多行块.

-# This fails:
= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |
= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

有条不紊地分手,有趣的是,没有什么更好的:

-# This fails,too:
= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

我发现唯一的工作解决方案是在其间运行一行空白的Ruby代码.看起来真的很丑陋.

= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |
-
= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

有更好的吗?

解决方法

这是一个功能,而不是一个bug.哈姆勒多线程块是有意笨重的 – 包括难以追随的一个一个 – 因为几乎所有的时间最好把这个Ruby代码放在一个帮手中.即使帮助者只调用一次,它将使您的模板更容易阅读.例如:
def blatz_link
  call_to_helper :foo1 => 'bar1',:foo4 => 'bar4',:foo5 => 'bar5'
end

def blootz_link
  call_to_helper :foo1 => 'bar1',:foo5 => 'bar5'
end

然后在你的哈姆尔,只是做

= blatz_link
= blootz_link

这将更加可读和更容易理解.

如果你绝对必须跟随一个多行块与另一个,只需添加一个注释之间:

= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |
-#
= call_to_helper :foo1 => 'bar1',:foo5 => 'bar5' |

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...