Skip to content

Commit 135ce0b

Browse files
committed
Use export.generate_node instead of passing param
1 parent d9204c9 commit 135ce0b

File tree

3 files changed

+69
-30
lines changed

3 files changed

+69
-30
lines changed

luaxmlgenerator-0.2.0-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.0-1"
3+
source = {
4+
url = "git+https://github.com/Frityet/LuaXMLGenerator",
5+
tag = "0.2.0"
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+
}

luaxmlgenerator-0.2.1-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.1-1"
3+
source = {
4+
url = "git+https://github.com/Frityet/LuaXMLGenerator",
5+
tag = "0.2.1"
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: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export.generator_metatable = setmetatable({}, {
110110
--[[
111111
tag "string"
112112
]]
113-
--
113+
--
114114
--then the content is the `string`
115115
local tname = typename(attributes)
116116
if tname ~= "table" and tname ~= "HTML.Node" then
@@ -198,42 +198,41 @@ function export.generate_node(ctx) return ctx(export.generator_metatable) end
198198
function export.generate(ctx) return tostring(export.generate_node(ctx)) end
199199

200200
---Turns a lua table into an html table, recursively, with multiple levels of nesting
201-
---@param xml XML.GeneratorTable
202201
---@param tbl table
203202
---@return XML.Node
204-
function export.html_table(xml, tbl)
205-
---@diagnostic disable: undefined-global
206-
return xml.table {
207-
function()
208-
local function getval(v)
209-
if type(v) ~= "table" or (getmetatable(v) or {}).__tostring then
210-
return tostring(v)
203+
function export.html_table(tbl)
204+
return export.generate_node(function(xml)
205+
return xml.table {
206+
function()
207+
local function getval(v)
208+
if type(v) ~= "table" or (getmetatable(v) or {}).__tostring then
209+
return tostring(v)
210+
end
211+
return export.html_table(v)
211212
end
212-
return export.html_table(xml, v)
213-
end
214213

215-
for i, v in ipairs(tbl) do
216-
coroutine.yield (
217-
xml.tr {
218-
xml.td(tostring(i)),
219-
xml.td(getval(v)),
220-
}
221-
)
214+
for i, v in ipairs(tbl) do
215+
coroutine.yield(
216+
xml.tr {
217+
xml.td(tostring(i)),
218+
xml.td(getval(v)),
219+
}
220+
)
222221

223-
tbl[i] = nil
224-
end
222+
tbl[i] = nil
223+
end
225224

226-
for k, v in pairs(tbl) do
227-
coroutine.yield (
228-
xml.tr {
229-
xml.td(tostring(k)),
230-
xml.td(getval(v)),
231-
}
232-
)
225+
for k, v in pairs(tbl) do
226+
coroutine.yield(
227+
xml.tr {
228+
xml.td(tostring(k)),
229+
xml.td(getval(v)),
230+
}
231+
)
232+
end
233233
end
234-
end
235-
}
236-
---@diagnostic enable: undefined-global
234+
}
235+
end)
237236
end
238237

239238
---@alias OptionalStringCollection string | string[]

0 commit comments

Comments
 (0)