-- This module generates a blank invocation of the sports results module
-- using the values of team1, team2, ...
local p = {}
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
function p.main(frame)
local args = (frame.args['team1'] ~= nil) and frame.args or frame:getParent().args
-- Count the number of teams
local numteams = 0
while isnotempty(args['team' .. (numteams + 1)]) do
numteams = numteams + 1
end
local res = '{{#invoke:sports results|main\n'
res = res .. '| template_name = '
.. (args['template_name'] or '<!-- to add v-t-e links -->') .. '\n'
res = res .. '| source = '
.. (args['source'] or '<!-- source -->') .. '\n'
res = res .. '| update = '
.. (args['update'] or '<!-- last updated -->') .. '\n'
if args['start_date'] then
res = res .. '| start_date = ' .. args['start_date'] .. '\n'
end
if args['match_col_width'] then
res = res .. '| match_col_width = ' .. args['match_col_width'] .. '\n'
end
if args['matches_style'] then
res = res .. '| matches_style = ' .. args['matches_style'] .. '\n'
end
res = res .. '| showteam = ' ..
(args['showteam'] or '<!-- for bolding one team results -->') .. '\n'
for i=1,numteams do
local ab = args['team' .. i]
res = res .. '| team' .. i .. '= ' .. ab .. ' '
end
res = res .. '\n\n'
for i=1,numteams do
local ab = args['team' .. i]
res = res .. '| name_'..ab ..' = '.. (args['name_'..ab] or '') .. '\n'
if args['no_short'] == nil then
res = res .. '| short_'..ab ..' = '.. (args['short_'..ab] or '') .. '\n'
end
end
res = res .. '\n'
for i=1,numteams do
local abi = args['team' .. i]
for j=1,numteams do
local abj = args['team' .. j]
if i ~= j then
local mij = 'match_' .. abi .. '_' .. abj
res = res .. '| ' .. mij .. ' = ' .. (args[mij] or '') .. '\n'
end
end
res = res .. '\n'
end
res = res .. '}}'
return res
end
return p