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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 1: Linha 1:
--[[
--[[
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Imagem com |link= vazio para não ir para a página do arquivo; link e nome em wikitext.
Args vêm do #invoke (frame.args). data-href com URL completa para o redirect funcionar.
]]
]]


Linha 7: Linha 7:


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args or {}
    -- Parâmetros: do #invoke (frame.args) ou da predefinição que chama o invoke (getParent().args)
     local parent = frame:getParent()
     local parentFrame = frame:getParent()
    local args = frame.args or (parentFrame and parentFrame.args) or {}
     local parent = parentFrame
     local out = {}
     local out = {}


Linha 20: Linha 22:
         local nome = (txt ~= '' and txt or link)
         local nome = (txt ~= '' and txt or link)


         -- Imagem com |link= vazio para não abrir página do arquivo (como em characters)
         -- Imagem: só wikitext com |link= vazio; preprocess para renderizar
        -- Link da wiki: [[página|conteúdo]]. Conteúdo = imagem (sem link) + nome
         local conteudo
         local display
         if img ~= '' then
         if img ~= '' then
             display = '[[Arquivo:' .. img .. '|48px|link=]]<br/>' .. nome
             local imgWikitext = '[[Arquivo:' .. img .. '|48px|link=]]'
            local imgHtml = (parent or frame):preprocess(imgWikitext)
            conteudo = imgHtml .. '<br/>' .. mw.text.encode(nome, 'entity')
         else
         else
             display = nome
             conteudo = mw.text.encode(nome, 'entity')
         end
         end
        local linkWikitext = '[[' .. link .. '|' .. display .. ']]'


         -- Preprocess para o parser interpretar o wikitext (link e imagem)
         -- URL completa no Lua para o redirect não depender do JS da wiki
         local parsed = parent:preprocess(linkWikitext)
        local uri = mw.uri.fullUrl(link)
         table.insert(out, '<div class="weekly-bosses__btn" data-background="' .. bg .. '">' .. parsed .. '</div>')
         local href = (type(uri) == 'string') and uri or tostring(uri)
 
         table.insert(out,
            '<div class="weekly-bosses__btn" data-background="' .. mw.text.encode(bg, 'entity') ..
            '" data-link="' .. mw.text.encode(link, 'entity') ..
            '" data-href="' .. mw.text.encode(href, 'entity') .. '">' ..
            conteudo .. '</div>')
     end
     end



Edição das 04h01min de 22 de fevereiro de 2026

A documentação para este módulo pode ser criada em Módulo:WeeklyBosses/doc

--[[
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Args vêm do #invoke (frame.args). data-href com URL completa para o redirect funcionar.
]]

local p = {}

function p.main(frame)
    -- Parâmetros: do #invoke (frame.args) ou da predefinição que chama o invoke (getParent().args)
    local parentFrame = frame:getParent()
    local args = frame.args or (parentFrame and parentFrame.args) or {}
    local parent = parentFrame
    local out = {}

    for i = 1, 10 do
        local link = mw.text.trim(args['linkbtn' .. i] or '')
        if link == '' then break end

        local txt = mw.text.trim(args['txtbtn' .. i] or '')
        local img = mw.text.trim(args['imgbtn' .. i] or '')
        local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
        local nome = (txt ~= '' and txt or link)

        -- Imagem: só wikitext com |link= vazio; preprocess para renderizar
        local conteudo
        if img ~= '' then
            local imgWikitext = '[[Arquivo:' .. img .. '|48px|link=]]'
            local imgHtml = (parent or frame):preprocess(imgWikitext)
            conteudo = imgHtml .. '<br/>' .. mw.text.encode(nome, 'entity')
        else
            conteudo = mw.text.encode(nome, 'entity')
        end

        -- URL completa no Lua para o redirect não depender do JS da wiki
        local uri = mw.uri.fullUrl(link)
        local href = (type(uri) == 'string') and uri or tostring(uri)

        table.insert(out,
            '<div class="weekly-bosses__btn" data-background="' .. mw.text.encode(bg, 'entity') ..
            '" data-link="' .. mw.text.encode(link, 'entity') ..
            '" data-href="' .. mw.text.encode(href, 'entity') .. '">' ..
            conteudo .. '</div>')
    end

    return '<div class="weekly-bosses">' .. table.concat(out) .. '</div>'
end

return p