Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haml: more elegant way to write tag + ruby-expression + string

I've got the following haml-code in one of my templates:

%b= t ('activerecord.attributes.exercise.title') + ':'

Is there a more elegant way to achieve this? Preferrably as oneliner and without the brackets.

like image 995
wintersolutions Avatar asked Dec 18 '25 23:12

wintersolutions


1 Answers

The solution I like to use is Haml’s surround, succeed, and precede helpers:

= surround '(', ')' do
  = link_to 'available here', foo_path


= precede '*' do
  = link_to 'source', foo_path


= succeed ':' do
  = link_to 'foo', foo_path
Text following link

Then it’s just typing/pasting a line before the helper and indenting the helper.

like image 88
Alan H. Avatar answered Dec 21 '25 13:12

Alan H.