Modulo:FictionTV

Versione del 16 feb 2017 alle 00:10 di Rotpunkt (discussione | contributi) (Nuovo modulo)
(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)
Info Istruzioni per l'uso
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 errorCategory = '[[Categoria: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 2020
	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
		return nil, nil, nil, 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 = frame.args
	inizio, produzione, fine, err = parse_annoprimatv(args.annoprimatv)

	if 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
			cat = 'Serie televisive in produzione'
		elseif fine then
			cat = ' 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 .. (err and errorCategory or '')
end

return p