Module:Test: Difference between revisions
From roblox chads wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local capiunto = require 'capiunto' | local capiunto = require 'capiunto' | ||
| Line 4: | Line 5: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | |||
local headerStyle | |||
if args.headerstyle and args.headerstyle ~= '' then | |||
headerStyle = string.format('background-color:%s;', args.headerstyle) | |||
else | |||
headerStyle = 'background-color:#a1dbff;' | |||
end | |||
local retval = capiunto.create({ | |||
title = args.title, | |||
headerStyle = headerStyle, | |||
for i,v in pairs(args) do | }):addImage(args.image, args.caption) | ||
local entries = {} | |||
elseif | |||
for i, v in pairs(args) do | |||
local key = tostring(i) | |||
if key:sub(-6) == "header" then | |||
table.insert(entries, { | |||
key = key, | |||
value = v, | |||
type = "header" | |||
}) | |||
elseif key:sub(-3) == "row" then | |||
table.insert(entries, { | |||
key = key, | |||
value = v, | |||
type = "row" | |||
}) | |||
end | end | ||
end | end | ||
table.sort(entries, function(a, b) | |||
local anum = tonumber(a.key:match("^(%d+)")) or math.huge | |||
local bnum = tonumber(b.key:match("^(%d+)")) or math.huge | |||
if anum ~= bnum then | |||
return anum < bnum | |||
end | |||
return a.key < b.key | |||
end) | |||
for _, entry in ipairs(entries) do | |||
if entry.type == "header" then | |||
retval:addHeader(entry.value) | |||
else | |||
local label = entry.key:sub(1,-4) | |||
retval:addRow(label, entry.value) | |||
end | |||
end | |||
return retval | |||
end | end | ||
return p | return p | ||
Revision as of 14:56, 2 November 2026
Documentation for this module may be created at Module:Test/doc
local capiunto = require 'capiunto'
local p = {}
function p.main(frame)
local args = frame:getParent().args
local headerStyle
if args.headerstyle and args.headerstyle ~= '' then
headerStyle = string.format('background-color:%s;', args.headerstyle)
else
headerStyle = 'background-color:#a1dbff;'
end
local retval = capiunto.create({
title = args.title,
headerStyle = headerStyle,
}):addImage(args.image, args.caption)
local entries = {}
for i, v in pairs(args) do
local key = tostring(i)
if key:sub(-6) == "header" then
table.insert(entries, {
key = key,
value = v,
type = "header"
})
elseif key:sub(-3) == "row" then
table.insert(entries, {
key = key,
value = v,
type = "row"
})
end
end
table.sort(entries, function(a, b)
local anum = tonumber(a.key:match("^(%d+)")) or math.huge
local bnum = tonumber(b.key:match("^(%d+)")) or math.huge
if anum ~= bnum then
return anum < bnum
end
return a.key < b.key
end)
for _, entry in ipairs(entries) do
if entry.type == "header" then
retval:addHeader(entry.value)
else
local label = entry.key:sub(1,-4)
retval:addRow(label, entry.value)
end
end
return retval
end
return p