Modulo:Infobox/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
Test parametro posizione
 
(8 versioni intermedie di un altro utente non mostrate)
Riga 2:
local p = {} -- per l'esportazione delle funzioni del modulo
 
local args = {} -- variabile che contiene gli argomenti passati al template (post elaborazione)
local origArgs
local origArgs -- argomenti passati originariamente al template (pre elaborazione)
local root -- radice del markup html
local dump = {}
Riga 13:
valore = '<div>\n' .. valore .. '\n</div>'
end
return valore .. '\n'
end
 
Riga 45:
:tag('th')
:attr('colspan', 2)
:cssText(rowArgs.stilestilegruppoN or args.StileGruppo or ''nil)
:wikitext(rowArgs.gruppo)
-- Altrimenti se rowArgs.valore non è nullo inserisce una riga dati, verificando
Riga 55:
row
:tag('th')
:cssText(rowArgs.stilenomeN or args.StileNome or ''nil)
:wikitext(rowArgs.nome)
dataCell = row:tag('td')
Riga 64:
end
dataCell
:addClass(rowArgs.classe or ''nil)
:cssText(rowArgs.stilevaloreN or args.StileValore or ''nil)
:wikitext(checkList(rowArgs.valore))
end
Riga 76:
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(args.StileSopraTitolo or ''nil)
:wikitext(args.SopraTitolo)
:done()
Riga 87:
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(args.StileSottoTitolo or ''nil)
:wikitext(args.SottoTitolo)
end
Riga 94:
:tag('caption')
:addClass('sinottico_testata')
:cssText(args.StileTitoloEst or ''nil)
:node(suptitle)
:wikitext(args.TitoloEst)
Riga 105:
:attr('colspan', '2')
:node(suptitle)
:cssText(args.StileTitoloInt or ''nil)
:wikitext(args.TitoloInt)
:node(subtitle)
Riga 117:
:addClass('sinottico_testo_centrale ' .. (args.ClasseImmagine or ''))
:attr('colspan', '2')
:cssText(args.StileImmagine or ''nil)
:wikitext(args.Immagine)
if args.Didascalia then
Riga 124:
:done()
:tag('span')
:cssText(args.StileDidascalia or ''nil)
:wikitext(args.Didascalia)
end
Riga 132:
 
local function renderRows()
local rownums = getArgNums('Obbligato', 'Valore', 'GruppoOpzionale', 'Gruppo', 'Nodo')
for k, num in ipairs(rownums) do
local skip = false
Riga 139:
for j = k+1, #rownums do
if args['Gruppo' .. rownums[j]] ~= nil or args['GruppoOpzionale' .. rownums[j]]~=nil then break end
if args['Valore' .. rownums[j]] ~= nil or args['Nodo' .. rownums[j]] ~= nil then
skip = false
break
end
if args['Obbligato' .. rownums[j]] then
skip = false
break
end
end
end
if args['ObbligatoNodo' .. rownums[j]num] ~= nil then
root:wikitext(args['Nodo' .. num])
skip = falsetrue
end
if not skip and args['GruppoOpzionale' .. num] ~= '$fine' then
Riga 153:
gruppo = args['GruppoOpzionale' .. num] or args['Gruppo' .. num],
nome = args['Nome' .. num],
valore = args['Valore' .. num] or args['Obbligato' .. num],
classe = args['Classe' .. num],
stilestilegruppoN = args['GruppoStile' .. num],
stilenomeN = args['NomeStile' .. num],
stilevaloreN = args['ValoreStile' .. num]
})
end
Riga 168 ⟶ 170:
:attr('colspan', '2')
:addClass('sinottico_piede')
:cssText(args.StileUltima or ''nil)
:wikitext(args.Ultima)
:newline()
Riga 190 ⟶ 192:
local function _infobox()
-- Crea l'albero html che rappresenta la tabella del sinottico e restituisce il markup
if args.CreaTable == 'no' or args.Posizione == 'corpo' or args.Posizione == 'coda' then
root = mw.html.create('')
else
root = mw.html.create('table')
root
:addClass('infobox sinottico')
:cssText(args.StileTabella or ''nil)
:attr('summary', args.Summary or 'Tabella sinottica che riassume i principali dati del soggetto')
end
Riga 204 ⟶ 206:
renderLastRow()
renderNavBar()
returnlocal res = tostring(root)
if args.Posizione == 'coda' then
res = res .. '</table>';
elseif args.Posizione == 'testa' then
res = mw.ustring.gsub( res, '</table>$', '')
end
return res
end
 
local function preprocessSingleArg(argName, argObbligato)
-- Se l'argomento esiste e non è una stringa vuota lo aggiunge alla tabella degli argomenti
-- Argomenti uguali a stringa vuota sono trattati come nulli come da comportamento
-- precedente del template {{Infobox}}
if origArgs[argName] and origArgs[argName] ~= '' then
if origArgsargs[argName] ~= '' thenorigArgs[argName]
args[argName] = origArgs[argName]
elseif argObbligato and origArgs[argObbligato] then
args[argName] = origArgs[argObbligato]
end
end
end
Riga 258 ⟶ 263:
for j,v in ipairs(prefixTable) do
local prefixArgName = v.prefix .. tostring(i)
if origArgs[prefixArgName] then
moreArgumentsExist = true -- Aggiunge una passata se un parametro è stato trovato, anche se nullo.
preprocessSingleArg(prefixArgName, (v.prefix=="Valore" and "Obbligato" .. tostring(i)))
end
-- Processa la tavola dei dipendenti se il parametro da cui dipendono esiste e non è nullo
Riga 313 ⟶ 318:
preprocessSingleArg('StileValore')
preprocessArgs({
{prefix = 'Nodo'},
{prefix = 'Gruppo', depend={'GruppoStile'}},
{prefix = 'GruppoOpzionale', depend={'GruppoStile'}},
{prefix = 'Valore', depend={'Nome', 'Classe', 'NomeStile', 'ValoreStile'}},
}, 50)
preprocessSingleArg('Ultima')
Riga 322 ⟶ 328:
preprocessSingleArg('LinkWikidata')
preprocessSingleArg('CreaTable')
preprocessSingleArg('Posizione')
preprocessSingleArg('Summary')
-- if true then return mw.text.jsonEncode( args ) end
return _infobox()
end