Modul:Ikon

A Wikipédiából, a szabad enciklopédiából
Ugrás a navigációhoz Ugrás a kereséshez

Source code project 1171.svg Ikon[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local template = nil

local function hanyas(...)
	hanyas = require('Modul:Nyelvtani modul').hanyas
	return hanyas(...)
end

local function getType(typ)
	local name = 'Ikon/Típus'
	if template and mw.title.new(template .. '/Típus', 10).exists then
		name = template .. '/Típus'
	end
	return mw.getCurrentFrame():expandTemplate{ title = name, args = { typ } }
end

local function icon(typ, city)
	local name = 'Ikon/Képek'
	if template and mw.title.new(template .. '/Képek', 10).exists then
		name = template .. '/Képek'
	end
	return mw.getCurrentFrame():expandTemplate{ title = name, args = { typ, city } }
end

local function text(sign, typ, city)
	if template and mw.title.new(template .. '/Szöveg', 10).exists then
		return mw.getCurrentFrame():expandTemplate{ title = template .. '/Szöveg', args = { sign, typ, city } }
	end
	local _, _, number = string.find(sign, '(%d+)$')
	local title
	number = tonumber(number)
	if number then
		if (number > 299.5 and number < 899.5) or (number > 999.5 and number < 8999.5) then
			-- 300..899, 1000..8999
			title = string.format('%s %s', hanyas(sign), typ)
		else
			-- 1..299, 900..999
			title = string.format('%s %s (%s)', hanyas(sign), typ, city)
		end
	else
		if string.lower(sign) == 'tesco' then
			title = string.format('Tesco-busz (%s)', city)
			sign = 'Tesco'
		else
			title = string.format('%s %s (%s)', sign, typ, city)
		end
	end
	if mw.title.new(title) and mw.title.new(title).exists then
		return string.format('[[%s|%s]]', title, sign)
	else
		return sign
	end
end

function p.ikon(frame, name)
	if name then
		template = name
	end
	local args = getArgs(frame, {removeBlanks = false})
	local typ = args[1]
	local typ_link = getType(typ)
	local city = mw.getCurrentFrame():expandTemplate{ title = 'Ikon/Város', args = { args[2] } }
	local list = {}
	for i, v in ipairs(args) do
		if i > 2 and v ~= '' then
			table.insert(list, text(v, typ_link, city))
		end
	end
	list = table.concat(list, ', ')
	if (args['láthatóikon'] or 'igen') == 'igen' then
		return string.format('<span class="noviewer">%s</span> %s', icon(typ, city), list)
	else
		return list
	end
end

setmetatable(p, {
	__index = function(t, name)
		return function(frame)
			return t.ikon(frame, name)
		end
	end
})

return p