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:
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.main(frame)
  Requer a extensão Scribunto e o widget {{#widget:ReportModal|...}} registrado.
    local args = frame:getParent().args
]]
    local cards = {}


    local i = 1
local p = {}
    while true do
        local nome = args['nome' .. i]
        if not nome or mw.text.trim(nome) == '' then break end


        local link = mw.text.trim(args['link' .. i] or '')
function p.embed(frame)
        local img  = mw.text.trim(args['img'  .. i] or '')
local pargs = (frame:getParent() and frame:getParent().args) or {}
        local qtd  = mw.text.trim(args['qtd'  .. i] or '0')
local args = frame.args or {}
        local bau  = mw.text.trim(args['bau'  .. i] or 'comum')
local base = (
        local bauImg = bau == 'ouro' and 'Chest_gold.png' or 'Chest_normal.png'
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 parts = {}
local heading = args.heading or pargs.heading or ""
        parts[#parts+1] = '|nome='  .. nome
local wid = args.wid or pargs.wid or ""
        parts[#parts+1] = '|link='  .. link
        parts[#parts+1] = '|img='    .. img
        parts[#parts+1] = '|qtd='    .. qtd
        parts[#parts+1] = '|bauimg=' .. bauImg


        cards[#cards+1] = frame:preprocess('{{#widget:Teste' .. table.concat(parts) .. '}}')
local wikitext = "{{#widget:ReportModal|api_base=" .. base
        i = i + 1
if heading ~= "" then
    end
wikitext = wikitext .. "|heading=" .. heading
end
if wid ~= "" then
wikitext = wikitext .. "|wid=" .. wid
end
wikitext = wikitext .. "}}"


    return '<div class="island-grid">' .. table.concat(cards) .. '</div>'
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