简体   繁体   中英

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.

这样看起来好点吗?

%b #{t 'activerecord.attributes.exercise.title'}:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM