Skip to content

Commit be6bded

Browse files
committed
Fixed xml table generation
1 parent 5bf423a commit be6bded

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

luaxmlgenerator-0.2.2-1.rockspec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package = "LuaXMLGenerator"
2+
version = "0.2.2-1"
3+
source = {
4+
url = "git+https://github.com/Frityet/LuaXMLGenerator",
5+
tag = "0.2.2"
6+
}
7+
description = {
8+
summary = "DSL to generate XML/HTML",
9+
homepage = "https://github.com/Frityet/LuaXMLGenerator",
10+
license = "MIT"
11+
}
12+
dependencies = {
13+
"lua >= 5.1, < 5.5"
14+
}
15+
build = {
16+
type = "builtin",
17+
modules = {
18+
["xml-generator"] = "xml-generator.lua"
19+
}
20+
}

xml-generator.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ end
9393

9494
---@type XML.GeneratorTable
9595
export.generator_metatable = setmetatable({}, {
96-
---@param self XML.GeneratorTable
96+
---@param _ XML.GeneratorTable
9797
---@param tag_name string
98-
__index = function(self, tag_name)
98+
__index = function(_, tag_name)
9999
---@param attributes { [string] : string, [integer] : (XML.Node | string | fun(): XML.Node) } | string
100100
---@return table | fun(children: (XML.Node | string | fun(): XML.Node)[]): XML.Node
101101
return function(attributes)
@@ -107,19 +107,21 @@ export.generator_metatable = setmetatable({}, {
107107
}
108108

109109
--if we have a situation such as
110-
--[[
111-
tag "string"
112-
]]
110+
---```lua
111+
---tag "string"
112+
---```
113113
--
114114
--then the content is the `string`
115115
local tname = typename(attributes)
116-
if tname ~= "table" and tname ~= "HTML.Node" then
116+
if tname ~= "table" and tname ~= "XML.Node" then
117117
node.attributes = attributes and { tostring(attributes) } or {}
118118
elseif tname == "XML.Node" then
119+
120+
---```lua
119121
---local tag = div { p "hi" }
120122
---div(tag)
123+
---```
121124
node.children = { attributes }
122-
attributes = {}
123125
else
124126
node.attributes = attributes --[[@as any]]
125127
end
@@ -210,7 +212,10 @@ function export.html_table(tbl)
210212
return xml.table {
211213
function ()
212214
local function getval(v)
213-
if typename(v) ~= "table" and (typename(v) ~= "XML.Node" and (getmetatable(v) or {}).__tostring ~= nil) then
215+
local tname = typename(v)
216+
if tname == "XML.Node" then return v end
217+
218+
if typename(v) ~= "table" or (getmetatable(v) or {}).__tostring then
214219
return tostring(v)
215220
end
216221

0 commit comments

Comments
 (0)