Modul:Ikon
Ikon[mi ez?] • [dokumentáció: mutat, ] • [tesztek: létrehozás]
|
A sablonhoz tartozó dokumentáció a Sablon:Ikon lapon található. |
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, expensiveEnabled)
if template and mw.title.new(template .. '/Szöveg', 10).exists then
return mw.getCurrentFrame():expandTemplate {
title = template .. '/Szöveg',
args = { sign, typ, city, not expensiveEnabled and 'X' or '' }
}
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 city and city:len() > 0 then
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
else
title = nil;
end
end
if not expensiveEnabled or title and mw.title.new(title) and mw.title.new(title).exists then
return string.format('[[%s|%s]]', title, sign)
end
return sign
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, not (args.piroslink == 'igen')))
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