Jump to content

Module:CFB schedule

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 14:39, 25 December 2017 (starting a lua version of the CFB schedule templates, will finish this later). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module implements {{CFB schedule}}
local p = {}

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

local function yesno(s, d)
	s = (s or ''):lower()
	if (s == 'no' or s == 'n') then
		return false
	elseif (s == 'yes' or s == 'y') then
		return true
	else
		return d
	end
end

local function getranklink(s)
	s = s or '{{CURRENTYEAR}}'
	return '[[{{cfb division|year=' .. s .. '}} football rankings|Rank]]'
end

function p.table(frame)
	local args = (frame.args[3] ~= nil) and frame.args or frame:getParent().args
	local ranknote = yesno(args['rank'], true) and '<sup>#</sup>' or ''
	
	-- switch headers on and off
	local headers = {'Date', 'Time', 'Opponent', 'Rank', 'Site', 'TV', 'Result', 'Attendance'}

	for k = #headers,1,-1 do
		if headers[k] == 'Time' and (yesno(args['time'], true) == false) then
			table.remove(headers,k)
		elseif headers[k] == 'Rank' and (yesno(args['rank'], true) == false) then
			table.remove(headers,k)
		elseif headers[k] == 'TV' and (yesno(args['tv'], true) == false) then
			table.remove(headers,k)
		elseif headers[k] == 'Attendance' and (yesno(args['attend'], true) == false) then
			table.remove(headers,k)
		end
	end

	-- create the root table
	local root = mw.html.create('table')
	root:addClass('wikitable')
		:css('font-size', '95%')

	-- add the headers
	local row = mw.html.create('tr')
	for k=1,#headers do
		local cell = row:tag('th')
		if headers[k] == 'Rank' then
			if yesno(args['ranklink'], true) then
				cell.wikitext(getranklink(args['rankyear']) .. ranknote)
			else
				cell.wikitext('Rank' .. ranknote)
			end
		elseif headers[k] == 'Rank' then
			cell.wikitext('Opponent' .. ranknote)
		else
			cell.wikitext(headers[k])
		end
	end
	
	-- build the table
	local stopflag = false
	local cols = #headers + 2
	local j = 0
	while stopflag == false do
		row = root:tag('tr')		
		for k = 1,cols do
			if args[k] == nil then
				stopflag = true
			end
		end
	end
	
	-- return the root table
	return tostring(root)
end

return p