Documentation icon Τεκμηρίωση module[δημιουργία]
local p = {}

local function stripToNil(text)
	-- If text is a string, return its trimmed content, or nil if empty.
	-- Otherwise return text (which may, for example, be nil).
	if type(text) == 'string' then
		text = text:match('(%S.-)%s*$')
	end
	return text
end

function p:FlagIOC()
		local args = frame:getParent().args
	local code = stripToNil(args[1]) or error('flagIOC parameter 1 should be a country code')
	local games = stripToNil(args[2])
	if year then
	   local year = stripToNil(args[3])
	end
	local athletes = stripToNil(args[4])
	if year or mw.ustring.len( games ) < 13 then
	games = games and (games .. ' Όλυμπιακούς Αγώνες' .. year) or 'Ολυμπιακούς Αγώνες' else
    	games = games and (mw.ustring.sub( games, 1, mw.ustring.find( games, ' ', 1, true ) ) .. ' Όλυμπιακούς Αγώνες' .. mw.ustring.sub(games, mw.ustring.find( games, ' ', 1, true ) + 1)) or 'Ολυμπιακούς Αγώνες'
	end
	local parms = {
		alias = code,
		fullName = games,
	}
	local fullName = countryAlias(parms)
	parms.flag = true
	return (('[[File:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} στους {games}|{name}]]{athletes}')
		:gsub('{(%w+)}', {
			athletes = athletes and
				('&nbsp;<span style="font-size:90%;">(' .. athletes .. ')</span>') or
				'',
			flag = countryAlias(parms),
			games = games,
			name = fullName,
		}))
	end