see add
.
var t = new Template
t.add_list(["1", "2", "3"], ", ", " and ")
assert t.write_to_string == "1, 2 and 3"
# Append a bunch of elements at the end of the template with separations.
# see `add`.
#
# var t = new Template
# t.add_list(["1", "2", "3"], ", ", " and ")
# assert t.write_to_string == "1, 2 and 3"
fun add_list(elements: Collection[Writable], sep, last_sep: Writable) do
var last = elements.length - 2
var i = 0
for e in elements do
content.add e
if i < last then
content.add sep
else if i == last then
content.add last_sep
end
i += 1
end
end
lib/template/template.nit:133,2--151,4