2012-02-29 94 views
5

我在HAML輸入文字:HAML添加軌的link_to後點之前刪除空格,MAIL_TO

Blab bla for any questions contact us on [email protected] 

所以HAML看起來像

%p 
    Blab bla for any questions contact us on 
    = mail_to '[email protected]' 
    . 

注.在ASCII碼點,我也可以替換該行與= '.'(渲染串點)

,但呈現的文本看起來像

Blab bla for any questions contact us on [email protected] . 

不同的是在最後

點之前空白解決方案我想出了和作品是

%p 
    Blab bla for any questions contact us on 
    = mail_to('[email protected]') + '.' 

這只是我正在尋找最佳實踐:) thx

回答

10

我會使用這樣的:

%p 
    Blab bla for any questions contact us on #{mail_to('[email protected]')}. 

另見the Haml FAQ

表達文檔的結構和表達內嵌格式是兩個完全不同的問題。 Haml主要是爲結構設計的,所以處理格式的最好方法是將其留給其他專門爲它設計的語言。

在這種情況下,您不需要其他語言,只需插入函數即可。

+0

這是一個史詩般的勝利:)!謝謝。鏈接也很有幫助。 – equivalent8 2012-02-29 15:57:30

+0

還有一個問題是,當使用任何ruby框架(sinatra,padrino f.e.)時,這僅僅是本地軌道事件,或者默認情況下由haml支持? – equivalent8 2012-02-29 16:01:38

+0

@ equivalent8這是正常的Haml行爲:http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ruby_interpolation_ – matt 2012-02-29 17:53:02

5

如果你使用的==符號,與MAIL_TO行了,你應該能夠做你想做的,這likle:

== #{mail_to '[email protected]'}. 

==符號進行整條生產線插補。

+0

是的,這是工作,它比我的解決方案更優雅。請問有什麼其他的解決方案:) – equivalent8 2012-02-29 13:02:45

3

HAML有a bunch of helpers很容易解決這種情況。 succeed解決了拖尾點問題。

= succeed '.' do 
    = link_to t('info.terms'), info_path(:terms)