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

De Wiki Gla
Ir para navegação Ir para pesquisar
Etiqueta: Revertido
m
 
(80 revisões intermediárias por 3 usuários não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
--[[
local itemData = require("Módulo:ItemData")
Módulo:Teste — exemplo didático (colar na página Módulo:Teste).


-- Parser dos itens estilo "nome:quantidade"
Uso: {{Teste|titulo=...|texto=...}}
local function parseItens(raw)
]]
    local resultado = {}
    for item in mw.text.gsplit(raw or "", ",", true) do
        local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
        if nome and qtd then
            nome = mw.text.trim(nome)
            if not nome:match("%.png$") and not nome:match("%.gif$") and not nome:match("%.jpg$") and not nome:match("%.webp$") then
                nome = nome .. ".png"
            end
            qtd = tonumber(qtd) or 0
            resultado[nome] = (resultado[nome] or 0) + qtd
        end
    end
    return resultado
end


-- Junta várias listas de recompensas
local p = {}
local function mergeRecompensas(lista)
    local total = {}
    for _, raw in ipairs(lista) do
        local dados = parseItens(raw)
        for nome, qtd in pairs(dados) do
            total[nome] = (total[nome] or 0) + qtd
        end
    end
    return total
end


-- Formata número com milhar
function p.main(frame)
local function formatNumber(n)
     local args = frame:getParent().args
     local s = tostring(n)
     local titulo = mw.text.trim(args.titulo or '')
    local result = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
     local texto = mw.text.trim(args.texto or '')
    return result:gsub("^,", "")
    if titulo == '' then
end
         titulo = 'Sem título'
 
function p.total(frame)
     local content = mw.title.getCurrentTitle():getContent()
     local rewardCalls = {}
 
    for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
        local itens = bloco:match("itens%s*=%s*([^|}]+)")
        if itens then
            table.insert(rewardCalls, itens)
         end
     end
     end


     local total = mergeRecompensas(rewardCalls)
     local root = mw.html.create('div'):addClass('teste-caixa')
    local html = mw.html.create("div"):addClass("reward-items")
     root:tag('h3'):wikitext(titulo)
 
    root:tag('p')
     for nome, qtd in pairs(total) do
        :addClass('teste-corpo')
        local data = itemData[nome] or {}
         :addClass('teste-colapsado')
        local nomeCompleto = data.nome or nome
         :wikitext(texto)
        local desc = data.desc
    -- <button> na saída do #invoke costuma ser escapado pelo sanitizer; usar span + role (igual data-href no lugar de <a>)
        local tooltip = nomeCompleto
    root:tag('span')
        if desc and desc ~= "" then
        :addClass('teste-toggle')
            tooltip = tooltip .. "\n—\n" .. desc
        :attr('role', 'button')
        end
        :attr('tabindex', '0')
 
        :wikitext('Expandir')
        local wrapper = html:tag("span"):addClass("item-wrapper")
         wrapper:attr("data-tooltip", tooltip)
 
         wrapper:tag("span")
            :wikitext(string.format("[[Arquivo:%s|link=]]", nome))
 
        wrapper:tag("span")
            :addClass("item-count")
            :wikitext((nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd))
    end


     return tostring(html)
     return tostring(root)
end
end


return p
return p

Edição atual tal como às 00h23min de 1 de abril de 2026

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

--[[
Módulo:Teste — exemplo didático (colar na página Módulo:Teste).

Uso: {{Teste|titulo=...|texto=...}}
]]

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local titulo = mw.text.trim(args.titulo or '')
    local texto = mw.text.trim(args.texto or '')
    if titulo == '' then
        titulo = 'Sem título'
    end

    local root = mw.html.create('div'):addClass('teste-caixa')
    root:tag('h3'):wikitext(titulo)
    root:tag('p')
        :addClass('teste-corpo')
        :addClass('teste-colapsado')
        :wikitext(texto)
    -- <button> na saída do #invoke costuma ser escapado pelo sanitizer; usar span + role (igual data-href no lugar de <a>)
    root:tag('span')
        :addClass('teste-toggle')
        :attr('role', 'button')
        :attr('tabindex', '0')
        :wikitext('Expandir')

    return tostring(root)
end

return p