Module:DynamicTable

From TwogPedia
Revision as of 13:02, 16 May 2023 by Couchor (talk | contribs)

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

local getArgs = require('Module:Arguments').getArgs

local DynamicTable = {}

function DynamicTable.main(frame)
	local args = getArgs(frame)

	local tableContainer = mw.html.create('table'):addClass('wikitable')
	if ( args.columns ) then
	local split = mw.text.split(args.columns, ',')
	local headerRow = mw.html.create('tr')
	for i = 1, #split do
		local th = mw.html.create('th'):wikitext(mw.text.trim(split[i]))
		headerRow:node(th)
	end
    tableContainer:node(headerRow)
    end

	tableContainer:node(args.rows)
	return tableContainer
end

function DynamicTable.row(frame)
	local args = getArgs(frame)

	local split = mw.text.split(args[1], ',')
	local row = mw.html.create('tr')
	
	for i = 1, #split do
		local td = mw.html.create('td'):wikitext(mw.text.trim(split[i]))
		row:node(td)
	end
	
	return row
end

return DynamicTable