De Muysc cubun - Lengua Muisca
(Página creada con «local p = {} local function splitCSV(s, sep) s = s or '' sep = sep or ',' local t = {} for token in mw.text.gsplit(s, sep, true) do token = mw.text.trim(token) if…») |
m |
||
| (No se muestran 3 ediciones intermedias del mismo usuario) | |||
| Línea 1: | Línea 1: | ||
| + | -- Módulo:LinkList | ||
local p = {} | local p = {} | ||
| − | local function | + | local function getArg(frame, name, default) |
| − | + | local v = (frame.args and frame.args[name]) or '' | |
| − | + | if v == '' and frame.getParent then | |
| − | + | local parent = frame:getParent() | |
| − | + | if parent and parent.args then v = parent.args[name] or '' end | |
| − | + | end | |
| − | + | if v == '' then v = default or '' end | |
| − | + | return v | |
| − | |||
end | end | ||
function p.links(frame) | function p.links(frame) | ||
| − | + | local valores = getArg(frame, 'valores', '') | |
| − | + | local outsep = getArg(frame, 'sep', ', ') | |
| − | + | local ns = getArg(frame, 'ns', '') | |
| − | + | local lead = getArg(frame, 'leadcolon', '') | |
| − | + | local prefix = getArg(frame, 'prefix', '') | |
| − | + | local suffix = getArg(frame, 'suffix', '') | |
| − | + | local doSort = getArg(frame, 'sort', '') ~= '' | |
| − | + | -- NUEVO: base para enlaces externos (déjalo vacío para enlaces internos) | |
| + | local base = getArg(frame, 'base', '') -- ej.: 'https://es.wikipedia.org/wiki/' | ||
| + | -- NUEVO: envoltorio para poder forzar target=_blank vía Common.js | ||
| + | local wrapCls = getArg(frame, 'class', 'll-newtab') | ||
| + | local newtab = getArg(frame, 'newtab', '') ~= '' | ||
| − | + | if valores == '' then | |
| − | + | return '⚠️ LinkList: sin "valores".' | |
| − | + | end | |
| − | |||
| − | + | -- Normaliza el separador: si es solo coma, añade espacio | |
| − | + | if outsep == ',' or outsep:match('^,%s*$') then | |
| − | + | outsep = ', ' | |
| − | + | end | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | local items = {} | |
| + | for tok in mw.text.gsplit(valores, ',', true) do | ||
| + | tok = mw.text.trim(tok) | ||
| + | if tok ~= '' then table.insert(items, tok) end | ||
| + | end | ||
| + | |||
| + | if doSort then | ||
| + | table.sort(items, function(a,b) | ||
| + | return mw.ustring.lower(a) < mw.ustring.lower(b) | ||
| + | end) | ||
| + | end | ||
| + | |||
| + | local out = {} | ||
| + | for _, it in ipairs(items) do | ||
| + | local target, label = it:match('^(.-)|(.+)$') | ||
| + | if not target then target, label = it, it end | ||
| + | target = prefix .. target .. suffix | ||
| + | local full = (lead ~= '' and ':' or '') .. ns .. target | ||
| + | |||
| + | if base ~= '' then | ||
| + | -- Enlace EXTERNO: convierte espacios a guiones bajos para que la URL sea válida | ||
| + | local urlTitle = full:gsub(' ', '_') | ||
| + | table.insert(out, string.format('[%s%s %s]', base, urlTitle, label)) | ||
| + | else | ||
| + | -- Enlace INTERNO wiki | ||
| + | table.insert(out, string.format('[[%s|%s]]', full, label)) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | local text = table.concat(out, outsep) | ||
| + | if newtab then | ||
| + | text = string.format('<span class="%s">%s</span>', wrapCls, text) | ||
| + | end | ||
| + | return text | ||
end | end | ||
return p | return p | ||
Revisión actual - 20:01 12 sep 2025
La documentación para este módulo puede ser creada en Módulo:LinkList/doc
-- Módulo:LinkList
local p = {}
local function getArg(frame, name, default)
local v = (frame.args and frame.args[name]) or ''
if v == '' and frame.getParent then
local parent = frame:getParent()
if parent and parent.args then v = parent.args[name] or '' end
end
if v == '' then v = default or '' end
return v
end
function p.links(frame)
local valores = getArg(frame, 'valores', '')
local outsep = getArg(frame, 'sep', ', ')
local ns = getArg(frame, 'ns', '')
local lead = getArg(frame, 'leadcolon', '')
local prefix = getArg(frame, 'prefix', '')
local suffix = getArg(frame, 'suffix', '')
local doSort = getArg(frame, 'sort', '') ~= ''
-- NUEVO: base para enlaces externos (déjalo vacío para enlaces internos)
local base = getArg(frame, 'base', '') -- ej.: 'https://es.wikipedia.org/wiki/'
-- NUEVO: envoltorio para poder forzar target=_blank vía Common.js
local wrapCls = getArg(frame, 'class', 'll-newtab')
local newtab = getArg(frame, 'newtab', '') ~= ''
if valores == '' then
return '⚠️ LinkList: sin "valores".'
end
-- Normaliza el separador: si es solo coma, añade espacio
if outsep == ',' or outsep:match('^,%s*$') then
outsep = ', '
end
local items = {}
for tok in mw.text.gsplit(valores, ',', true) do
tok = mw.text.trim(tok)
if tok ~= '' then table.insert(items, tok) end
end
if doSort then
table.sort(items, function(a,b)
return mw.ustring.lower(a) < mw.ustring.lower(b)
end)
end
local out = {}
for _, it in ipairs(items) do
local target, label = it:match('^(.-)|(.+)$')
if not target then target, label = it, it end
target = prefix .. target .. suffix
local full = (lead ~= '' and ':' or '') .. ns .. target
if base ~= '' then
-- Enlace EXTERNO: convierte espacios a guiones bajos para que la URL sea válida
local urlTitle = full:gsub(' ', '_')
table.insert(out, string.format('[%s%s %s]', base, urlTitle, label))
else
-- Enlace INTERNO wiki
table.insert(out, string.format('[[%s|%s]]', full, label))
end
end
local text = table.concat(out, outsep)
if newtab then
text = string.format('<span class="%s">%s</span>', wrapCls, text)
end
return text
end
return p
