Module:Sandbox/Jts1882/Goal
Module documentation[] [purge]
local p = {}
-- [[File:Soccerball shade.svg|13px|Goal|link=]]
--{{#if: {{#if:{{{1|}}}|{{{1|}}}|{{{2|}}}}}| <small style="vertical-align: middle;">{{#if: {{{1|}}}|{{{1}}}{{`}}}}{{#if: {{{2|}}}|{{#if:{{{1|}}}| }}{{#switch: {{{2|}}} |o.g. =([[Own goal#Association football|o.g.]]) |pen. =([[Penalty kick (association football)|pen.]]) |p =([[Penalty kick (association football)|p]]) | #default = ({{{2}}})}}}}</small>}}<!--
--{{#if: {{{3<includeonly>|</includeonly>}}}|, <small style="vertical-align: middle;">{{{3}}}{{`}}{{#if: {{{4|}}}| {{#switch: {{{4|}}} |o.g. =([[Own goal#Association football|o.g.]]) |pen. =([[Penalty kick (association football)|pen.]]) |p =([[Penalty kick (association football)|p]]) | #default = ({{{4}}})}}}}</small>}}
function p.main(frame)
local args = frame:getParent().args
if args['card'] == "red" or args['card'] == "yellow" then
local description = mw.language.getContentLanguage():ucfirst(args['card']) .. " card"
return p.cards(frame, args['card'], description)
elseif args['card'] == "second-yellow" then
return p.cards(frame, args['card'], "Sent off (second yellow)")
else -- must be goal
return p.goal(frame)
end
end
function p.cards(frame, color, description)
local args = frame:getParent().args
local outputString = ""
local i = 1
local sep = "" -- use for comma between items, except for first item
while i<3 do -- loop through cards
local time = 0
if args[i] and args[i] ~= "" then
time = args[i]
-- add span element for icon (provided as background image in styles.css of template)
if i == 1 then
outputString = outputString .. '<span class="'.. color .. '-card"'
.. ' role="img" aria-label="'.. description .. '"'
.. ' title="'.. description .. '"></span>'
end
-- add time of card
outputString = outputString .. sep .. time .. "'"
else break; -- would there ever be cases where only later positions used?
end
sep = ", " -- separate items by comma hereafter
i=i+1
end
-- if we have content, put in block with template styles icon
if outputString ~= "" then
outputString = '<span class="fb-goal-card">' .. outputString .. '</span>'
end
return frame:extensionTag{ name='templatestyles', args = { src='Goal/styles.css'} } .. outputString
end
function p.goal(frame)
local args = frame:getParent().args
local outputString = ""
local icon = "" --"[[File:Soccerball shade.svg|13px|Goal|link=]]"
local i = 1
local sep = "" -- use for comma between items, except for first item
while i<40 do -- loop through goals scored by player (goals in positions 1,3,5 ...)
local time = 0
local suffix = ""
if args[i] and args[i] ~= "" then
time = args[i]
if args[i+1] and args[i+1] ~= "" then -- optional text for pen or o.g. etc
suffix = args[i+1]
--else suffix = ""
end
-- add span element for icon (provided as background image in styles.css of template)
if i == 1 then
-- TODO? background images have no alt image; instead use role="img" aria-label="[place alt text here]>
--outputString = outputString .. '<span class="goal"/>' --</span>'
outputString = outputString .. '<span class="goal" role="img" aria-label="Goal" title="Goal"></span>'
end
-- add text string give goal times and other info
-- does it need own span? No as it enlarges transclusion size
--outputString = outputString .. '<span class="text">' .. sep .. time .. suffix .. '</span>'
outputString = outputString .. sep .. p.parseTime(time) .. p.parseSuffix(suffix)
else break; -- would there ever be cases where only later positions used?
end
sep = ", " -- separate items by comma hereafter
i=i+2
end
-- if we have content, put in block with template styles icon
if outputString ~= "" then
outputString = '<span class="fb-goal-card">' .. outputString .. '</span>'
end
return frame:extensionTag{ name='templatestyles', args = { src='Goal/styles.css'} } .. outputString
end
function p.parseTime(time)
--TODO check that minutes aren't already specified
return time .. "'"
end
function p.parseSuffix(suffix)
if suffix == "" then return suffix end
if suffix == "pen." or suffix == "p" then
suffix = '([[Penalty kick (association football)|' .. suffix .. ']])'
elseif suffix == "o.g." or suffix == "og" then
suffix = '([[Own goal#Association football|' .. suffix .. ']])'
end
return " " .. suffix
end
function p.noicon(frame)
return frame:extensionTag{ name='templatestyles', args = { src='Goal/styles-no-icon.css'} }
end
return p