Documentation for this module may be created at Module:Cheerful carnival/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
local team_names = {
args['team1'],
args['team2']
}
local team_images = {
[args['team1'] or 'Team 1'] = args['team1 image'],
[args['team2'] or 'Team 2'] = args['team2 image']
}
local function formatName(team_name)
if team_name and team_name ~= '' then
return 'Team ' .. team_name
end
return nil
end
local function formatImage(team_name)
if team_name and team_name ~= '' then
local team_image = team_images[team_name]
if team_image and team_image ~= '' then
return string.format(
'[[File:%s|100px]]',
team_image
)
end
end
return nil
end
local function formatNameImage(team_name)
local _team_name = formatName(team_name)
local _team_image = formatImage(team_name)
if _team_name and _team_image then
return _team_image .. '<br>' .. _team_name
elseif _team_name then
return _team_name
end
return 'TBA'
end
local function formatPoints(points)
if points then
return points .. ' pts'
end
return nil
end
local root = mw.html.create('table')
:addClass('wikitable')
:css({
['text-align'] = 'center'
})
:tag('tr')
:tag('th')
:css({
['width'] = '33%',
['padding'] = '10px'
})
:wikitext('Theme')
:done()
:tag('td')
:css({
['width'] = '66%'
})
:attr('colspan', 2)
:wikitext(args['theme'] or 'TBA')
:done()
:done()
:tag('tr')
:tag('th')
:css({
['padding'] = '10px',
['height'] = '150px'
})
:wikitext('Teams')
:done()
:tag('td')
:css({ ['width'] = '33%' })
:wikitext(formatNameImage(team_names[1]))
:done()
:tag('td')
:css({ ['width'] = '33%' })
:wikitext(formatNameImage(team_names[2]))
:done()
:done()
:tag('tr')
:tag('td'):attr('colspan', 3):done()
:done()
:tag('tr')
:tag('th')
:attr('colspan', 3)
:css({ ['padding'] = '10px' })
:wikitext('Winner')
:done()
:done()
:tag('tr')
:tag('th')
:css({ ['padding'] = '10px' })
:wikitext('First Midterm')
:done()
:tag('tr')
:css({ ['padding'] = '10px' })
:wikitext('Second Midterm')
:done()
:tag('tr')
:css({ ['padding'] = '10px' })
:wikitext('Final')
:done()
:done()
:tag('tr')
:tag('td')
:attr('height', '150px')
:wikitext(formatImage(args['winner1']) or 'TBA')
:done()
:tag('td')
:attr('height', '150px')
:wikitext(formatImage(args['winner2']) or 'TBA')
:done()
:tag('td')
:attr('height', '150px')
:wikitext(formatImage(args['winner3']) or 'TBA')
:done()
:tag('tr')
:tag('td'):attr('colspan', 3):done()
:done()
:tag('tr')
:tag('td')
:attr('colspan', 3)
:css({ ['padding'] = '10px' })
:wikitext('Final Point Result')
:done()
:done()
:tag('tr')
:tag('th')
:css({ ['padding'] = '10px' })
:wikitext(formatName(team_names[1]) or 'TBA')
:done()
:tag('td')
:attr('colspan', 2)
:wikitext(formatPoints(args['team1 points']) or 'TBA')
:done()
:done()
:tag('tr')
:tag('th')
:css({ ['padding'] = '10px' })
:wikitext(formatName(team_names[2]) or 'TBA')
:done()
:tag('td')
:attr('colspan', 2)
:wikitext(formatPoints(args['team2 points']) or 'TBA')
:done()
:done()
:done()
return tostring(root)
end
return p