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 })
-- annoprimatv e tipofiction sono obbligatori
if args.annoprimatv and args.tipofiction then
inizio, produzione, fine, err = parse_annoprimatv(args.annoprimatv)
else
err = true
end
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 inizio and not produzione and not fine then
finecat = 'Serie televisive terminate nel ' .. inizio
elseif 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 inizio and not produzione and not fine then
finecat = 'Serial televisivi terminati nel ' .. inizio
elseif 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
-- Funzione per {{#invoke:FictionTV|visualizzazione_anno}}
function p.visualizzazione_anno(frame)
local args, inizio, produzione, fine, err, annoinizio, annofine, inproduzione
args = getArgs(frame, { parentOnly = true })
if args.annoprimatv and args.tipofiction then
inizio, produzione, fine, err = parse_annoprimatv(args.annoprimatv)
else
err = true
end
if err then
cat = errorCategory
elseif inizio then
annoinizio = inizio
end
if fine then
annofine = fine
elseif produzione then
inproduzione = ' – in produzione'
end
annoinizio = annoinizio and string.format('[[%s]]', annoinizio) or ''
annofine = annofine and string.format('-[[%s]]', annofine) or ''
inproduzione = inproduzione and string.format('%s', inproduzione) or ''
return annoinizio,annofine,inproduzione
end
return p