Editing Module:TableGeneratorGive feedback
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
local p = {} | 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 = {} | |||
function p. | |||
local args = frame.args | |||
local cols = tonumber(args[ | |||
local | |||
local | |||
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 | end | ||
-- Add any remaining data (in case the last row is incomplete) | |||
if #row > 0 then | |||
table.insert(output, '|-\n' .. table.concat(row, ' || ')) | |||
end | end | ||
-- | table.insert(output, '|}') -- End of the table | ||
return table.concat(output, '\n') | |||
end | end | ||
return p | return p | ||