Modulo:Infobox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
aggiungo preprocessSingleArg per StileTabella |
Aggiungo supporto per posizione del template, come usato in Template:Personaggio e Template:Fumetto e animazione |
||
(27 versioni intermedie di 5 utenti non mostrate) | |||
Riga 1:
-- Modulo per implementare le funzionalità di infobox
local p = {} -- per l'esportazione delle funzioni del modulo
local args = {}-- variabile che contiene gli argomenti passati al template
Riga 9 ⟶ 7:
local dump = {}
local function
-- Permette al software Mediawiki di gestire le liste # o *
local c = mw.ustring.sub(valore, 1, 1)
if c == '#'
valore = '<div>\n' .. valore .. '\n</div>'
end
return valore .. '\n'
end
local function getArgNums(
local nums = {}
for k, _ in pairs(args) do
local num = nil
for _, candidate in ipairs(prefixs) do
num = ('' .. k):match('^' .. candidate .. '(%d+)$')
if num ~= nil then break end
end
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
local function addRow(rowArgs)
:cssText(rowArgs.stilegruppoN or
row
:cssText(rowArgs.stilenomeN or args.StileNome or nil)
:addClass('sinottico_testo_centrale')
:attr('colspan', 2)
:cssText(rowArgs.stilevaloreN or
end
local function renderTitle()
local suptitle = mw.html.create('')
if args.SopraTitolo then
suptitle
:tag('span')
:addClass('sinottico_sottotitolo')
:done()
:tag('br'):done()
end
local subtitle = mw.html.create('')
if args.SottoTitolo then
subtitle
:tag('br'):done()
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(args.StileSottoTitolo or nil)
:wikitext(args.SottoTitolo)
end
if args.TitoloEst then
root
:tag('caption')
:addClass('sinottico_testata')
:cssText(args.StileTitoloEst or nil)
:node(suptitle)
:wikitext(args.TitoloEst)
:node(subtitle)
elseif args.TitoloInt then
root
:tag('tr')
:addClass('sinottico_testata')
:tag('th')
:attr('colspan', '2')
:node(suptitle)
:cssText(args.StileTitoloInt or nil)
:wikitext(args.TitoloInt)
:node(subtitle)
end
end
local function renderImage()
local cell_immagine = mw.html.create('td')
:addClass('sinottico_testo_centrale ' .. (args.ClasseImmagine or ''))
:attr('colspan', '2')
:cssText(args.StileImmagine or nil)
:wikitext(args.Immagine)
if args.Didascalia then
cell_immagine
:tag('br', {selfClosing = true})
:done()
:tag('span')
:cssText(args.StileDidascalia or nil)
:wikitext(args.Didascalia)
end
root:tag('tr'):node(cell_immagine)
end
local function renderRows()
for k, num in
local skip = false
if args['GruppoOpzionale' .. num] ~= nil then
skip = true
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
end
end
if args['Nodo' .. num] ~= nil then
root:wikitext(args['Nodo' .. num])
skip = true
end
if not skip and args['GruppoOpzionale' .. num] ~= '$fine' then
addRow({
gruppo = args['GruppoOpzionale' .. num] or args['Gruppo' .. num],
nome = args['Nome' .. num],
valore = args['Valore' .. num],
classe = args['Classe' .. num],
stilegruppoN = args['GruppoStile' .. num],
stilenomeN = args['NomeStile' .. num],
stilevaloreN = args['ValoreStile' .. num]
})
end
end
end
local function renderLastRow()
root
:tag('tr')
:attr('colspan', '2')
:addClass('sinottico_piede')
:cssText(args.StileUltima or nil)
:wikitext(args.Ultima)
:newline()
end
local function renderNavBar()
root
:tag('tr')
:addClass('sinottico_piede2 noprint nomobile metadata')
:wikitext(mw.getCurrentFrame():expandTemplate({
title = 'Link sinottico',
args = args.LinkWikidata and
{ args.NomeTemplate, nowd = 1 }
}))
end
local function _infobox()
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
renderTitle()
renderImage()
renderRows()
renderLastRow()
renderNavBar()
local 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)
end
local function preprocessArgs(prefixTable, step)
end
end
end
end
end
end
end
function p.infobox(frame)
-- Le funzioni Parser considerano la stringa vuota come falsa, così per preservare il
-- comportamento di {{infobox}} tutti gli argomenti vuoti non vengono memorizzati
-- nella tabella globale args, così da essere considerati falsi
-- Nota: args è una variabile globale per il modulo dichiarata al suo inizio
-- Scandisce i parametri nello stesso ordine in cui lo faceva il vecchio {{infobox}}
-- così che eventuali istruzioni ref compariranno in posizione e ordine corretto. Parametri che dipendono da
-- altri parametri sono processati solo se il parametro è presente, così da evitare
-- la comparsa di riferimenti fantasma in posti inattesi.
preprocessSingleArg('StileTabella')
preprocessArgs({
{prefix='SopraTitolo', depend={'StileSopraTitolo'}}
}, 0)
preprocessArgs({
{prefix='TitoloEst', depend={'StileTitoloEst'}}
}, 0)
preprocessArgs({
{prefix='TitoloInt', depend={'StileTitoloInt'}}
}, 0)
preprocessArgs({
{prefix='SottoTitolo', depend={'StileSottoTitolo'}}
}, 0)
preprocessArgs({
{prefix='Immagine', depend={'ClasseImmagine', 'StileImmagine',
'Didascalia', 'StileDidascalia'}}
}, 0)
preprocessSingleArg('StileGruppo')
preprocessSingleArg('StileNome')
preprocessSingleArg('StileValore')
preprocessArgs({
{prefix = 'Nodo'},
{prefix = 'Gruppo', depend={'GruppoStile'}},
{prefix = 'GruppoOpzionale', depend={'GruppoStile'}},
{prefix = 'Valore', depend={'Nome', 'Classe', 'NomeStile', 'ValoreStile'}},
}, 50)
preprocessSingleArg('Ultima')
preprocessSingleArg('StileUltima')
preprocessSingleArg('NomeTemplate')
preprocessSingleArg('LinkWikidata')
preprocessSingleArg('CreaTable')
preprocessSingleArg('Posizione')
preprocessSingleArg('Summary')
return _infobox()
end
|