Software /
code /
prosody
Changeset
13404:034c7af177f0
util.xtemplate: Test the each template function
It iterates over childtags, so a template like {foo|each{...}} would be
equivalent to root:childtags("foo"), while a deeper query needs the bit
that becomes arguments to :childtags as an argument to each, e.g.
{foo/bar|each(baz)} would behave like
root:get_child("foo"):get_child("bar"):childtags("baz")
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 Dec 2023 13:47:55 +0100 |
parents | 13403:0369f6986824 |
children | 13405:c8f3cfe59e90 |
files | spec/util_xtemplate_spec.lua |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_xtemplate_spec.lua Tue Dec 12 16:19:04 2023 +0100 +++ b/spec/util_xtemplate_spec.lua Sat Dec 16 13:47:55 2023 +0100 @@ -31,5 +31,13 @@ assert.same(" Hello", xtemplate.render(" {greeting-} ", st.stanza("root"):text_tag("greeting", "Hello"))) assert.same("Hello", xtemplate.render(" {-greeting-} ", st.stanza("root"):text_tag("greeting", "Hello"))) end) + describe("each", function () + it("makes sense", function () + local x = st.stanza("root"):tag("foo"):tag("bar") + for i = 1, 5 do x:text_tag("i", tostring(i)); end + x:reset(); + assert.same("12345", xtemplate.render("{foo/bar|each(i){{#}}}", x)); + end) + end) end) end)