2012-08-08 114 views
0

这是代码如何从haml中的这段代码中删除空格?

.meta 
    = time_ago_in_words(discussion.created_at) 
    ago by 
    = discussion.user.username 
    | 
    = link_to "Edit", edit_discussion_path(discussion), class: "meta" 
    | 
    = link_to "Delete", discussion_path(discussion), method: :delete, confirm: "Are you sure?", class: "meta" 

这是输出:

<div class='meta'> 
     about 7 hours 
     ago by 
     foo 
     | 
     <a href="/discussions/2/edit" class="meta">Edit</a> 
     | 
     <a href="/discussions/2" class="meta" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a> 
    </div> 

这使得输出对|的两侧不平衡的空间。

是否可以删除这些语句之间的空格,而不是将所有内容都添加到span,或仅使用erbstring interpolation

回答

0

截至目前(2012年10月21日),没有办法优雅地做到这一点。

如果您在阅读本文时有可能,请回答问题,我会将其标记为答案。

1

会明确地将它打印为Ruby String的帮助吗?

.meta 
    = time_ago_in_words(discussion.created_at) 
    ago by 
    = discussion.user.username 
    = "|" 
    = link_to "Edit", edit_discussion_path(discussion), class: "meta" 
    = "|" 
    = link_to "Delete", discussion_path(discussion), method: :delete, confirm: "Are you sure?", class: "meta" 

我的意思是,这是不是最好的代码,我宁愿只需将字符,如您最初的尝试,但由于HAML力压痕你可能不得不采取某种不同的路径,用于确定空白/空间-characters。我想这样做可能会给你简单的精度,只要在任何一边添加特定数量的空格或&nbsp;个字符(如果需要多个)。

编辑:我注意到标题指定“删除”空白,而不是“平衡”它 - 我的错误。因此,您可以尝试succeed,如此处所述:Haml: Control whitespace around textSucceed没有跟进,或者跟着是空字符串,应该可能实现你想要的而没有任何空格。

编辑2:你是绝对正确的,>修改不符合红宝石打印线(如link to)工作。成功应该仍然有效,或者您可以创建一个帮助函数,将所有这些行连接成一个字符串。

+0

不,在这种语句的末尾添加'>'是无效的haml。不适合我。 – Dogbert 2012-08-08 12:07:40

+0

你是绝对正确的,不确定我在想什么,但'''修饰符在ruby打印行上不可用。可能最好使用'succeed'或一个辅助函数来处理小的字符串。 – DRobinson 2012-08-08 13:14:58

-5

打开乌尔在土坯dreamwever和PRES Ctrl + F键代码..

写入下面的代码,并用蜱正则表达式框

在查找框中

:\ r \ n]的{2,}

在替换框中:\ n

ň全部更换...

enjoyyyy