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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
 
(10 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
--[[
Módulo:Teste — exemplo didático (colar na página Módulo:Teste).
Uso: {{Teste|titulo=...|texto=...}}
]]
local p = {}
local p = {}


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local cards = {}
     local titulo = mw.text.trim(args.titulo or '')
 
    local texto = mw.text.trim(args.texto or '')
    local i = 1
    if titulo == '' then
    while true do
         titulo = 'Sem título'
        local nome = args['nome' .. i]
     end
        if not nome or mw.text.trim(nome) == '' then break end
 
        local link  = mw.text.trim(args['link' .. i] or '')
        local img    = mw.text.trim(args['img'  .. i] or '')
        local qtd    = mw.text.trim(args['qtd'  .. i] or '0')
        local bau    = mw.text.trim(args['bau' .. i] or 'comum')
        local bauImg = bau == 'ouro' and 'Chest_gold.png' or 'Chest_normal.png'
 
        local imgHtml  = frame:preprocess('[[File:' .. img    .. '|150px|link=]]')
         local bauHtml  = frame:preprocess('[[File:' .. bauImg .. '|link=]]')
        local href     = tostring(mw.uri.localUrl(link))
 
        local card =
            '<a class="island-card" href="' .. href .. '">' ..
            '<span class="island-img">'    .. imgHtml  .. '</span>' ..
            '<span class="island-name">'  .. nome    .. '</span>' ..
            '<span class="island-chests">' .. qtd .. ' ' .. bauHtml .. '</span>' ..
            '</a>'


         cards[#cards+1] = card
    local root = mw.html.create('div'):addClass('teste-caixa')
         i = i + 1
    root:tag('h3'):wikitext(titulo)
    end
    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 '<div class="island-grid">' .. table.concat(cards) .. '</div>'
     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