Module:Test

From roblox chads wiki
Revision as of 14:56, 2 November 2026 by Swobodap (talk | contribs)
Jump to navigationJump to search

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