Mudanças entre as edições de "Módulo:Changelog"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 1: Linha 1:
local p = {}
local p = {}


local function N(s) return s and mw.text.trim(tostring(s)) or '' end
local function N(s)
local function has(s) return N(s) ~= '' end
    return s and mw.text.trim(tostring(s)) or ''
end
local function has(s)
    return N(s) ~= ''
end
 
local function clean_url(s)
    s = N(s)
    -- remove CR/LF/TAB e espaços dentro do atributo
    s = s:gsub('[\r\n\t]', ''):gsub(' +', '')
    return s
end


-- Uso: {{#invoke:Changelog|item|title=...|description=...|date=...|link=...|icon=...|color=#FCE5CD}}
-- 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 or {}
    local a = (parent and parent.args) or frame.args or {}


  local title = N(a.title)
    local title = N(a.title)
  local link = N(a.link)
    local link = clean_url(a.link)
  local date = N(a.date)
    local date = N(a.date)
  local desc = N(a.description)
    local desc = N(a.description)
  local icon = N(a.icon)
    local icon = N(a.icon)
  local color = N(a.color)
    local color = N(a.color)


  -- Raiz do item
    -- container do item
  local item = mw.html.create('div')
    local item = mw.html.create('div'):addClass('notice-item')
     :addClass('notice-item')
     if has(color) then
        item:css('--notice-color', color)
    end


  if has(color) then
    -- preparar ícones (inline e overlay), sem link
    item:css('--notice-color', color)
    local overlay_icon_wikitext, inline_icon_wikitext
  end
    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:')


  -- Pré-monta wikitext dos ícones (inline e overlay)
        if is_url then
  local overlay_icon_wikitext, inline_icon_wikitext
            overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />',
  if has(icon) then
                icon, title)
    local lower = icon:lower()
            inline_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />',
    local is_url = lower:find('://', 1, true) ~= nil
                icon, title)
    local is_prefixed = lower:match('^file:') or lower:match('^image:')
        elseif is_prefixed then
            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)
        else
            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)
        end
    end


     if not is_url and not is_prefixed then
     local content = item:tag('div'):addClass('notice-content'):css('flex', '1')
      -- 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
    -- header com esquerda (ícone+titulo) e direita (data)
  local content = item:tag('div'):addClass('notice-content'):css('flex', '1')
    if has(title) or has(date) then
        local header = content:tag('div'):addClass('notice-header')
        local left = header:tag('div'):addClass('notice-header-left')
        local right = header:tag('div'):addClass('notice-header-right')


  -- Header (ícone inline + título + data)
        if inline_icon_wikitext then
  local header = content:tag('div'):addClass('notice-header')
            left:wikitext(inline_icon_wikitext)
  local left  = header:tag('div'):addClass('notice-left')
        end


  if inline_icon_wikitext then
        if has(title) then
    left:wikitext(inline_icon_wikitext)
            local holder = left:tag('span'):addClass('notice-title')
  end
            if has(link) then
                holder:tag('a'):attr('href', link):attr('target', '_blank') -- também forço nova aba aqui
                :attr('rel', 'noopener noreferrer'):wikitext(title)
            else
                holder:wikitext(title)
            end
        end


  if has(title) then
        if has(date) then
    local holder = left:tag('span'):addClass('notice-title')
            right:tag('span'):addClass('notice-date'):wikitext(date)
    if has(link) then
         end
      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
    if has(desc) then
    left:tag('div'):addClass('notice-date'):wikitext(date)
        content:tag('p'):addClass('notice-desc'):wikitext(desc)
  end
    end


  if has(desc) then
     if overlay_icon_wikitext then
     content:tag('p'):addClass('notice-desc'):wikitext(desc)
        item:wikitext(overlay_icon_wikitext)
  end
    end
 
  -- Ícone overlay (se o CSS usar posição absoluta)
  if overlay_icon_wikitext then
    item:wikitext(overlay_icon_wikitext)
  end


  return tostring(item)
    return tostring(item)
end
end


return p
return p

Edição das 14h16min 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

local function clean_url(s)
    s = N(s)
    -- remove CR/LF/TAB e espaços dentro do atributo
    s = s:gsub('[\r\n\t]', ''):gsub(' +', '')
    return 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 = clean_url(a.link)
    local date = N(a.date)
    local desc = N(a.description)
    local icon = N(a.icon)
    local color = N(a.color)

    -- container do item
    local item = mw.html.create('div'):addClass('notice-item')
    if has(color) then
        item:css('--notice-color', color)
    end

    -- preparar ícones (inline e overlay), sem link
    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 is_url then
            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)
        elseif is_prefixed then
            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)
        else
            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)
        end
    end

    local content = item:tag('div'):addClass('notice-content'):css('flex', '1')

    -- header com esquerda (ícone+titulo) e direita (data)
    if has(title) or has(date) then
        local header = content:tag('div'):addClass('notice-header')
        local left = header:tag('div'):addClass('notice-header-left')
        local right = header:tag('div'):addClass('notice-header-right')

        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') -- também forço nova aba aqui
                :attr('rel', 'noopener noreferrer'):wikitext(title)
            else
                holder:wikitext(title)
            end
        end

        if has(date) then
            right:tag('span'):addClass('notice-date'):wikitext(date)
        end
    end

    if has(desc) then
        content:tag('p'):addClass('notice-desc'):wikitext(desc)
    end

    if overlay_icon_wikitext then
        item:wikitext(overlay_icon_wikitext)
    end

    return tostring(item)
end

return p