Module:TableGenerator: Difference between revisions

Sur (talk | contribs)
m Blanked the page
Tag: Blanking
Sur (talk | contribs)
mNo edit summary
Line 1: Line 1:
local p = {}


function p.generateTable(frame)
    local args = frame:getParent().args
    local cols = tonumber(args["cols"]) or 1  -- Default to 1 column if no value is passed
    local output = {}
    local row = {}
   
    table.insert(output, '{| class="wikitable"')  -- Start of the table
   
    for i, v in ipairs(args) do
        -- Add the value to the current row
        table.insert(row, string.format('| %s', v))
        -- If we have enough columns, close the row and add it to the output
        if #row == cols then
            table.insert(output, '|-\n' .. table.concat(row, ' || '))
            row = {}  -- Reset the row
        end
    end
    -- Add any remaining data (in case the last row is incomplete)
    if #row > 0 then
        table.insert(output, '|-\n' .. table.concat(row, ' || '))
    end
   
    table.insert(output, '|}')  -- End of the table
   
    return table.concat(output, '\n')
end
return p