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

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 10: Linha 10:
     end
     end


    -- Para cada item separado por ponto-e-vírgula
     for item in mw.text.gsplit(pointsStr, ";", true) do
     for item in mw.text.gsplit(pointsStr, ";", true) do
         item = mw.text.trim(item)
         item = mw.text.trim(item)
         if item ~= "" then
         if item ~= "" then
             -- Espera cada “item” no formato: X|Y|Descrição|PáginaDestino
             -- Esperamos o formato: X|Y|Descrição|PáginaDestino
             local x, y, desc, target = item:match("^(%d+)|(%d+)|(.+)|(.+)$")
             local x, y, desc, target = item:match("^(%d+)|(%d+)|(.+)|(.+)$")
             if x and y and desc and target then
             if x and y and desc and target then

Edição das 22h56min de 5 de junho de 2025

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

local p = {}

function p.render(frame)
    local args = frame:getParent().args or {}
    local pointsStr = args.points or ""
    local html = mw.html.create()

    if pointsStr == "" then
        return ""
    end

    -- Para cada item separado por ponto-e-vírgula
    for item in mw.text.gsplit(pointsStr, ";", true) do
        item = mw.text.trim(item)
        if item ~= "" then
            -- Esperamos o formato: X|Y|Descrição|PáginaDestino
            local x, y, desc, target = item:match("^(%d+)|(%d+)|(.+)|(.+)$")
            if x and y and desc and target then
                local span = html:tag("span")
                    :addClass("map-point")
                    :css("top", y .. "px")
                    :css("left", x .. "px")

                span:tag("a")
                    :attr("href", mw.title.new(target):getFullText())
                    :wikitext(desc)
                    :done()

                span:tag("span")
                    :addClass("tooltip")
                    :wikitext(desc)
                    :done()
            end
        end
    end

    return tostring(html)
end

return p