Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haml remove whitespace before dot after adding rails link_to, mail_to

I'm writing text in haml:

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

so the haml looks like

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

note . is dot in ascii, I can also replace that line with = '.' (render string dot)

but the rendered text looks like

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

difference is that whitespace before dot at the end

the solution I came up with and works is

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

it's just I'm looking for best practice :) thx

like image 523
equivalent8 Avatar asked Feb 29 '12 12:02

equivalent8


2 Answers

I'd use this:

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

Also see the Haml FAQ:

Expressing the structure of a document and expressing inline formatting are two very different problems. Haml is mostly designed for structure, so the best way to deal with formatting is to leave it to other languages that are designed for it.

In this case you don't need another language, just interpolate the function.

like image 73
matt Avatar answered Oct 22 '22 00:10

matt


If you were to use the == notation, for the line with mail_to, you should be able to do what you want, likle this:

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

The == notation performs interpolation for the entire line.

like image 6
TheDelChop Avatar answered Oct 22 '22 00:10

TheDelChop