Modulo:Stemma
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Stemma/man (modifica · cronologia)
Sandbox: Modulo:Stemma/sandbox · Sottopagine: lista · Test: Modulo:Stemma/test (modifica · cronologia · esegui)
Modulo Lua che implementa il template {{Stemma con ornamenti comuni}}.
Ha una sottopagina di configurazione: Modulo:Stemma/Configurazione.
--[[
* Modulo che implementa il template "Stemma con ornamenti comuni".
* Ha sostituito tutte le ~180 sottopagine in "Categoria:Template ornamenti esteriori".
]]
require('strict')
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Stemma/Configurazione')
local errorCategory = '[[Categoria:Voci con errori del modulo Stemma]]'
-- Error handler per xpcall, formatta l'errore.
--
-- @param {string} msg
-- @return {string}
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
-- =============================================================================
-- Classe Stemma
-- =============================================================================
-- La classe Stemma è la classe principale del modulo.
-- Al suo interno ha un riferimento alla configurazione dell'ornamento richiesto,
-- allo scudo specificato e li restituisce in una tabella HTML opportunamente formattata.
local Stemma = {}
-- Costruttore della classe Stemma.
--
-- @param {table} args - gli argomenti passati al template
-- @return {table} un nuovo oggetto Stemma
function Stemma:new(args)
local self = {}
setmetatable(self, { __index = Stemma })
-- ha 1 parametro posizionale e 3 con nome
self.ornName = args[1]
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 not self.orn then
error(string.format('l\'ornamento %s non esiste', self.ornName or ''), 3)
elseif args.coef and not self.coef then
error('coef non è valido', 3)
end
self.coef = self.coef or 1
self.ornFile = self.orn[1]
self.ornSize = math.floor(self.orn[2] * self.coef)
self.scudoSize = math.floor(self.orn[3] * self.coef)
self.scudoTop = math.floor((self.orn[4] + 50) * self.coef)
self.scudoLeft = math.floor((self.orn[5] + 50) * self.coef)
return self
end
-- Restituisce una tabella HTML con l'ornamento e lo scudo richiesti.
--
-- @return {string}
function Stemma:getHTML()
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
-- =============================================================================
-- Funzioni esportate
-- =============================================================================
local p = {}
-- Funzione per il template {{Stemma con ornamenti comuni}}.
function p.main(frame)
return select(2, xpcall(function()
return Stemma:new(getArgs(frame, { parentOnly = true })):getHTML()
end, errhandler))
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.