Module:TableGenerator

Revision as of 02:36, 14 September 2024 by Sur (talk | contribs) (test)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:TableGenerator/doc

local p = {}

function p.generateTable(frame)
    local args = frame:getParent().args
    local output = {}
    local row = {}

    for i = 1, #args / 2 do
        local statName = args['stat_name' .. i]
        local statValue = args['stat_value' .. i]

        if statName and statValue then
            table.insert(row, '<td>' .. statName .. ' ' .. statValue .. '</td>')
            
            -- Every 3rd entry creates a new row
            if #row == 3 then
                table.insert(output, '<tr>' .. table.concat(row) .. '</tr>')
                row = {}  -- Clear row for next set of values
            end
        end
    end

    -- Handle remaining cells (if not divisible by 3)
    if #row > 0 then
        while #row < 3 do
            table.insert(row, '<td></td>')  -- Fill remaining cells with empty
        end
        table.insert(output, '<tr>' .. table.concat(row) .. '</tr>')
    end

    return table.concat(output)
end

return p