Jump to content

Module:SongContestTable

From Wikipedia, the free encyclopedia

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
	if roundInput then
		round, roundNo = roundInput:gsub("%d+", ""), tonumber(roundInput:match("%d+"))
	end
	
	local sorting
	if round then
		sorting = round..'_draw'
	end
	
	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