Module:Wt/lij/Vedi anche

From Wikimedia Incubator

Questo template serve unicamente per gestire il {{Vedi}}, ha perciò un'unica funzione, main, che gestisce tutti i parametri e la creazione del box.

Fare riferimento al suddetto template per la sintassi d'uso.


local mBox = require('Module:Wt/lij/Message box')
local getArgs = require('Module:Wt/lij/Arguments').getArgs

local p = {}

local function categorizza(cat)
	return string.format('[[%s:%s]]', mw.site.namespaces[14].name, cat)
end

function p.main(frame)
	local lemmi = {}
	local boxArgs = {}
	local testo, stile, immagine
	local args = getArgs(frame)
	local sect = args.sect
	
	
	for i, j in pairs(args) do
--		if type(i) ~= 'number' then
--			error ('[[Template:Vedi|Template Vedi]]: È stato specificato un parametro nominale')
--		end
		
		if mw.text.trim(j) == '' then
			error ('[[Template:Wt/lij/Vedi|Template Vedi]]: È stato specificato un parametro vuoto')
		end

		if i ~= 'sect' then
			table.insert(lemmi, string.format('[[||%s]]', mw.text.trim(j)))
		end
	end

	if (#lemmi) == 0 then
			stile = 'background-color: #FFDBDB;'
			immagine = '[[File:Gnome-software-update-urgent.svg|30px]]'
			testo =  '<strong class="error">Il [[Template:Wt/lij/Vedi|Template Vedi]] è stato lasciato vuoto</strong> per correggere questo errore puoi <span class="plainlinks">['..mw.title.getCurrentTitle():fullUrl{action = 'edit'}..' modificare la pagina] oppure, per sapere come correggere, puoi leggere la [[template:Vedi/man|guida]]'
			-- testo = testo .. categorizza('template con errori') -- Se volessimo, la categorizzazione è già pronta, basta decidere quale usare
		else
			
			stile = 'background-color: #D8E8FF; border:1px solid #A0CCA0;'
			immagine = '[[File:Blue_Glass_Arrow.svg|30px]]'
			testo = 'Vedi anche: ' ..mw.text.listToText( lemmi, ', ', ' e ' )
		
	end

-- GESTIONE E CREAZIONE DEL BOX

	boxArgs.stile = stile
	boxArgs.immagine = immagine
if sect == 'y' then
	boxArgs.small='y'
end
	boxArgs.testo = testo	
	return mBox.main('ombox', boxArgs)
end

return p