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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
 
(97 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.


function p.render(frame)
  Uso num modelo ou página:
     local args = frame:getParent().args or {}
     {{#invoke:GlaReportEmbed|embed|api_base=https://teu-deploy.com}}
    local nomeImagem = args.imagem or ""
    local pontosStr = args.pontos or ""


    if nomeImagem == "" then
  Parâmetros nomeados (opcionais):
        return mw.html.create("div")
    |heading=Título da caixa
            :css("color", "red")
     |wid=2
            :wikitext("Erro: imagem não informado em Módulo:Teste.")
            :allDone()
     end


    local container = mw.html.create("div")
  Requer a extensão Scribunto e o widget {{#widget:ReportModal|...}} registrado.
]]


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


    for ponto in mw.text.gsplit(pontosStr, ";", true) do
function p.embed(frame)
        ponto = mw.text.trim(ponto)
local pargs = (frame:getParent() and frame:getParent().args) or {}
        if ponto ~= "" then
local args = frame.args or {}
            local x, y, descricao, alvo = ponto:match("^%s*(%d+)%s*|%s*(%d+)%s*|%s*(.-)%s*|%s*(.-)%s*$")
local base = (
            if x and y and descricao and alvo then
args.api_base
                local pointSpan = container:tag("span")
or pargs.api_base
                    :addClass("map-point")
or args[1]
                    :css("top", y .. "px")
or pargs[1]
                    :css("left", x .. "px")
or ""
):gsub("^%s+", ""):gsub("%s+$", "")
if base == "" then
return '<span class="error">GlaReportEmbed: falta <code>api_base</code>.</span>'
end


                pointSpan:tag("a")
local heading = args.heading or pargs.heading or ""
                    :attr("href", mw.title.makeTitle(0, alvo):getFullText())
local wid = args.wid or pargs.wid or ""
                    :wikitext("")
                    :done()


                pointSpan:tag("span")
local wikitext = "{{#widget:ReportModal|api_base=" .. base
                    :addClass("tooltip")
if heading ~= "" then
                    :wikitext(descricao)
wikitext = wikitext .. "|heading=" .. heading
                    :done()
end
            else
if wid ~= "" then
                container:tag("div")
wikitext = wikitext .. "|wid=" .. wid
                    :css("color", "red")
end
                    :wikitext("Parâmetro de ponto inválido: <code>" .. ponto .. "</code>")
wikitext = wikitext .. "}}"
                    :done()
            end
        end
    end


    return tostring(container)
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