Module:Sandbox/Jts1882/Goal

local p = {}

-- --<!-- -- 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 .. ' ' 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 = ' ' .. outputString .. ' '	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 = "" --"" 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  .. ' ' -- '       	    	outputString = outputString  .. ' '         	end        	-- add text string give goal times and other info        	--    does it need own span? No as it enlarges transclusion size  			--outputString = outputString  .. ' ' .. sep  .. time .. suffix .. ' '  			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 = ' ' .. outputString  .. ' '	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 = '(' .. suffix .. ')' elseif suffix == "o.g." or suffix == "og" then suffix = '(' .. suffix .. ')' end return " " .. suffix end

function p.noicon(frame) return frame:extensionTag{ name='templatestyles', args = { src='Goal/styles-no-icon.css'} } end

return p