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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
 
(13 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 = {}
local BAU_COMUM = 'https://i.imgur.com/URL_COMUM'
local BAU_OURO  = 'https://i.imgur.com/URL_OURO'


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
 
     local titulo = mw.text.trim(args.titulo or '')
    local cards = {}
    local texto = mw.text.trim(args.texto or '')
 
    if titulo == '' then
     local i = 1
         titulo = 'Sem título'
    while true do
        local nome = args['nome' .. i]
        if not nome or mw.text.trim(nome) == '' then break end
 
        local link = args['link' .. i] or ''
        local img  = args['img'  .. i] or ''
        local qtd  = args['qtd'  .. i] or '0'
        local bau  = mw.text.trim(args['bau' .. i] or 'comum')
 
        local bauSrc = bau == 'ouro' and BAU_OURO or BAU_COMUM
 
        local imgFile = mw.getCurrentFrame():callParserFunction(
            '#tag', 'span',
            frame:preprocess('[[File:' .. img .. '|150px|link=' .. link .. ']]')
        )
 
        local card = mw.html.create('a')
            :addClass('island-card')
            :attr('href', tostring(mw.uri.localUrl(link)))
 
        card:tag('span')
            :addClass('island-img')
            :wikitext('[[File:' .. img .. '|150px|link=]]')
 
         card:tag('span')
            :addClass('island-name')
            :wikitext(link ~= '' and '[[' .. link .. '|' .. nome .. ']]' or nome)
 
        card:tag('span')
            :addClass('island-chests')
            :wikitext(qtd .. ' [[File:' .. (bau == 'ouro' and 'Chest_gold.png' or 'Chest_normal.png') .. '|link=]]')
 
        cards[#cards + 1] = tostring(card)
        i = i + 1
     end
     end


     local grid = mw.html.create('div')
     local root = mw.html.create('div'):addClass('teste-caixa')
         :addClass('island-grid')
    root:tag('h3'):wikitext(titulo)
         :wikitext(table.concat(cards))
    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(grid)
     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