Module:Rugby box
| This Lua module is used on approximately 3,600 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module is currently under extended confirmed protection. Extended confirmed protection prevents edits from all unregistered editors and registered users with fewer than 30 days tenure and 500 edits. The policy on community use specifies that extended confirmed protection can be applied to combat disruption, if semi-protection has proven to be ineffective. Extended confirmed protection may also be applied to enforce arbitration sanctions. Please discuss any changes on the talk page; you may submit an edit request to ask for uncontroversial changes supported by consensus. |
Usage
See {{rugbybox}}
-- Implements [[Template:rugby box]]
local p = {}
local eventschema = "http://schema.org/SportsEvent"
local labels = {
['aet'] = '[[Overtime (sports)#Rugby union|a.e.t.]]',
['penalties'] = '[[Penalty shootout#Rugby union|Penalties]]',
['attendance'] = 'Attendance:',
['referee'] = 'Referee:',
['try'] = 'Try:',
['con'] = 'Con:',
['pen'] = 'Pen:',
['drop'] = 'Drop:',
['gfm'] = 'Goal from mark:',
['cards'] = 'Cards:'
}
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 nil
end
local function getid(s)
s = trim(s or '')
if s and s ~= '' then
return s
end
return nil
end
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({'date', 'time', 'round'}) 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, '<br/>'))
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 = {args['homescore'] or '', args['awayscore'] or ''}
for k = 1,2 do
if score[k] == '' then
local vals = {}
for _, v in pairs({'try', 'con', 'pen', 'drop', 'gfm', 'cards'}) do
if args[v .. k] then
table.insert(vals, '\'\'\'' .. labels[v] .. '\'\'\' ' .. args[v .. k])
end
end
score[k] = table.concat(vals, '<br />')
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, '<span class="location">' .. args['stadium'] .. '</span>')
end
if args['attendance'] then
table.insert(extra, labels['attendance'] .. ' ' .. args['attendance'])
end
if args['referee'] then
table.insert(extra, labels['referee'] .. ' <span class="attendee">' .. args['referee'] .. '</span>')
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, '<br/>'))
root:tag('div'):css('clear', 'both')
local check = require('Module:Check for unknown parameters')._check
local tracking = check({
['unknown']='[[Category:Pages using Rugby box with unknown parameters|_VALUE_ ]]',
['preview']='Page using [[Template:Rugbybox]] with unknown parameter "_VALUE_"',
['ignoreblank']='y',
'aet', 'attendance', 'away', 'awayscore', 'bg', 'cards1', 'cards2',
'con1', 'con2', 'cw1', 'cw2', 'cw3', 'date', 'drop1', 'drop2',
'gfm1', 'gfm2', 'home', 'homescore', 'id', 'noaway', 'nohome',
'pen1', 'pen2', 'penalties1', 'penalties2', 'penaltyscore',
'referee', 'report', 'round', 'score', 'size', 'stadium',
'team1', 'team2', 'time', 'try1', 'try2'
}, frame:getParent().args)
return tostring(root) .. tracking
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.