Jump to content

Module:SongContestTable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheThomanski (talk | contribs) at 23:05, 17 March 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
local order = require('Module:SongContestData')._order

local rowTemplate = "SongContestTableRow"

local p = {}

function p.main(f)
	local args = getArgs(f)
	local contest, year, roundInput, wikitable = args[1], args[2], args[3], args['table']
	local round, roundNo = roundInput:gsub("%d+", ""), tonumber(roundInput:match("%d+"))
	
	local sorting = round..'_draw'
	local ordered = {}
	if roundNo then
		ordered = order({contest, year, sorting, desc=false, excludeAtt=round, excludeVal=roundNo, excludeInvert=true})
	else
		ordered = order({contest, year, sorting, desc=false})
	end
	
	-- build table from template
	local result = f:expandTemplate{title=rowTemplate,args={contest, year, roundInput, ['table'] = wikitable, header=1}}
	for _,entry in pairs(ordered) do
		result = result ..'\n'.. f:expandTemplate{title=rowTemplate,args={contest, year, entry, round, ['table'] = wikitable}}
	end
	return result..'\n|}'
end

return p