Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Società atletica/man (modifica · cronologia)
Sandbox: Modulo:Società atletica/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Società atletica/test (modifica · cronologia · Esegui)
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Società atletica/man (modifica · cronologia)
Sandbox: Modulo:Società atletica/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Società atletica/test (modifica · cronologia · Esegui)
Modulo che implementa il template {{Società atletica}}.
Ha una sottopagina di configurazione: Modulo:Società atletica/Configurazione.
--[[
* Modulo che implementa il template Società atletica.
]]--
require('strict')
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Società atletica/Configurazione')
-- se manca il primo argomento
local noparamCategory = '[[Categoria:Malfunzionamenti template atletica leggera]]'
-- se la società specificata non esiste
local missingCategory = '[[Categoria:Voci con bandierine di atletica leggera mancanti]]'
local p = {}
local function titleExists(name)
local title = mw.title.new(name)
return title and title.exists
end
local function formatSocieta(societa, args)
local text = ''
if args[2] then
if titleExists(societa.nome) then
-- se args2 è diverso da 'nome' crea un piped wikilink
if args[2] == 'nome' then
text = string.format('[[%s]]', societa.nome)
else
text = string.format('[[%s|%s]]', societa.nome, args[2])
end
else
text = args[2] == 'nome' and societa.nome or args[2]
end
end
return string.format('[[File:%s|20px|border]] %s', societa.bandiera, text)
end
-- Entry-point per il template {{Società atletica}}
function p.main(frame)
local args = getArgs(frame, {parentOnly = true})
local ns0 = mw.title.getCurrentTitle().namespace == 0
local ret
local societa = cfg.societa[cfg.alias[args[1]] or args[1]]
if societa then
ret = formatSocieta(societa, args) ..
((args.cat and societa.categoria and ns0) and
string.format('[[Categoria:%s]]', societa.categoria) or '')
else
ret = '[[File:Flag of None.svg|20px|border]] ' ..
(args[2] == 'nome' and (args[1] or '') or (args[2] or '')) ..
(ns0 and missingCategory or '')
end
return ret .. ((not args[1] and ns0) and noparamCategory or '')
end
return p