ruby-on-rails – Haml:控制文本周围的空格

在我的Rails模板中,我想使用HAML完成最终的HTML效果:

I will first <a href="http://example.com">link somewhere</a>, then render this half of the sentence if a condition is met

接近的模板:

I will first
= link_to 'link somewhere', 'http://example.com'
- if @condition
  , then render this half of the sentence if a condition is met

但是,您可能会注意到,这会在链接和逗号之间产生一个空格。有没有任何实用的方法来避免这个空格?我知道有删除标记周围的空格的语法,但是这个相同的语法可以应用于文本?我真的不喜欢额外的标记的解决方案来完成这一点。

一个更好的方法是通过Haml的帮助介绍:

surround

= surround '(', ')' do
  %a{:href => "food"} chicken

产品:

(<a href='food'>chicken</a>)

succeed

click
= succeed '.' do
  %a{:href=>"thing"} here

产品:

click
<a href='thing'>here</a>.

precede

= precede '*' do
  %span.small Not really

产品:

*<span class='small'>Not really</span>

回答原来的问题:

I will first
= succeed ',' do
  = link_to 'link somewhere', 'http://example.com'
- if @condition
  then render this half of the sentence if a condition is met

产品:

I will first
<a href="http://example.com">link somewhere</a>,
then render this half of the sentence if a condition is met
http://stackoverflow.com/questions/1311428/haml-control-whitespace-around-text

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:ruby-on-rails – Haml:控制文本周围的空格