Модуль:Sports results/blank

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
-- Этот модуль генерирует пустой вызов модуля sports results используя значения 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 or frame.args['team_order'] ~= nil) and frame.args or frame:getParent().args
	local processed = {}
-- Альтернативный синтаксис для списка команд
	if args['team_order'] and args['team_order'] ~= '' then
		local tlist = mw.text.split(args['team_order'], '%s*[;,]%s*')
		for k, tname in ipairs(tlist) do
			if tname ~= '' then
				args['team' .. k] = tname
			end
		end
	end

-- Вычисляем количество команд
	local numteams = 0
	while isnotempty(args['team' .. (numteams + 1)]) do
		numteams = numteams + 1
	end
	local res = '{{#invoke:sports results|main\n'
	res = res .. '| source = ' .. (args['source'] or '<!-- источник -->') .. '\n'
	processed['source'] = 1
	res = res .. '| update = ' .. (args['update'] or '<!-- дата обновления -->') .. '\n'
	processed['update'] = 1
	if args['start_date'] then
		res = res .. '| start_date = ' .. args['start_date'] .. '\n'
		processed['start_date'] = 1
	end
	if args['match_col_width'] then
		res = res .. '| match_col_width = ' .. args['match_col_width'] .. '\n'
		processed['match_col_width'] = 1
	end
	if args['matches_style'] then
		res = res .. '| matches_style = ' .. args['matches_style'] .. '\n'
		processed['matches_style'] = 1
	end
	if args['a_note'] then
		res = res .. '| a_note = ' .. args['a_note'] .. '\n'
		processed['a_note'] = 1
	end
	if args['showteam'] then
		res = res .. '| showteam = ' .. (args['showteam'] or '<!-- для выделения жирным шрифтом результатов одной команды -->') .. '\n'
		processed['showteam'] = 1
	end
	if args['team_order'] and args['team_order'] ~= '' then
		res = res .. '| team_order = ' .. args['team_order']
		processed['team_order'] = 1
		for i = 1, numteams do
			local ab = args['team' .. i]
			processed['team' .. i] = 1
		end
	else
		for i = 1, numteams do
			local ab = args['team' .. i]
			processed['team' .. i] = 1
			res = res .. '| team' .. i .. '= ' .. ab .. ' '
		end
	end
	res = res .. '\n\n'
	for i = 1, numteams do
		local ab = args['team' .. i]
		res = res .. '| name_' .. ab .. ' = ' .. (args['name_' .. ab] or '') .. '\n'
		processed['name_' .. ab] = 1
		if (args['short_' .. ab]) then
			res = res .. '| short_' .. ab .. ' = ' .. (args['short_' .. ab] or '') .. '\n'
			processed['short_' .. ab] = 1
		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'
				processed[mij] = 1
			end
		end
		res = res .. '\n'
	end
	local comment = '<!-- другие параметры -->\n'
	for k, v in pairs( args) do
		if v ~= nil and processed[k] == nil then
			res = res .. comment .. '| ' .. k .. ' = ' .. v .. '\n'
			comment = ''
		end
	end
	res = res .. '}}'
	return res
end

return p