简体   繁体   English

Haml:编写标签+ ruby​​-expression +字符串的更优雅的方式

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

I've got the following haml-code in one of my templates: 我的模板之一中包含以下haml代码:

%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: 我喜欢用的解决方案是Haml的的surroundsucceed ,并precede助手:

= 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. 然后,它只是在帮助程序之前键入/粘贴一行并缩进该帮助程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在haml中的多行上编写单个表达式? - Is there a way to write a single expression over multiple lines in haml? 有没有更优雅的方法来执行多重包含? 选择红宝石? - Is there a more elegant way to perform a multiple include? selection in ruby? 在Ruby中,有一种替代的,更优雅的方法来调用方法而不是'case - when'吗? - In Ruby is there an alternative and more elegant way to call a method than 'case - when'? 有没有更优雅的方式来写这个? activerecord中的变量不是nil - is there a more elegant way to write this? variable within activerecord is not nil Ruby-更优雅地推向数组 - Ruby - more elegant pushing to array Ruby 中最优雅的替换“?”的方法是什么? 在字符串中,值在数组中 - What is the most elegant way in Ruby to substitute '?' in string with values in array 在haml字符串中编写ruby代码 - Writing ruby code in a haml string 使用haml和Ruby On Rails对Select_tag进行排序 - Sorting a Select_tag with haml and Ruby On Rails 在 ruby​​ 中写入条件的正确格式,然后使用 HAML 标记内的字符串插值将输出转换为字符串 - Correct format for writing conditionals in ruby and then converting output into string using string interpolation inside HAML tag 有没有更有效/正确的方法在Ruby中编写它? - Is there a more efficient/proper way to write this in Ruby?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM