【发布时间】:2010-12-01 06:12:20
【问题描述】:
对 HAML 使用(故意)奇怪的多行格式,我想在我的模板中包含以下行:
= call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
:foo4 => 'bar4', :foo5 => 'bar5' |
-# and
= call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
:foo4 => 'bar4', :foo5 => 'bar5' |
但是,它们不能相互碰撞,或者它们被读取为一个单独的多行块。
-# This fails:
= 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' |
有趣的是,用换行符分隔并没有更好的效果:
-# This fails, too:
= 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' |
我发现的唯一可行的解决方案是在两者之间运行一个空的 Ruby 代码行。看起来真的很丑。
= 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' |
还有什么更好的吗?
【问题讨论】:
-
更新: 最新版本的 HAML 中不需要管道,所以如果您刚刚遇到这个问题,请不要纠结于此;)
标签: ruby-on-rails haml