summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-05-22 12:49:14 -0500
committersanine <sanine.not@pm.me>2022-05-22 12:49:14 -0500
commit7e61cd41cca9a8915b346a79d658bab4829d8ff1 (patch)
treeef9185c8738e21f9fe54bf91c2f504b9e80cefa9
parentfc4a406371fdf130d6f0db02d3a2e09112686b9f (diff)
allow adding children via marigold.h
-rw-r--r--marigold.lua5
-rwxr-xr-xtest.lua21
2 files changed, 26 insertions, 0 deletions
diff --git a/marigold.lua b/marigold.lua
index c95ecb5..3ed0f59 100644
--- a/marigold.lua
+++ b/marigold.lua
@@ -63,6 +63,11 @@ marigold.h = function(tag_type, content, tbl)
tag.content = content
tag.attributes = {}
tag.children = {}
+ if tbl then
+ for _, child in ipairs(tbl) do
+ table.insert(tag.children, child)
+ end
+ end
return tag
end
diff --git a/test.lua b/test.lua
index 81d5d77..2a733a1 100755
--- a/test.lua
+++ b/test.lua
@@ -64,3 +64,24 @@ test("marigold.h produces a correct basic tag", function()
end
assert(#(h1.children) == 0)
end)
+
+
+test("marigold.h correctly adds children", function()
+ local h = marigold.h
+ local div = h('div', "some stuff", {
+ h('p', "the first paragraph"),
+ h('p', "the second paragraph"),
+ })
+
+ assert(div.tag == 'div')
+ assert(div.content == "some stuff")
+ -- still should have nothing in the attributes table
+ for k, v in ipairs(div.attributes) do
+ assert(false, string.format("%s, %s", tostring(k), tostring(v)))
+ end
+ assert(#div.children == 2)
+ assert(div.children[1].tag == 'p')
+ assert(div.children[1].content == 'the first paragraph')
+ assert(div.children[2].tag == 'p')
+ assert(div.children[2].content == 'the second paragraph')
+end)