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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
 
(94 revisões intermediárias por 3 usuários não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
--[[
  Módulo: opcional para inserir o widget via {{#invoke}}.
 
  Na wiki: criar página Módulo:GlaReportEmbed com este código.
 
  Uso num modelo ou página:
    {{#invoke:GlaReportEmbed|embed|api_base=https://teu-deploy.com}}
 
  Parâmetros nomeados (opcionais):
    |heading=Título da caixa
    |wid=2


function p.render(frame)
  Requer a extensão Scribunto e o widget {{#widget:ReportModal|...}} registrado.
    local args = frame:getParent().args or {}
]]
    local pointsStr = args.points or ""
    local html = mw.html.create()


    if pointsStr == "" then
local p = {}
        return ""
    end


    -- Para cada item separado por ponto-e-vírgula
function p.embed(frame)
    for item in mw.text.gsplit(pointsStr, ";", true) do
local pargs = (frame:getParent() and frame:getParent().args) or {}
        item = mw.text.trim(item)
local args = frame.args or {}
        if item ~= "" then
local base = (
            -- Esperamos o formato: X|Y|Descrição|PáginaDestino
args.api_base
            local x, y, desc, target = item:match("^(%d+)|(%d+)|(.+)|(.+)$")
or pargs.api_base
            if x and y and desc and target then
or args[1]
                local span = html:tag("span")
or pargs[1]
                    :addClass("map-point")
or ""
                    :css("top", y .. "px")
):gsub("^%s+", ""):gsub("%s+$", "")
                    :css("left", x .. "px")
if base == "" then
return '<span class="error">GlaReportEmbed: falta <code>api_base</code>.</span>'
end


                span:tag("a")
local heading = args.heading or pargs.heading or ""
                    :attr("href", mw.title.new(target):getFullText())
local wid = args.wid or pargs.wid or ""
                    :wikitext(desc)
                    :done()


                span:tag("span")
local wikitext = "{{#widget:ReportModal|api_base=" .. base
                    :addClass("tooltip")
if heading ~= "" then
                    :wikitext(desc)
wikitext = wikitext .. "|heading=" .. heading
                    :done()
end
            end
if wid ~= "" then
        end
wikitext = wikitext .. "|wid=" .. wid
    end
end
wikitext = wikitext .. "}}"


    return tostring(html)
return frame:preprocess(wikitext)
end
end


return p
return p

Edição atual tal como às 16h07min de 28 de abril de 2026

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

--[[
  Módulo: opcional para inserir o widget via {{#invoke}}.

  Na wiki: criar página Módulo:GlaReportEmbed com este código.

  Uso num modelo ou página:
    {{#invoke:GlaReportEmbed|embed|api_base=https://teu-deploy.com}}

  Parâmetros nomeados (opcionais):
    |heading=Título da caixa
    |wid=2

  Requer a extensão Scribunto e o widget {{#widget:ReportModal|...}} registrado.
]]

local p = {}

function p.embed(frame)
	local pargs = (frame:getParent() and frame:getParent().args) or {}
	local args = frame.args or {}
	local base = (
		args.api_base
		or pargs.api_base
		or args[1]
		or pargs[1]
		or ""
	):gsub("^%s+", ""):gsub("%s+$", "")
	if base == "" then
		return '<span class="error">GlaReportEmbed: falta <code>api_base</code>.</span>'
	end

	local heading = args.heading or pargs.heading or ""
	local wid = args.wid or pargs.wid or ""

	local wikitext = "{{#widget:ReportModal|api_base=" .. base
	if heading ~= "" then
		wikitext = wikitext .. "|heading=" .. heading
	end
	if wid ~= "" then
		wikitext = wikitext .. "|wid=" .. wid
	end
	wikitext = wikitext .. "}}"

	return frame:preprocess(wikitext)
end

return p