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)
         local trimmed = mw.text.trim(item)
         if item ~= "" then
         if trimmed ~= "" then
             -- Esperamos o formato: X|Y|Descrição|PáginaDestino
             -- agora permitimos espaços ao redor de cada parte
             local x, y, desc, target = item:match("^(%d+)|(%d+)|(.+)|(.+)$")
             local x, y, desc, target = trimmed:match("^%s*(%d+)%s*|%s*(%d+)%s*|%s*(.-)%s*|%s*(.-)%s*$")
             if x and y and desc and target then
             if x and y and desc and target then
                 local span = html:tag("span")
                 local span = html:tag("span")
Linha 22: Linha 21:
                     :css("left", x .. "px")
                     :css("left", x .. "px")


                -- link vazio cobrindo o ponto
                 span:tag("a")
                 span:tag("a")
                     :attr("href", mw.title.new(target):getFullText())
                     :attr("href", mw.title.new(target):getFullText())
                     :wikitext(desc)
                     :wikitext(""):done()
                    :done()


                -- tooltip com o texto
                 span:tag("span")
                 span:tag("span")
                     :addClass("tooltip")
                     :addClass("tooltip")

Edição das 23h02min 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

    for item in mw.text.gsplit(pointsStr, ";", true) do
        local trimmed = mw.text.trim(item)
        if trimmed ~= "" then
            -- agora permitimos espaços ao redor de cada parte
            local x, y, desc, target = trimmed:match("^%s*(%d+)%s*|%s*(%d+)%s*|%s*(.-)%s*|%s*(.-)%s*$")
            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")

                -- link vazio cobrindo o ponto
                span:tag("a")
                    :attr("href", mw.title.new(target):getFullText())
                    :wikitext(""):done()

                -- tooltip com o texto
                span:tag("span")
                    :addClass("tooltip")
                    :wikitext(desc)
                    :done()
            end
        end
    end

    return tostring(html)
end

return p