Modulo:Vedi anche/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiornato stile documentazione a quello usato in Mediawiki per Lua, +string.format, fix minori
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(10 versioni intermedie di un altro utente non mostrate)
Riga 1:
--[[
* Modulo che implementa iil template {{Vedi anche}} e {{Vedi anche sezione}}.
]]
 
require('Modulo:No globalsstrict')
 
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne restituisce il wikilink.
Riga 12:
local dest, count
 
-- restituscerestituisce errore con wikilink a categorie
if arg:match('^%s*:%s*[Cc][Aa][Tt]') then
return '<span class="error">(usare il [[Template:Vedi categoria]])</span>'
Riga 24:
dest = arg
arg, count = arg:gsub('#', ' § ')
dest = count == 1 and (dest .. '|') or ''
 
return string.format("'''[[%s%s%s]]'''", dest, count == 1 and '|' or '', arg)
end
 
Line 31 ⟶ 32:
--
-- @param {string} wikitext
-- @param {boolean} withNoprint
-- @return {string}
local function buildHTML(wikitext, withNoprint)
local tableStyle = {
['margin-bottom'] = '.5em',
border = '1px solid #CCC',
['text-align'] = 'left',
['font-size'] = '95%',
background = 'transparent'
}
local tableNode = mw.html.create('table')
tableNode
:addClass(withNoprint'vedi-anche and 'noprint' or nil)
:css(tableStyle)
:tag('tr')
:tag('td')
:css('padding', '0 .5em')
:wikitext('[[File:Magnifying glass icon mgx2.svg|20px|class=noviewer|link=]]')
:done()
:tag('td')
:css('width', '100%')
:wikitext(string.format("''Lo stesso argomento in dettaglio: %s''.", wikitext))
:done()
Line 63 ⟶ 53:
 
local p = {}
 
-- Funzione per il template {{Vedi anche sezione}}.
function p.sezione(frame)
local arg = frame:getParent().args[1]
local wlink = arg and string.format("'''[[#%s|%s]]'''", arg, arg) or ''
return buildHTML('sezione ' .. wlink)
end
 
-- Funzione per il template {{Vedi anche}}.
function p.main(frame)
local lastArg, conjunction
local styles = 'Modulo:Vedi anche/sandbox/styles.css'
local args = {}
 
for _, val in ipairs(frame:getParent().args) do
if mw.text.trim(val) ~= '' then
table.insert(args, parseArg(val))
lastArg = val
end
end
if #args > 1 and lastArg then
Line 85 ⟶ 71:
end
 
return frame:extensionTag{
return buildHTML(mw.text.listToText(args, ',&#32;', conjunction), true)
name = 'templatestyles',
args = {src = styles}
return } .. buildHTML(mw.text.listToText(args, ',&#32;', conjunction), true)
end