Modulo:FictionTV

Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:FictionTV/man (modifica · cronologia)
Sandbox: Modulo:FictionTV/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:FictionTV/test (modifica · cronologia · esegui)
Modulo a supporto del template {{FictionTV}}, per gestirne le funzioni di categorizzazione automatica per anno.
--[[
* Modulo a supporto del template FictionTV.
]]--
require('Modulo:No globals')
local getArgs = require('Modulo:Arguments').getArgs
local errorCategory = 'Errori di compilazione del template FictionTV'
local p = {}
-- Parsifica il parametro annoprimatv
local function parse_annoprimatv(annoprimatv)
local inizio, produzione, fine, err
-- annoprimatv senza intervallo, esempio "2010" o "[[2010]]"
inizio = annoprimatv:match('^%[?%[?(%d+)%]?%]?$')
-- altrimenti è un intervallo tipo "[[2010]]-[[2015]]" o "[[2010]] - in produzione"
if not inizio then
inizio = annoprimatv:match('^%[?%[?(%d+)%]?%]?%s*[–-]')
produzione = annoprimatv:match('produzione$')
fine = annoprimatv:match('^%[?%[?%d+%]?%]?%s*[–-]%s*%[?%[?(%d+)%]?%]?$')
end
-- verifica che inizio e fine siano compresi tra 1880 e 2030
inizio = inizio and tonumber(inizio)
fine = fine and tonumber(fine)
if not inizio or (inizio and (inizio <= 1880 or inizio >= 2030)) or
(fine and not produzione and (fine <= 1880 or fine >= 2030)) then
err = true
end
return inizio, produzione, fine, err
end
-- Funzione per {{#invoke:FictionTV|categorie_anno}}
function p.categorie_anno(frame)
local args, inizio, produzione, fine, err, cat, finecat
args = getArgs(frame, { parentOnly = true })
inizio, produzione, fine, err = parse_annoprimatv(args.annoprimatv)
if err then
cat = errorCategory
elseif args.tipofiction == 'miniserie TV' and inizio then
cat = 'Miniserie televisive del ' .. inizio
elseif args.tipofiction == 'film TV' and inizio then
cat = 'Film per la televisione del ' .. inizio
elseif args.tipofiction == 'serie TV' then
if inizio then
cat = 'Serie televisive iniziate nel ' .. inizio
end
if produzione then
finecat = 'Serie televisive in produzione'
elseif fine then
finecat = 'Serie televisive terminate nel ' .. fine
end
elseif args.tipofiction == 'serial TV' then
if inizio then
cat = 'Serial televisivi iniziati nel ' .. inizio
end
if produzione then
finecat = 'Serial televisivi in produzione'
elseif fine then
finecat = 'Serial televisivi terminati nel ' .. fine
end
end
cat = cat and string.format('[[Categoria:%s]]', cat) or ''
finecat = finecat and string.format('[[Categoria:%s]]', finecat) or ''
return cat .. finecat
end
return p