Module:CFB schedule
Appearance
![]() | This Lua module is used on approximately 28,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Implements {{CFB schedule}}
-- 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