# HG changeset patch # User Kim Alvefur # Date 1616272191 -3600 # Node ID 348b191cd850d8455dbae9adfae4524f38b1bb92 # Parent 88792dd2bee90169e5a42c59e2b090ac0ee540d4 util.datamapper: Complete array building support diff -r 88792dd2bee9 -r 348b191cd850 spec/util_datamapper_spec.lua --- a/spec/util_datamapper_spec.lua Sat Mar 20 21:25:45 2021 +0100 +++ b/spec/util_datamapper_spec.lua Sat Mar 20 21:29:51 2021 +0100 @@ -181,5 +181,16 @@ assert.equal(#x.tags-1, #u.tags) end); + + it("handles arrays", function () + local u = map.unparse(disco_schema, disco); + assert.equal("urn:example:feature:1", u:find("{http://jabber.org/protocol/disco#info}query/feature/@var")) + local n = 0; + for child in u:get_child("query", "http://jabber.org/protocol/disco#info"):childtags("feature") do + n = n + 1; + assert.equal(string.format("urn:example:feature:%d", n), child.attr.var); + end + end); + end); end) diff -r 88792dd2bee9 -r 348b191cd850 teal-src/util/datamapper.tl --- a/teal-src/util/datamapper.tl Sat Mar 20 21:25:45 2021 +0100 +++ b/teal-src/util/datamapper.tl Sat Mar 20 21:29:51 2021 +0100 @@ -323,18 +323,9 @@ return out; elseif schema.type == "array" then - local proptype, value_where, name, namespace = unpack_propschema(schema.items, current_name, current_ns) - -- TODO , prefix, single_attribute - if proptype == "string" then - for _, item in ipairs(t as { string }) do - if value_where == "in_text_tag" then - out:text_tag(name, item, { xmlns = namespace }); - else - error "NYI" - end - end - else - error "NYI" + local proptype, value_where, name, namespace, prefix, single_attribute = unpack_propschema(schema.items, current_name, current_ns) + for _, item in ipairs(t as { string }) do + unparse_property(out, item, proptype, schema.items, value_where, name, namespace, current_ns, prefix, single_attribute) end return out; end diff -r 88792dd2bee9 -r 348b191cd850 util/datamapper.lua --- a/util/datamapper.lua Sat Mar 20 21:25:45 2021 +0100 +++ b/util/datamapper.lua Sat Mar 20 21:29:51 2021 +0100 @@ -290,18 +290,9 @@ return out elseif schema.type == "array" then - local proptype, value_where, name, namespace = unpack_propschema(schema.items, current_name, current_ns) - - if proptype == "string" then - for _, item in ipairs(t) do - if value_where == "in_text_tag" then - out:text_tag(name, item, {xmlns = namespace}); - else - error("NYI") - end - end - else - error("NYI") + local proptype, value_where, name, namespace, prefix, single_attribute = unpack_propschema(schema.items, current_name, current_ns) + for _, item in ipairs(t) do + unparse_property(out, item, proptype, schema.items, value_where, name, namespace, current_ns, prefix, single_attribute) end return out end