Mudanças entre as edições de "Módulo:WeeklyBosses"
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. | ||
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 | -- Parâmetros: do #invoke (frame.args) ou da predefinição que chama o invoke (getParent().args) | ||
local parent = | 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 | -- Imagem: só wikitext com |link= vazio; preprocess para renderizar | ||
local conteudo | |||
local | |||
if img ~= '' then | 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 | else | ||
conteudo = mw.text.encode(nome, 'entity') | |||
end | end | ||
-- | -- URL completa no Lua para o redirect não depender do JS da wiki | ||
local | local uri = mw.uri.fullUrl(link) | ||
table.insert(out, '<div class="weekly-bosses__btn" data-background="' .. bg .. '">' .. | 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