Módulo:WeeklyBosses
Ir para navegação
Ir para pesquisar
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