Mudanças entre as edições de "Módulo:Changelog"
Ir para navegação
Ir para pesquisar
m Etiqueta: Reversão manual |
m |
||
| Linha 4: | Linha 4: | ||
local function has(s) return N(s) ~= '' end | local function has(s) return N(s) ~= '' end | ||
-- Uso: {{#invoke:Changelog|item|title=...|description=...|date=...|link=...|icon=...|color=#FCE5CD}} | |||
function p.item(frame) | function p.item(frame) | ||
local parent = frame:getParent() | local parent = frame:getParent() | ||
local a = parent and parent.args or frame.args | local a = (parent and parent.args) or frame.args or {} | ||
local title = N(a.title) | local title = N(a.title) | ||
| Linha 15: | Linha 16: | ||
local color = N(a.color) | local color = N(a.color) | ||
local item = mw.html.create('div'):addClass('notice-item') | -- Raiz do item | ||
local item = mw.html.create('div') | |||
:addClass('notice-item') | |||
if has(color) then item:css('--notice-color', color) end | if has(color) then | ||
item:css('--notice-color', color) | |||
end | |||
-- Pré-monta wikitext dos ícones (inline e overlay) | |||
local inline_icon_wikitext | local overlay_icon_wikitext, inline_icon_wikitext | ||
if has(icon) then | if has(icon) then | ||
local | local lower = icon:lower() | ||
local | local is_url = lower:find('://', 1, true) ~= nil | ||
if | local is_prefixed = lower:match('^file:') or lower:match('^image:') | ||
overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay]]', | |||
inline_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline]]', | if not is_url and not is_prefixed then | ||
-- Nome de arquivo "puro" (ex.: Attr_PVE.png) | |||
overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title) | |||
inline_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title) | |||
elseif is_url then | |||
-- URL externa | |||
overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', icon, title) | |||
inline_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />', icon, title) | |||
else | else | ||
-- Já veio com File:/Image: | |||
overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title) | |||
inline_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title) | |||
end | end | ||
end | end | ||
local content = item:tag('div'):addClass('notice-content'):css('flex','1') | -- Conteúdo principal | ||
local content = item:tag('div'):addClass('notice-content'):css('flex', '1') | |||
-- Header | -- Header (ícone inline + título + data) | ||
local header = content:tag('div'):addClass('notice-header') | |||
local left = header:tag('div'):addClass('notice-left') | |||
if inline_icon_wikitext then | |||
left:wikitext(inline_icon_wikitext) | |||
end | |||
if has(title) then | |||
local holder = left:tag('span'):addClass('notice-title') | |||
if has(link) then | |||
holder:tag('a') | |||
:attr('href', link) | |||
:attr('target', '_blank') | |||
:attr('rel', 'noopener noreferrer') | |||
:wikitext(title) | |||
else | |||
holder:wikitext(title) | |||
end | end | ||
end | |||
if has(date) then | |||
left:tag('div'):addClass('notice-date'):wikitext(date) | |||
end | end | ||
if has(desc) then | if has(desc) then | ||
content:tag('p'):addClass('notice-desc') | content:tag('p'):addClass('notice-desc'):wikitext(desc) | ||
end | end | ||
-- | -- Ícone overlay (se o CSS usar posição absoluta) | ||
if overlay_icon_wikitext then | if overlay_icon_wikitext then | ||
item:wikitext(overlay_icon_wikitext) | item:wikitext(overlay_icon_wikitext) | ||
end | end | ||
return tostring(item) | return tostring(item) | ||
end | end | ||
return p | return p | ||
Edição das 14h11min de 10 de setembro de 2025
A documentação para este módulo pode ser criada em Módulo:Changelog/doc
local p = {}
local function N(s) return s and mw.text.trim(tostring(s)) or '' end
local function has(s) return N(s) ~= '' end
-- Uso: {{#invoke:Changelog|item|title=...|description=...|date=...|link=...|icon=...|color=#FCE5CD}}
function p.item(frame)
local parent = frame:getParent()
local a = (parent and parent.args) or frame.args or {}
local title = N(a.title)
local link = N(a.link)
local date = N(a.date)
local desc = N(a.description)
local icon = N(a.icon)
local color = N(a.color)
-- Raiz do item
local item = mw.html.create('div')
:addClass('notice-item')
if has(color) then
item:css('--notice-color', color)
end
-- Pré-monta wikitext dos ícones (inline e overlay)
local overlay_icon_wikitext, inline_icon_wikitext
if has(icon) then
local lower = icon:lower()
local is_url = lower:find('://', 1, true) ~= nil
local is_prefixed = lower:match('^file:') or lower:match('^image:')
if not is_url and not is_prefixed then
-- Nome de arquivo "puro" (ex.: Attr_PVE.png)
overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
inline_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title)
elseif is_url then
-- URL externa
overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', icon, title)
inline_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />', icon, title)
else
-- Já veio com File:/Image:
overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
inline_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title)
end
end
-- Conteúdo principal
local content = item:tag('div'):addClass('notice-content'):css('flex', '1')
-- Header (ícone inline + título + data)
local header = content:tag('div'):addClass('notice-header')
local left = header:tag('div'):addClass('notice-left')
if inline_icon_wikitext then
left:wikitext(inline_icon_wikitext)
end
if has(title) then
local holder = left:tag('span'):addClass('notice-title')
if has(link) then
holder:tag('a')
:attr('href', link)
:attr('target', '_blank')
:attr('rel', 'noopener noreferrer')
:wikitext(title)
else
holder:wikitext(title)
end
end
if has(date) then
left:tag('div'):addClass('notice-date'):wikitext(date)
end
if has(desc) then
content:tag('p'):addClass('notice-desc'):wikitext(desc)
end
-- Ícone overlay (se o CSS usar posição absoluta)
if overlay_icon_wikitext then
item:wikitext(overlay_icon_wikitext)
end
return tostring(item)
end
return p