Modul:Ice hockey box
Megjelenés
Ice hockey box[mi ez?] • [dokumentáció: mutat, ] • [tesztek: létrehozás]
-- implements [[template:IceHockeybox]]
local p = {}
local errorcats = ''
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
local function mysplit(s)
-- Change <br> tags to slashes
s = mw.ustring.gsub(s or '', '<[\/%s]*[Bb][Rr][^<>]*>', ' / ')
s = mw.ustring.gsub(s or '', '[%s]* /[%s]*', ' / ')
s = mw.ustring.gsub(s or '', '[%s]*/ [%s]*', ' / ')
-- Split into a table
s = mw.text.split(s .. ' / ', ' / ')
-- Remove empty rows
local t = {}
for k=1,#s do
if isnotempty(s[k]) then
table.insert(t, s[k])
end
end
return t
end
local function scoringtable(g1, g2, p)
local root = ''
-- If there is no progression then do a very simple format
if (not isnotempty(p)) and (isnotempty(g1) or isnotempty(g2)) then
root = mw.html.create('table')
root
:attr('cellspacing', '0')
:css('width', '100%')
local row = root:tag('tr'):css('text-align','top')
row:tag('td')
:css('text-align','right')
:css('width', '39%')
:wikitext(g1 or '')
row:tag('td')
:css('text-align','center')
:css('width', '22%')
:tag('i'):wikitext('Gólok')
row:tag('td')
:css('text-align','left')
:css('width', '39%')
:wikitext(g2 or '')
return tostring(root)
end
-- Split into tables
local gt1 = mysplit(g1)
local gt2 = mysplit(g2)
local pt = mysplit(p)
-- Align goals with scores in progression
local score1, score2 = 0, 0
for k = 1,#pt do
local s1 = tonumber(mw.ustring.gsub(pt[k] or '', '^[%s]*([0-9][0-9]*)[^0-9][^0-9]*([0-9][0-9]*)[%s]*$', '%1') or '-1') or -1
local s2 = tonumber(mw.ustring.gsub(pt[k] or '', '^[%s]*([0-9][0-9]*)[^0-9][^0-9]*([0-9][0-9]*)[%s]*$', '%2') or '-1') or -1
if s1 == (score1 + 1) and s2 == score2 then
score1 = s1
table.insert(gt2, k, '')
elseif s2 == (score2 + 1) and s1 == score1 then
score2 = s2
table.insert(gt1, k, '')
else
errorcats = errorcats .. '[[Category:Jégkorongbox nem megfelelő formázással]]'
errorcats = errorcats .. 'Error: Goals/Progression mismatch: S1 = ' .. s1 .. ' S2 = ' .. s2 .. ' GT1 = ' .. (gt1[k] or '') .. ' GT2 = ' .. (gt2[k] or '') .. '<br>'
end
end
if not (#gt1 == #pt) or not(#gt2 == #pt) then
errorcats = errorcats .. '[[Category:Jégkorongbox nem megfelelő formázással]]'
errorcats = errorcats .. 'Error: Goals/Progression mismatch: N1 = ' .. #gt1 .. ' N2 = ' .. #gt2 .. ' PN = ' .. #pt .. '<br>'
end
-- Now build the score table
for k=1,#pt do
if k == 1 then
root = mw.html.create('table')
root
:attr('cellspacing', '0')
:css('width', '100%')
end
local row = root:tag('tr'):css('text-align','top')
row:tag('td')
:css('text-align','right')
:css('width', '39%')
:wikitext(gt1[k] or '')
row:tag('td')
:css('text-align','center')
:css('width', '22%')
:wikitext(pt[k] or '')
row:tag('td')
:css('text-align','left')
:css('width', '39%')
:wikitext(gt2[k] or '')
end
return tostring(root)
end
function p.box( frame )
local args = frame:getParent().args
local res = ''
local id = args['id']
id = id ~= nil and mw.ustring.gsub(id,'^"(.-)"$', '%1') or nil
local root = mw.html.create('table')
root
:attr('cellspacing', '0')
:attr('id', id )
:css('width', '100%')
:css('background-color', args['háttér'] )
:addClass('vevent')
local row = root:tag('tr'):css('vertical-align', 'top'):addClass('summary')
-- Date and time
local cell = row:tag('td')
:css('width', '15%')
:css('text-align', 'center')
:css('font-size', '100%')
cell:wikitext(args['dátum'] or '')
cell:wikitext(isnotempty(args['időpont']) and '<br>' .. args['időpont'] or '')
-- Team 1
cell = row:tag('td')
:css('width', '25%')
:css('text-align', 'right')
:addClass('vcard attendee')
cell:tag('span')
cell:tag('b'):addClass('fn org'):wikitext(args['csapat1'] or '')
-- Score
cell = row:tag('td')
:css('width', '15%')
:css('text-align', 'center')
if isnotempty(args['végeredmény']) then
cell:tag('b'):wikitext(args['végeredmény'])
if isnotempty(args['hosszabbítás']) then cell:wikitext(' ') cell:tag('abbr'):attr('title', 'hosszabbítás után'):wikitext('(h.u.)') else end
if isnotempty(args['szétlövés']) then cell:wikitext(' ') cell:tag('abbr'):attr('title', 'szétlövéssel'):wikitext('(sz.)') else end
else
cell:tag('abbr'):attr('title', 'versus'):css('text-decoration', 'none'):wikitext('–')
end
if isnotempty(args['harmadok']) then
cell:wikitext('<br>')
cell:tag('small'):wikitext(args['harmadok'])
end
-- Team 2
cell = row:tag('td')
:css('width', '25%')
:css('text-align', 'left')
:addClass('vcard attendee')
cell:tag('span')
cell:tag('b'):addClass('fn org'):wikitext(args['csapat2'] or '')
-- Stadium and attendance
cell = row:tag('td')
:css('font-size', '85%')
if isnotempty(args['helyszín']) then
cell:tag('span'):addClass('location'):wikitext(args['helyszín'])
end
if isnotempty(args['nézőszám']) then
cell:wikitext('<br>')
cell:tag('b'):wikitext('Nézőszám:')
cell:wikitext(' ' .. args['nézőszám'])
end
res = res .. tostring(root)
if isnotempty(args['végeredmény']) then
root = mw.html.create('table')
root
:addClass('collapsible collapsed')
:attr('cellspacing', '0')
:css('width', '100%')
:css('background-color', args['háttér'] )
cell = root:tag('tr'):tag('th')
cell:attr('colspan', '5')
:css('style', 'text-align', 'center')
:css('font-size', '85%')
if isnotempty(args['jegyzőkönyv']) then
cell:tag('b'):wikitext('[' .. args['jegyzőkönyv'] .. ' Jegyzőkönyv]')
end
-- Empty spacing
row = root:tag('tr'):css('font-size', '85%')
cell = row:tag('td')
:attr('rowspan', '7')
:css('width', '15%')
:css('vertical-align', 'top')
-- Goalies
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'right')
:wikitext(args['kapus1'] or '')
cell = row:tag('td')
:css('width', '15%')
:css('vertical-align', 'top')
:css('text-align', 'center')
if isnotempty(args['kapus1']) or isnotempty(args['kapus2']) then
cell:tag('i'):wikitext('Kapusok')
end
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'left')
:wikitext(args['kapus2'] or '')
-- Officials and linesmen
cell = row:tag('td')
:attr('rowspan', '7')
:css('vertical-align', 'top')
if isnotempty(args['bíró1']) then
if isnotempty(args['bíró2']) then
cell:tag('i'):wikitext('Játékvezetők:')
cell:wikitext('<br>' .. args['bíró1'] .. '<br>' .. args['bíró2'])
else
cell:tag('i'):wikitext('Játékvezető:')
cell:wikitext('<br>' .. args['bíró1'])
end
end
if isnotempty(args['vonalbíró1']) then
cell:wikitext('<br>')
if isnotempty(args['vonalbíró2']) then
cell:tag('i'):wikitext('Vonalbírók:')
cell:wikitext('<br>' .. args['vonalbíró1'] .. '<br>' .. args['vonalbíró2'])
else
cell:tag('i'):wikitext('Vonalbíró:')
cell:wikitext('<br>' .. args['vonalbíró1'])
end
end
-- Goals and progression
row = root:tag('tr'):css('font-size', '85%')
cell = row:tag('td')
:attr('colspan', '3')
:css('width', '65%')
:wikitext(
scoringtable(args['gólszerzők1'] or '',
args['gólszerzők2'] or '',
args['eredményváltozás'] or '')
)
if isnotempty(args['pnote']) then
row = root:tag('tr'):css('font-size', '85%')
row:tag('td')
:attr('colspan', '3')
:css('text-align','center')
:css('width', '65%')
:wikitext(args['pnote'])
end
-- Shoot out
if isnotempty(args['szétlövés1']) or isnotempty(args['szétlövés2']) then
soshots1 = table.concat(mysplit(args['szétlövés1'] or ''), '<br>')
soshots2 = table.concat(mysplit(args['szétlövés2'] or ''), '<br>')
row = root:tag('tr'):css('font-size', '85%')
row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'right')
:wikitext(soshots1 or '')
row:tag('td')
:css('width', '15%')
:css('vertical-align', 'top')
:css('text-align', 'center')
:tag('i'):wikitext('Szétlövés')
row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'left')
:wikitext(soshots2 or '')
end
if isnotempty(args['sonote']) then
row = root:tag('tr'):css('font-size', '85%')
row:tag('td')
:attr('colspan', '3')
:css('text-align', 'center')
:css('width', '65%')
:wikitext(args['sonote'])
end
-- Second leg overtime
if isnotempty(args['otgoals1']) or isnotempty(args['otgoals2'])
or isnotempty(args['otprogression']) then
row = root:tag('tr'):css('font-size', '85%')
cell = row:tag('td')
:attr('colspan', '3')
:css('width', '65%')
:wikitext(
scoringtable(args['otgoals1'] or '',
args['otgoals2'] or '',
args['otprogression'] or '')
)
end
if isnotempty(args['otnote']) then
row = root:tag('tr'):css('font-size', '85%')
row:tag('td')
:attr('colspan', '3')
:css('text-align','center')
:css('width', '65%')
:wikitext(args['otnote'])
end
-- Penalties
row = root:tag('tr'):css('font-size', '85%')
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'right')
if isnotempty(args['büntetések1']) then
cell:tag('i'):wikitext(args['büntetések1'] .. ' perc')
end
cell = row:tag('td')
:css('width', '15%')
:css('vertical-align', 'top')
:css('text-align', 'center')
if isnotempty(args['büntetések1']) or isnotempty(args['büntetések2']) then
cell:tag('i'):wikitext('Büntetések')
end
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'left')
if isnotempty(args['büntetések2']) then
cell:tag('i'):wikitext(args['büntetések2'] .. ' perc')
end
-- Shots
row = root:tag('tr'):css('font-size', '85%')
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'right')
if isnotempty(args['lövések1']) then
cell:tag('i'):wikitext(args['lövések1'])
end
cell = row:tag('td')
:css('width', '15%')
:css('vertical-align', 'top')
:css('text-align', 'center')
if isnotempty(args['lövések1']) or isnotempty(args['lövések2']) then
cell:tag('i'):wikitext('Lövések')
end
cell = row:tag('td')
:css('width', '25%')
:css('vertical-align', 'top')
:css('text-align', 'left')
if isnotempty(args['lövések2']) then
cell:tag('i'):wikitext(args['lövések2'])
end
res = res .. tostring(root)
end
if isnotempty(args['note']) then
root = mw.html.create('table')
root
:attr('cellspacing', '0')
:css('width', '100%')
:css('background-color', args['háttér'] )
cell = root:tag('tr'):tag('td')
cell
:css('text-align', 'left')
:css('font-size', '100%')
:tag('i'):wikitext(args['note'])
res = res .. tostring(root) .. '[[Kategória:Jégkorongboxot tartalmazó oldalak jegyzettel]]'
end
-- tracking
if (args['sogoals1'] or args['sogoals2']) then
errorcats = errorcats .. '[[Kategória:A jégkorongbox nem megfelelően formázott| ]]'
end
-- make errors visible in preview mode
if errorcats ~= '' then
if frame:preprocess( "{{REVISIONID}}" ) == "" then
errorcats = '<span class="error">' .. errorcats .. '</span>'
else
errorcats = '<span style="display:none">' .. errorcats .. '</span>'
end
end
return errorcats .. res
end
return p