summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-05-22 12:52:41 -0500
committersanine <sanine.not@pm.me>2022-05-22 12:52:41 -0500
commit825194d0e5a1c16d3c3170a90a9a2679146044a7 (patch)
tree065ddca8a8ce34ea15f4fd01f0d74db95a029bb6
parent7e61cd41cca9a8915b346a79d658bab4829d8ff1 (diff)
allow ignoring the content field in marigold.h
-rw-r--r--marigold.lua5
-rwxr-xr-xtest.lua22
2 files changed, 27 insertions, 0 deletions
diff --git a/marigold.lua b/marigold.lua
index 3ed0f59..16aa054 100644
--- a/marigold.lua
+++ b/marigold.lua
@@ -58,6 +58,11 @@ end
marigold.h = function(tag_type, content, tbl)
+ if type(content) == 'table' and tbl == nil then
+ tbl = content
+ content = ''
+ end
+
local tag = {}
tag.tag = tag_type
tag.content = content
diff --git a/test.lua b/test.lua
index 2a733a1..17aa46d 100755
--- a/test.lua
+++ b/test.lua
@@ -85,3 +85,25 @@ test("marigold.h correctly adds children", function()
assert(div.children[2].tag == 'p')
assert(div.children[2].content == 'the second paragraph')
end)
+
+
+test("marigold.h correctly ignores missing content", function()
+ local h = marigold.h
+ local div = h('div', {
+ h('p', "the first paragraph"),
+ h('p', "the second paragraph"),
+ })
+
+ assert(div.tag == 'div')
+ assert(div.content == "")
+ -- 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)