Module:RoundN

This is an old revision of this page, as edited by Codehydro (talk | contribs) at 05:24, 25 December 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local defaultRounds = {'Quarter Finals' , 'Semi Finals', 'Finals'}
local output = mw.html.create('table')
local last = {row = nil, cell = nil}

function newRow()
	last.row = output:tag('tr')
	last.cell = last.row:tag('td')
	last.cell:attr('height', 5)
end

function spacer(width)
	last.row:tag('td')
		:attr('width', width)
		:wikitext(' ')
end

function p._main(args, frame)
	output
		:css('font-size', '90%')
		:css('margin', '1em 2em 1em 1em')
		:css('border-spacing', 0)
		:css('border', 0)
		:css('padding', 0)
	for k = 1, args.columns do
		if k == 1 then
			newRow()
		else
			last.row:tag('td'):attr('colspan', 2)
		end
		last.row:tag('td')
			:attr('colspan', 2)
			:css('text-align', 'center')
			:css('border', '1px solid #aaa')
			:css('background-color', '#f2f2f2')
			:wikitext(
				args['RD' .. k] or
				defaultRounds[k - 1] or
				('Round of ' .. math.pow(2, args.columns - k + 1))
			)
	end
	for k = 1, args.columns do
		if k == 1 then
			newRow()
		else
			spacer(15)
			spacer(20)
		end
		spacer(170)
		spacer(args.wiidescores and 40 or 30)
	end
	output = tostring(output)
	for k, v in pairs(args) do
		if type(k) == type(1) then
			output = output .. k .. ' '
		end
	end
	return output
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = WRAPPER_TEMPLATE
	})
	return p._main(args, frame)
end

return p