Modulo:Stemma: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m aggiornato al funzionamento di mw.html:attr |
aggiornamento generale |
||
Riga 1:
--[[
* Modulo
* Sostituisce tutte le ~180 sottopagine in "Categoria:Template ornamenti esteriori".
]]
require('Modulo:No globals')
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Stemma/Configurazione')
local errorCategory = '[[Categoria:Voci con errori del modulo Stemma]]'
local function errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
Riga 39 ⟶ 22:
function Stemma:new(args)
-- ha 1 parametro posizionale e 3 con nome
self.scudoFile = args.stemma
self.align = args.align
self.coef = tonumber(args.coef)
-- ricerca l'ornamento
self.orn = cfg.ornamenti[self.ornName]
-- verifica argomenti
if
error(string.format('l\'ornamento %s non esiste', self.ornName or ''), 3)
elseif
error('coef non è valido', 3)
end
self.coef = self.coef or 1
self.ornFile = self.orn[1]
self.ornSize = tonumber(self.orn[2]) * self.coef
self.scudoSize = tonumber(self.orn[3]) * self.coef
self.scudoTop = (tonumber(self.orn[4]) + 50) * self.coef
self.scudoLeft = (tonumber(self.orn[5]) + 50) * self.coef
end
function Stemma:
local tableStyle = {
margin = '0',
border = 'none',
padding = '0',
['background-color'] = 'transparent'
}
local root = mw.html.create('table')
root
:attr('border', '0')
:attr('cellspacing', '0')
:attr('cellpadding', '0')
:attr('align', self.align)
:css(tableStyle)
:tag('tr')
:tag('td')
:tag('div')
:css('position', 'relative')
:wikitext(string.format('[[File:%s|%spx]]', self.ornFile, self.ornSize))
:tag('div')
:css('position', 'absolute')
:css('border', 'none')
:css('top', self.scudoTop .. 'px')
:css('left', self.scudoLeft .. 'px')
:tag('div')
:css('position', 'absolute')
:css('top', '0px')
:css('left', '0px')
:wikitext(string.format('[[File:%s|%spx]]', self.scudoFile or cfg.defaultScudo, self.scudoSize))
return tostring(root)
end
-------------------------------------------------------------------------------
-- API
-------------------------------------------------------------------------------
Riga 110 ⟶ 93:
-- Entry-point per {{Stemma con ornamenti comuni}}
function p.
return Stemma:new(getArgs(frame, { parentOnly = true })) end, errhandler)) end
return p
|