1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
import ety

ns test

pub fn template() {
    let tmpl = ety.compile(
        '''
        ### This is a template string.
        #### You have <%= #widgets %> widgets:
        <% for w in widgets { %>
        - Widget: <%= w.name %>
        <% } %>
        ''',
        ['widgets']
    )
    let widgets = [
        { name: 'Widget A' },
        { name: 'Widget B' },
        { name: 'Widget C' }
    ]
    let output = tmpl(widgets)
    let expected =
        '''
        ### This is a template string.
        #### You have 3 widgets:
        - Widget: Widget A
        - Widget: Widget B
        - Widget: Widget C

        '''
    assert(output == expected)
}