ruby - Is it possible to pass a value to a YAML list? -
i'm looking way pass value list enumerable, produce set of list items <ul>. value should displayed item allows it.
- new
- favorites (15) <-- 15 being value want displayed.
- archived
- deleted
the following not work is, should illustrate goal achieve.
haml
%ul =list_of t('.menu', favorites_count: 15) |item| #{item}
yaml
menu: - new - favorites ('%{favorites_count}') - archived - deleted
note: had yaml include <li> tags in dictionary form, inside strings, 1 of includes count value. find bit clumsy mix html , yaml, so:
menu: first_item: <li>new</li> second_item: <li>favorites %{favorites_count}</li> third_item: <li>archived</li> fourth_item: <li>deleted</li>
hence looking cleaner option, render tags on haml side , not litter them in yaml.
i18n.t
uses interpolation syntax similar sprintf
's, can use advantage:
%ul = list_of t(".item") |item| = sprintf(item, favorites_count: 15)
i'm not entirely sure that's right haml syntax, idea.
Comments
Post a Comment