Modulo:Vedi anche/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunta funzione "sezione" per il template "Vedi anche sezione"
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(14 versioni intermedie di 3 utenti non mostrate)
Riga 1:
--[[
* Modulo che implementa le funzionalità deiil template {{Vedi anche}} e {{Vedi anche sezione}}.
]]
 
require('Modulo:No globalsstrict')
 
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne ritornarestituisce il wikilink.
local p = {}
--
 
-- @param {string} arg
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne ritorna il wikilink.
-- @return {string}
local function parseArg(arg)
local dest, count
 
-- restituisce errore con wikilink a categorie
if arg:match('^%s*:%s*[Cc][Aa][Tt]') then
return '<span class="error">(usare il [[Template:Vedi categoria]])</span>'
end
 
-- rimuove eventuali pipe inserite tramite {{!}}
arg = arg:match('(.*)|') or arg
Line 20 ⟶ 26:
dest = count == 1 and (dest .. '|') or ''
 
return string.format("'''[[" .. dest .. arg .. "%s%s]]'''", dest, arg)
end
 
-- Costruisce l'HTML per contenere i wikilink alle pagine.
--
local function buildHTML(wikitext, with_noprint)
-- @param {string} wikitext
local tableStyle = {
-- @return {string}
['margin-bottom'] = '.5em',
local function buildHTML(wikitext, with_noprint)
border = '1px solid #CCC',
['text-align'] = 'left',
['font-size'] = '95%',
background = 'transparent'
}
local tableNode = mw.html.create('table')
tableNode
:addClass(with_noprint'vedi-anche and 'noprint' or nil)
:css(tableStyle)
:tag('tr')
:tag('td')
:wikitext('[[File:Exquisite-kfindMagnifying glass icon mgx2.pngsvg|20px|class=noviewer|link=]]')
:css('padding', '0 .5em')
:wikitext('[[File:Exquisite-kfind.png|20px|class=noviewer]]')
:done()
:tag('td')
:wikitext(string.format("''Lo stesso argomento in dettaglio: " .. wikitext .. "%s''.", wikitext))
:css('width', '100%')
:wikitext("''Lo stesso argomento in dettaglio: " .. wikitext .. "''.")
:done()
 
return tostring(tableNode)
end
 
-- =============================================================================
-- Entry-point per {{Vedi anche sezione}}
-- Funzioni esportate
function p.sezione(frame)
-- =============================================================================
local arg = frame:getParent().args[1]
local wlink = arg and ("'''[[#" .. arg .. "|" .. arg .. "]]'''") or ''
return buildHTML('sezione ' .. wlink)
end
 
local p = {}
-- Entry-point per {{Vedi anche}}
 
-- Entry-pointFunzione per il template {{Vedi anche sezione}}.
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
conjunction = mw.ustring.lower(lastArg:sub(1, 1)) == 'e' and 'ed' or 'e'
conjunction = '&#32;' .. conjunction .. '&#32;'
end
 
return frame:extensionTag{
return buildHTML(mw.text.listToText(args, ',&#32;', '&#32;e&#32;'), true)
name = 'templatestyles',
args = {src = styles}
return } .. buildHTML(mw.text.listToText(args, ',&#32;', '&#32;e&#32;'conjunction), true)
end