I'm generating a Javascript array in StringTemplate 4 and I'm having trouble skipping the trailing coma after last element. Each item gets generated using a template and then I want to separate them using comas to create an array in the form:
[ item1, item2, item3, item4 ]
Currently, my best shot at generating this array is this:
array(elems) ::= <<
[
$first(elems):elem_noComa()$
$rest(elems):elem()$
]
>>
elem_noComa(el) ::= << { ...element generation... } >>
elem(el) ::= <<
, $elem_noComa(el)$
>>
Is there a way to do it easier/in a shorter form?
does this work for you?
It applies itemTemplate() to each element of elems array and using "," in between. Terence