Module:Rugby box explained

-- Implements local p = local eventschema = "http://schema.org/SportsEvent"local labels =

local function isnotempty(s) return s and s:match('^%s*(.-)%s*$') ~= end

local function trim(s) if isnotempty(s) then s = s:match('^[\'"%s]*(.-)[\'"%s]*$') return isnotempty(s) and s or nil end return nilend

local function getid(s) s = trim(s or ) if s and s ~= then return s end return nilend

function p.main(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) local id = getid(args['id']) -- start box local root = mw.html.create('div') :attr('itemscope', ) :attr('itemtype', eventschema) :css('width', args['size'] or '100%') :css('background-color', args['bg']) :addClass('vevent summary') :attr('id', id) -- date/time/round local dtr = for _, v in pairs do if args[v] then table.insert(dtr, args[v]) end end root:tag('table') :css('float', 'left') :css('width', args['cw1'] or '15%') :css('table-layout', 'fixed') :tag('tr') :tag('td') :css('text-align', 'right') :wikitext(table.concat(dtr, '
')) local block = root:tag('table') :css('float', 'left') :css('width', args['cw2'] or '61%') :css('table-layout', 'fixed') :css('text-align', 'center')

local row = block:tag('tr') :css('vertical-align', 'top') :css('font-weight', 'bold') row:tag('td') :css('width', '39%') :css('text-align', 'right') :addClass('vcard') :tag('span') :addClass('fn org') :wikitext(args['team1'] or args['home'] or args['nohome']) row:tag('td') :css('width', '22%') :wikitext(args['score'] or 'v') :wikitext(args['aet'] and ' (' .. labels['aet'] .. ')' or nil) row:tag('td') :css('width', '39%') :css('text-align', 'left') :addClass('vcard') :tag('span') :addClass('fn org') :wikitext(args['team2'] or args['away'] or args['noaway'])

row = block:tag('tr') :css('font-size', '85%') :css('vertical-align', 'top') local score = for k = 1,2 do if score[k]

then local vals = for _, v in pairs do if args[v .. k] then table.insert(vals, '\'\'\ .. labels[v] .. '\'\'\' ' .. args[v .. k]) end end score[k] = table.concat(vals, '
') end end row:tag('td'):css('text-align', 'right'):wikitext(score[1]) row:tag('td'):wikitext(args['report']) row:tag('td'):css('text-align', 'left'):wikitext(score[2]) if args['penaltyscore'] then row = block:tag('tr') row:tag('th') row:tag('th'):wikitext(labels['penalties']) row:tag('th') row = block:tag('tr') :css('font-size', '85%') :css('vertical-align', 'top') row:tag('td'):css('text-align','right'):wikitext(args['penalties1']) row:tag('td'):css('font-weight','bold'):wikitext(args['penaltyscore']) row:tag('td'):css('text-align','left'):wikitext(args['penalties2']) end -- stadium/attendance/referee local extra = if args['stadium'] then table.insert(extra, '

' .. args['stadium'] .. '') end if args['attendance'] then table.insert(extra, labels['attendance'] .. ' ' .. args['attendance']) end if args['referee'] then table.insert(extra, labels['referee'] .. ' ' .. args['referee'] .. '') end root:tag('table') :css('float', 'left') :css('width', args['cw3'] or '24%') :css('table-layout', 'fixed') :tag('tr') :tag('td') :css('font-size', '85%') :wikitext(table.concat(extra, '
')) root:tag('div'):css('clear', 'both') local check = require('Module:Check for unknown parameters')._check local tracking = check(frame:getParent.args) return tostring(root) .. trackingend

return p