Перейти к содержанию

Модуль:Sports career

Сæрибар энциклопеди Википедийы æрмæг.

Для документации этого модуля может быть создана страница Модуль:Sports career/doc

local p={}

local currentTemplate = '<abbr title="нырыккон рæстæг" class="nowrap">н.&thinsp;р.</abbr>'
local spacesTemplate = '<span style="visibility:hidden;">0000</span>'
local yearFormat = '[12]%d?[%d?][%d?]'

function formatRow(row, mode, years, club, scores)
	years = years and mw.text.trim(years) or ''
	club = club and mw.text.trim(club) or ''
	scores = scores and mw.text.trim(scores) or ''
	
	if years ~= '' then
		years = mw.ustring.gsub(years, ' *[—-] *', '—')
		years = mw.ustring.gsub(years, \. *в\.', currentTemplate)
		local unboldYears =  mw.ustring.gsub(years, "'''", "")
		if not mw.ustring.find(unboldYears, '^' .. yearFormat .. '$')
			and not mw.ustring.find(unboldYears, '^' .. yearFormat .. '—' .. yearFormat .. '$')
			and not mw.ustring.find(unboldYears, '^' .. yearFormat .. '—' .. currentTemplate .. '$')
			and not mw.ustring.find(unboldYears, '^' .. spacesTemplate .. '—' .. yearFormat .. '$')
		then
			years = '<span class="sports-career-wrong">' .. years .. ''
		end
	end
	if scores ~= '' and mw.ustring.len(mw.text.trim(scores)) > 16 and not mw.ustring.find(scores, 'comment')
			and not mw.ustring.find(scores, 'abbr') and not mw.ustring.find(scores, 'ref') then
		scores = '<span class="sports-career-wrong">' .. scores .. ''
	end

	if years ~= '' or club ~= '' then
		local class = ''
		if mode == 3 then
			class = (row % 2 == 0) and ' even' or ' odd'
		end
		if scores ~= '' then
			return '|- class="nowrap' .. class .. '"\n| ' .. years .. '\n| ' .. club .. '\n| ' .. scores .. '\n'
		else
			return '|- class="nowrap' .. class .. '"\n| ' .. years .. '\n| colspan="2" |' .. club .. '\n'
		end
	else
		return ''
	end
end

function p.main(frame)
	local args = frame:getParent().args
	local mode = (frame.args.mode == '2') and 2 or 3
	local result = ''
	
	local params = {}
	local row = 1
	for key, param in pairs(args) do
		if tonumber(key) then
			table.insert(params, param)
			if key % mode == 0 then
				result = result .. formatRow(row, mode, unpack(params))
				params = {}
				row = row+1
			end
		end
	end
	if #params > 0 then
		result = result .. formatRow(row, mode, unpack(params))
	end
	
	if result == '' then
		return ''
	else
		return result
	end
end

return p