Last Updated: February 25, 2016
·
1.18K
· saratovsource

DRY with *haml_coffee_assets* and partials

DRY

https://github.com/netzpirat/haml_coffee_assets

You can render partial templates with hamlcoffeeassets. It is very simple to use:

In first file (/template/index.jst.hamlrc):

%p Lorem ipsum...
%ul
  - for @word in ['Sample', 'text', 'string']
    %li!= JST['path/to/partial'](class: 'red_text', word: @word)

In partial (/path/to/partial.jst.hamlc):

%span{class: @class}= @word

Result:

<p>Lorem ipsum...</p>
<ul>
  <li><span class='red_text'>Sample</span></li>
  <li><span class='red_text'>text</span></li>
  <li><span class='red_text'>string</span></li>
</ul>