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.
Params: imgbtn, txtbtn, linkbtn, bg, imgsize (tamanho em px), imgx/imgy (posição da img: % ou left/center/right e top/center/bottom).
Params: imgbtn, txtbtn, linkbtn, bg. Imagem sem tamanho fixo: usa o tamanho do arquivo.
]]
]]


Linha 20: Linha 20:
         local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
         local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
         local nome = (txt ~= '' and txt or link)
         local nome = (txt ~= '' and txt or link)
        local imgsize = mw.text.trim(args['imgsize' .. i] or args['imgsize'] or '80')
        local imgx = mw.text.trim(args['imgx' .. i] or args['imgx'] or '50%')
        local imgy = mw.text.trim(args['imgy' .. i] or args['imgy'] or '50%')
        if imgsize == '' then imgsize = '80' end
        if imgx == '' then imgx = '50%' end
        if imgy == '' then imgy = '50%' end


         local conteudo
         local conteudo
         if img ~= '' then
         if img ~= '' then
             local imgWikitext = '[[Arquivo:' .. img .. '|' .. imgsize .. 'px|link=]]'
             local imgWikitext = '[[Arquivo:' .. img .. '|link=]]'
             local imgHtml = (parent or frame):preprocess(imgWikitext)
             local imgHtml = (parent or frame):preprocess(imgWikitext)
             conteudo = '<div class="weekly-bosses__btn-img">' .. imgHtml ..
             conteudo = '<div class="weekly-bosses__btn-img">' .. imgHtml ..
Linha 43: Linha 37:
             '" data-link="' .. mw.text.encode(link, 'entity') ..
             '" data-link="' .. mw.text.encode(link, 'entity') ..
             '" data-href="' .. mw.text.encode(href, 'entity') .. '"'
             '" data-href="' .. mw.text.encode(href, 'entity') .. '"'
        if img ~= '' then
            dataAttrs = dataAttrs .. ' data-imgsize="' .. mw.text.encode(imgsize, 'entity') ..
                '" data-imgx="' .. mw.text.encode(imgx, 'entity') ..
                '" data-imgy="' .. mw.text.encode(imgy, 'entity') .. '"'
        end
         table.insert(out, '<div class="weekly-bosses__btn" ' .. dataAttrs .. '>' .. conteudo .. '</div>')
         table.insert(out, '<div class="weekly-bosses__btn" ' .. dataAttrs .. '>' .. conteudo .. '</div>')
     end
     end

Edição das 04h56min 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.
Params: imgbtn, txtbtn, linkbtn, bg. Imagem sem tamanho fixo: usa o tamanho do arquivo.
]]

local p = {}

function p.main(frame)
    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)

        local conteudo
        if img ~= '' then
            local imgWikitext = '[[Arquivo:' .. img .. '|link=]]'
            local imgHtml = (parent or frame):preprocess(imgWikitext)
            conteudo = '<div class="weekly-bosses__btn-img">' .. imgHtml ..
                '</div><div class="weekly-bosses__btn-label">' .. mw.text.encode(nome, 'entity') .. '</div>'
        else
            conteudo = '<div class="weekly-bosses__btn-label">' .. mw.text.encode(nome, 'entity') .. '</div>'
        end

        local uri = mw.uri.fullUrl(link)
        local href = (type(uri) == 'string') and uri or tostring(uri)

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

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

return p