Modulo:Infobox/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
+CreaTable, rimossi InserisciTestata e InserisciCoda inutilizzati |
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 function is_defined(s)
if s == nil or s == '' then
return false
end
return true
end
-------------------------------------------------------------------------------
-- classe Infobox
-------------------------------------------------------------------------------
p.Infobox = {}
function Infobox:new(args)
local self = {}
setmetatable(self, { __index = Infobox })
-- Crea l'albero html che rappresenta la tabella del sinottico
self.stile_gruppi = args.stile_gruppi or ''
self.stile_etichette = args.stile_etichette or ''
self.stile_valori = args.stile_valori or ''
else
self.root = mw.html.create('table')
self.root
:addClass(args.classe or 'sinottico')
:attr('summary', args.sommario or 'Tabella sinottica che riassume i principali dati del soggetto' )
end
self:_setupTableNode()
return self
end
return tostring(self.root)
end
function Infobox:sopratitolo(text, options)
if is_defined(text) then
self.subtitle = mw.html.create('')
:tag('span')
:addClass('sinottico_sottotitolo')
:cssText(
:wikitext(
:done()
:tag('br')
end
return self
end
function Infobox:sottotitolo(text, options)
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(
:node(options.sopratitolo, options)
:
:node(options.sottotitolo, options)
else
self.root
:tag('tr')
:addClass('sinottico_testata')
:tag('th')
:attr('colspan', '2')
:
:
:
:node(options.sottotitolo, options)
end
return self
end
if not
if options.is_opzionale ~= nil then
self.opzionale_label = label
self.opzionale_options = options
return self
end
if self.opzionale_label ~= nil then
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
if args['GruppoOpzionale' .. num] ~= nil then
if args['GruppoOpzionale' .. num] ~= '$fine' then
Infobox:gruppo(args['GruppoOpzionale' .. num], {opzionale='s',
else
Infobox:annulla_gruppo()
end
end
end
end
local function
-- Crea l'albero html che rappresenta la tabella del sinottico e restituisce il markup
Infobox = infobox.create({sommario = args.summary, stile_gruppi = args.StileGruppo,
stile_valori = args.StileValore, stile_etichette = args.StileEtichetta })
local titolo, stile_titolo
if args.TitoloEst then
titolo = args.TitoloEst
stile = args.StileTitoloEst
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
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)
}, 0)
preprocessArgs({
|