Jump to content

Module:Ice hockey box

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 17:14, 8 November 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- implements [[template:IceHockeybox]]
local p = {}

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

local function parsebrlist(s)
	if s then
		s = mw.ustring.gsub(s, '<[\/%s]*[Bb][Rr][^<>]*>', ' / ')
		s = mw.ustring.gsub(s, '[%s]*/[%s]*', '<br>')
	end
	return s
end

function p.box( frame )
	local args = frame:getParent().args
	local res = ''
	local goals1 = parsebrlist(args['goals1'] or '')
	local goals2 = parsebrlist(args['goals2'] or '')
	local progression = parsebrlist(args['progression'] or '')
	local id = args['id'] or ''
	
	id = mw.ustring.gsub(id,'^"(.-)"$', '%1')
	
	local root = mw.html.create('table')
	root
		:attr('cellspacing', '0')
		:attr('id', args['id'] )
		:css('width', '100%')
		:css('background-color', args['bg'] or '#eeeeee')
		:addClass('vevent')
	local row = root:tag('tr'):addClass('summary')
	-- Date and time
	local cell = row:tag('td')
		:css('width', '15%')
		:css('text-align', 'center')
		:css('font-size', '85%')
	cell:wikitext(args['date'] or '')
	cell:wikitext(isnotempty(args['time']) and '<br>' .. args['time'] or '')
	-- Team 1
	cell = row:tag('td')
		:css('width', '25%')
		:css('text-align', 'right')
		:addClass('vcard attendee')
	cell:tag('span'):addClass('fn org'):wikitext(args['team1'] or '')
	-- Score
	cell = row:tag('td')
		:css('width', '15%')
		:css('text-align', 'center')
	if isnotempty(args['score']) then
		cell:tag('b'):wikitext(args['score'])
		cell:wikitext('<br>')
		if isnotempty(args['periods']) then
			cell:tag('small'):wikitext(args['periods'])
		end
	end
	-- Team 2
	cell = row:tag('td')
		:css('width', '25%')
		:css('text-align', 'left')
		:addClass('vcard attendee')
	cell:tag('span'):addClass('fn org'):wikitext(args['team2'] or '')
	-- Stadium and attendance
	cell = row:tag('td')
		:css('font-size', '85%')
	if isnotempty(args['stadium']) then
		cell:tag('span'):addClass('location'):wikitext(args['stadium'])
	end
	if isnotempty(args['attendance']) then
		cell:wikitext('<br>')
		cell:tag('i'):wikitext('Attendance:')
		cell:wikitext(' ' .. args['attendance'])
	end
	res = res .. tostring(root)

	if isnotempty(args['score']) then
		root = mw.html.create('table')
		root
			:addClass('collapsible collapsed')
			:attr('cellspacing', '0')
			:css('width', '100%')
			:css('background-color', args['bg'] or '#eeeeee')
		cell = root:tag('tr'):tag('th')
		cell:attr('colspan', '5')
			:css('style', 'text-align', 'center')
			:css('font-size', '85%')
		if isnotempty(args['reference']) then
			cell:tag('b'):wikitext('[' .. args['reference'] .. ' Game reference]')
		end
		-- Empty spacing
		row = root:tag('tr'):css('font-size', '85%')
		cell = row:tag('td')
			:attr('rowspan', '4')
			: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['goalie1'] or '')
		cell = row:tag('td')
			:css('width', '15%')
			:css('vertical-align', 'top')
			:css('text-align', 'center')
		if isnotempty(args['goalie1']) or isnotempty(args['goalie2']) then
			cell:tag('i'):wikitext('Goalies')
		end
		cell = row:tag('td')
			:css('width', '25%')
			:css('vertical-align', 'top')
			:css('text-align', 'left')
			:wikitext(args['goalie2'] or '')

		-- Officials and linesmen
		cell = row:tag('td')
			:attr('rowspan', '4')
			:css('vertical-align', 'top')
		if isnotempty(args['official']) then
			if isnotempty(args['official2']) then
				cell:tag('i'):wikitext('Referees:')
				cell:wikitext('<br>' .. args['official'] .. '<br>' .. args['official2'])
			else
				cell:tag('i'):wikitext('Referee:')
				cell:wikitext('<br>' .. args['official'])
			end
		end
		if isnotempty(args['linesman']) then
			cell:wikitext('<br>')
			if isnotempty(args['linesman2']) then
				cell:tag('i'):wikitext('Linesmen:')
				cell:wikitext('<br>' .. args['linesman'] .. '<br>' .. args['linesman2'])
			else
				cell:tag('i'):wikitext('Linesman:')
				cell:wikitext('<br>' .. args['linesman'])
			end
		end
		-- Goals and progression
		row = root:tag('tr'):css('font-size', '85%')
		cell = row:tag('td')
			:css('width', '25%')
			:css('vertical-align', 'top')
			:css('text-align', 'right')
			:wikitext(goals1)
		cell = row:tag('td')
			:css('width', '15%')
			:css('vertical-align', 'top')
			:css('text-align', 'center')
			:wikitext(progression)
		cell = row:tag('td')
			:css('width', '25%')
			:css('vertical-align', 'top')
			:css('text-align', 'left')
			:wikitext(goals2)
		-- 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['penalties1']) then
			cell:tag('i'):wikitext(args['penalties1'] .. ' min')
		end
		cell = row:tag('td')
			:css('width', '15%')
			:css('vertical-align', 'top')
			:css('text-align', 'center')
		if isnotempty(args['penalties1']) or isnotempty(args['penalties2']) then
			cell:tag('i'):wikitext('Penalties')
		end
		cell = row:tag('td')
			:css('width', '25%')
			:css('vertical-align', 'top')
			:css('text-align', 'left')
		if isnotempty(args['penalties2']) then
			cell:tag('i'):wikitext(args['penalties2'] .. ' min')
		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['shots1']) then
			cell:tag('i'):wikitext(args['shots1'])
		end
		cell = row:tag('td')
			:css('width', '15%')
			:css('vertical-align', 'top')
			:css('text-align', 'center')
		if isnotempty(args['shots1']) or isnotempty(args['shots2']) then
			cell:tag('i'):wikitext('Shots')
		end
		cell = row:tag('td')
			:css('width', '25%')
			:css('vertical-align', 'top')
			:css('text-align', 'left')
		if isnotempty(args['shots2']) then
			cell:tag('i'):wikitext(args['shots2'])
		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['bg'] or '#eeeeee')
		cell = root:tag('tr'):tag('td')
		cell
			:css('text-align', 'left')
			:css('font-size', '100%')
			:tag('i'):wikitext(args['note'])
		res = res .. tostring(root)
	end
	return res
end

return p