Modulo:Infobox/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
+CreaTable, rimossi InserisciTestata e InserisciCoda inutilizzati
Moroboshi (discussione | contributi)
test
Riga 1:
-- Modulo per implementare le funzionalità di infobox
local p = {} -- per l'esportazione delle funzioni del modulo
require('Modulo:No globals')
local immagine_sinottico = require('Module:Immagine sinottico')._main
 
local args = {}-- variabile che contiene gli argomenti passati al template
local origArgs
local root -- radice del markup html
local dump = {}
 
 
local function getArgNums(...)
local function is_defined(s)
-- Restituisce una lista che contiene il suffisso numerico di tutti gli argomenti
if s == nil or s == '' then
-- che iniziano con il prefisso "prefix"
return false
-- Per esempio se nella lista argomenti sono valorizzati "Valore1, Valore2 e Valore4"
-- retistuirà la lista [1, 2, 4]
local prefixs = {...}
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
return true
table.sort(nums)
return nums
end
 
-------------------------------------------------------------------------------
local function addRow(rowArgs)
-- classe Infobox
-- Aggiunge una riga alla tabella
-------------------------------------------------------------------------------
-- Se rowArgs.gruppo non è nullo la considera come una riga di testata di gruppo
 
-- e ignora eventuali valorizzazioni di rowArgs.valore
p.Infobox = {}
if rowArgs.gruppo then
 
root
function Infobox:new(args)
:tag('tr')
local self = {}
:addClass("sinottico_divisione")
 
:tag('th')
setmetatable(self, { __index = Infobox })
:attr('colspan', 2)
-- Crea l'albero html che rappresenta la tabella del sinottico
:cssText(rowArgs.stile or args.StileGruppo or '')
self.stile_gruppi = args.stile_gruppi or ''
:wikitext(rowArgs.gruppo)
self.stile_etichette = args.stile_etichette or ''
-- Altrimenti se rowArgs.valore non è nullo inserisce una riga dati, verificando
self.stile_valori = args.stile_valori or ''
-- se esiste o meno la testata
elseifif rowArgsargs.valoreCreaTable == 'no' then
local rowself.root = root:tagmw.html.create('tr')
else
local dataCell
self.root = mw.html.create('table')
if rowArgs.nome then
self.root
row
:addClass(args.classe or 'sinottico')
:tag('th')
:cssText(args.StileNome or ''stile)
:attr('summary', args.sommario or 'Tabella sinottica che riassume i principali dati del soggetto' )
:wikitext(rowArgs.nome)
dataCell = row:tag('td')
else
dataCell = row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
end
dataCell
:addClass(rowArgs.classe or '')
:cssText(args.StileValore or '')
:wikitext(rowArgs.valore)
end
self:_setupTableNode()
return self
end
 
local function renderTitleInfobox:tostring()
return tostring(self.root)
local subtitle = mw.html.create('')
end
if args.SottoTitolo then
 
subtitle
function Infobox:sopratitolo(text, options)
:tag('br'):done()
if is_defined(text) then
self.subtitle = mw.html.create('')
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(argsoptions.StileSottoTitolo or ''stile_sopratitolo)
:wikitext(args.SottoTitolotext)
:done()
:tag('br')
end
return self
if args.TitoloEst then
end
root
 
:tag('caption')
function Infobox:sottotitolo(text, options)
:addClass('sinottico_testata')
if is_defined(text) then
self.subtitle = mw.html.create('')
:tag('br')
:done()
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(options.stile_sottotitolo)
:wikitext(text)
end
return self
end
 
 
function Infobox:titolo(title, options)
self.root = nil
if self.options.TitoloEst then
self.root
:tag('caption')
:addClass('sinottico_testata' )
:css("font-weight", "bold")
:cssText(argsoptions.StileTitoloEst or ''stile)
:node(options.sopratitolo, options)
:wikitext(args.TitoloEst)
:nodewikitext(subtitletitle)
:node(options.sottotitolo, options)
elseif args.TitoloInt then
else
root
self.root
:tag('tr')
:addClass('sinottico_testata')
:tag('th')
:attr('colspan', '2')
:cssTextnode(argsoptions.StileTitoloIntsopratitolo, or ''options)
:wikitextcssText(argsoptions.TitoloIntstile)
:nodewikitext(subtitletitle)
:node(options.sottotitolo, options)
end
return self
end
 
local function renderImageinfobox:gruppo(label, options)
if not args.Immagineis_defined(label) then return self end
if options.is_opzionale ~= nil then
local cell_immagine = mw.html.create('td')
self.opzionale_label = label
cell_immagine
self.opzionale_options = options
:addClass(args.ClasseImmagine or '')
return self
:attr('colspan', '2')
:css('text-align', 'center')
:cssText(args.StileImmagine or '')
:wikitext(args.Immagine)
if args.Didascalia then
cell_immagine
:tag('br', {selfClosing = true})
:done()
:tag('span')
:cssText(args.StileDidascalia or '')
:wikitext(args.Didascalia)
end
if self.opzionale_label ~= nil then
root:tag('tr'):node(cell_immagine)
infobox:voidGroup()
end
self.root
:tag('tr')
:addClass("sinottico_divisione")
:tag('th')
:attr('colspan', 2)
:cssText(options.stile or self.stile_gruppi or '')
:wikitext(label)
return self
 
end
 
function infobox:annulla_gruppo()
self.opzionale_label = ''
self.opzionale_options = nil
return self
end
 
function infobox:valore(value, label, options)
if not is_defined(value) then return self end
if self.opzionale_label then
self:gruppo(self.opzionale_label, self.opzionale_options)
self:annulla_gruppo()
end
local row = self.root:tag('tr')
local dataCell
if label ~= nil then
row
:tag('th')
:cssText(options.stile_etichetta or self.stile_etichette or '')
:wikitext(label)
dataCell = row:tag('td')
else
dataCell = row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
end
dataCell
:addClass(options.classe or '')
:cssText(args.stile_valore or self.stile_valori or '')
:wikitext(value)
return self
end
 
-------------------------------------------------------------------------------
-- fine classe Infobox
-------------------------------------------------------------------------------
 
local function getArgNums(...)
-- Restituisce una lista che contiene il suffisso numerico di tutti gli argomenti
-- che iniziano con il prefisso "prefix"
-- Per esempio se nella lista argomenti sono valorizzati "Valore1, Valore2 e Valore4"
-- retistuirà la lista [1, 2, 4]
local prefixs = {...}
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 renderRows()
local rownums = getArgNums('Valore', 'GruppoOpzionale', 'Gruppo')
for k, num in ipairs(rownums) do
local skip = false
if args['GruppoOpzionale' .. num] ~= nil then
if args['GruppoOpzionale' .. num] ~= '$fine' then
skip = true
Infobox:gruppo(args['GruppoOpzionale' .. num], {opzionale='s',
for j = k+1, #rownums do
if classe = args['GruppoClasse' .. rownums[j]num], stile ~= nil or args['GruppoOpzionaleGruppoStile' .. rownums[jnum]]~=nil then break end})
else
if args['Valore' .. rownums[j]] ~= nil then
Infobox:annulla_gruppo()
skip = false
break
end
end
endelse
if not skip and Infobox:valore(args['GruppoOpzionaleValore' .. num], ~= args['$fineNome' then.. num])
addRow({
gruppo = args['GruppoOpzionale' .. num] or args['Gruppo' .. num],
nome = args['Nome' .. num],
valore = args['Valore' .. num],
classe = args['Classe' .. num],
stile = args['GruppoStile' .. num]
})
end
end
end
 
local function renderLastRow()
if not args.Ultima then return end
root
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('sinottico_piede')
:cssText(args.StileUltima or '')
:wikitext(args.Ultima)
:newline()
end
 
local function renderNavBar_infobox()
-- Crea l'albero html che rappresenta la tabella del sinottico e restituisce il markup
if not args.NomeTemplate then return end
Infobox = infobox.create({sommario = args.summary, stile_gruppi = args.StileGruppo,
root
stile_valori = args.StileValore, stile_etichette = args.StileEtichetta })
:tag('tr')
local titolo, stile_titolo
:tag('td')
if args.TitoloEst then
:addClass('sinottico_piede2 noprint metadata')
titolo = args.TitoloEst
:attr('colspan', '2')
stile = args.StileTitoloEst
:wikitext(mw.getCurrentFrame():expandTemplate({
else
titolo = args.TitoloInt
stile = args.StileTitoloInt
end
Infobox:titolo( titolo, nil , { stile = stile, sottotitolo=args.SottoTitolo, stile_sottotitolo=args.StileSottoTitolo,
sopratitolo = args.SopraTitolo, stile_sopratitolo = args.SopraTitolo })
if args.Immagine then
local args_immagine =
Infobox:Valore(immagine_sinottico({ args.Immagine, args.Didascalia, stile_valore = args.StileImmagine,
compatibile = 's'}))
end
renderRows(Infobox)
Infobox:valore(args.Ultima, nil , {classe_valore='sinottico_piede', stile_valore = args.StileUltima })
if args.NomeTemplate then
local txt_nav = mw.getCurrentFrame():expandTemplate({
title = 'Link sinottico',
args = args.LinkWikidata and
{ args.NomeTemplate } or
{ args.NomeTemplate, nowd = 1 }
}))
Infobox:valore(txt_nav, nil , {classe_valore='sinottico_piede2 noprint metadata'})
end
 
local function _infobox()
-- Crea l'albero html che rappresenta la tabella del sinottico e restituisce il markup
if args.CreaTable == 'no' then
root = mw.html.create('')
else
root = mw.html.create('table')
root
:addClass('sinottico')
:cssText(args.StileTabella or '')
:attr('summary', args.Summary or 'Tabella sinottica che riassume i principali dati del soggetto')
end
renderTitle()
renderImage()
renderRows()
renderLastRow()
renderNavBar()
return tostring(root)
end
Riga 266 ⟶ 305:
-- la comparsa di riferimenti fantasma in posti inattesi.
preprocessSingleArg('StileTabella')
preprocessArgs({
{prefix='SopraTitolo', depend={'StileSopraTitolo'}}
}, 0)
preprocessArgs({
{prefix='TitoloEst', depend={'StileTitoloEst'}}
Riga 272 ⟶ 314:
{prefix='TitoloInt', depend={'StileTitoloInt'}}
}, 0)
preprocessArgs({
{prefix='SottoTitolo', depend={'StileSottoTitolo'}}
}, 0)
preprocessArgs({