-- CFB schedule table conversion
-- {{subst:#invoke:CFB schedule/convert|table|...}}
local p = {}
local function splitargs(s)
s = '♣MARK♣' .. s
i = 0
while mw.ustring.find(s, '♣MARK♣') and (i < 100) do
i = i + 1
s=mw.ustring.gsub(s,'(♣MARK♣)%s*%|%s*([^%|{}%[%]=%s]*)%s*=%s*', '♦♦%2 = %1')
s=mw.ustring.gsub(s,'(♣MARK♣)([^%|{}%[%]=]*)', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%{%{[^%{%}]*%}%})', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[%[[^%[%]]*%]%])', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[[^%[%]]*%])', '%2%1')
s=mw.ustring.gsub(s,'♣MARK♣$', '')
end
local res = {}
for t in mw.text.gsplit(s, '%s*♦♦%s*') do
local k = mw.ustring.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%1')
local v = mw.ustring.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%2')
if k ~= t then
res[k] = v
end
end
return res
end
local function parseHeader(frame, s)
return frame:expandTemplate{title='CFB Schedule Start', args=splitargs(s)}
end
local function parseFooter(frame, s)
return frame:expandTemplate{title='CFB Schedule End', args=splitargs(s)}
end
local function parseEntry(frame, s)
local args = splitargs(s)
local res = '\n'
res = res .. '| ' .. (args['date'] or '')
if args['time'] and args['time'] == 'no' then
else
res = res .. '| ' .. (args['time'] or '')
end
res = res .. '| '
if args['away'] and args['away'] ~= '' then
res = res .. 'at '
end
if args['neutral'] and args['neutral'] ~= '' then
res = res .. 'vs '
end
res = res .. '|'
if args['opprank'] and args['opprank'] ~= '' then
res = res .. '#' .. args['opprank']
end
res = res .. ' ' .. (args['opponent'] or '')
if args['nonconf'] and args['nonconf'] == 'yes' then
res = res .. '<ncg>'
end
if args['homecoming'] and args['homecoming'] == 'yes' then
res = res .. '<hc>'
end
res = res .. (args['ref'] or '')
if args['rank'] and args['rank'] == 'no' then
else
res = res .. '| ' .. (args['rank'] or '')
end
res = res .. '| ' .. (args['site_stadium'] or '')
if args['site_cityst'] and args['site_cityst'] ~= '' then
else
if args['gamename'] and args['gamename'] ~= '' then
res = res .. ' (' .. args['gamename'] .. ')'
end
end
res = res .. '| ' .. (args['site_cityst'] or '')
if args['site_cityst'] and args['site_cityst'] ~= '' then
if args['gamename'] and args['gamename'] ~= '' then
res = res .. ' (' .. args['gamename'] .. ')'
end
end
if args['tv'] and args['tv'] == 'no' then
else
res = res .. '| ' .. (args['tv'] or '')
end
res = res .. '|' .. (args['w/l'] or '') .. ' ' .. (args['score'] or '')
if args['overtime'] and args['overtime'] ~= '' then
res = res .. '<sup>' .. args['overtime'] .. '</sup>'
end
if args['attend'] then
res = res .. '| ' .. args['attend']
end
return res
end
function p.table(frame)
local res = ''
for t in mw.text.gsplit(frame.args[1] or '', '{{[_%s]*CFB[_%s]*Schedule[_%s]*') do
local s = t:match( '^%s*(.-)%s*$' )
if mw.ustring.sub(s,-2) == '}}' then
s = mw.ustring.sub(s,1,-3)
if mw.ustring.sub(s,1,5) == 'Entry' then
res = res .. parseEntry(frame,mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,5) == 'Start' then
res = res .. parseHeader(frame,mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,3) == 'End' then
res = res .. parseFooter(frame,mw.ustring.sub(s,4))
else
res = res .. t
end
else
res = res .. t
end
end
return res
end
return p