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

De Wiki Gla
Ir para navegação Ir para pesquisar
Etiqueta: Revertido
m
 
(49 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}}.


function p.render(frame)
  Na wiki: criar página Módulo:GlaReportEmbed com este código.
    local args = frame:getParent().args
    local html = mw.html.create('div')
        :addClass('habilidades-container')


    -- Botões
  Uso num modelo ou página:
     local botoes = html:tag('div'):addClass('habilidades-botoes')
     {{#invoke:GlaReportEmbed|embed|api_base=https://teu-deploy.com}}


    for i = 1, 6 do
  Parâmetros nomeados (opcionais):
        botoes:tag('button')
    |heading=Título da caixa
            :attr('onclick', 'mostrarHabilidade(' .. i .. ')')
     |wid=2
            :wikitext(i)
     end


    -- Conteúdo inicial (habilidade 1)
  Requer a extensão Scribunto e o widget {{#widget:ReportModal|...}} registrado.
    html:tag('h2')
]]
        :attr('id', 'habilidade-titulo')
        :wikitext(args['titulo1'] or '')


    html:tag('div')
local p = {}
        :attr('id', 'habilidade-descricao')
        :wikitext(args['descricao1'] or '')
 
    local video = html:tag('div')
        :addClass('habilidade-video')
 
    video:tag('iframe')
        :attr('id', 'habilidade-video')
        :attr('src', args['video1'] or '')
        :attr('frameborder', '0')
        :attr('allowfullscreen', 'true')
 
    -- Dados JS
    local js = '<script>const habilidades = {'


    for i = 1, 6 do
function p.embed(frame)
        js = js .. i .. ':{' ..
local pargs = (frame:getParent() and frame:getParent().args) or {}
            'titulo:`' .. (args['titulo'..i] or '') .. '`,' ..
local args = frame.args or {}
            'descricao:`' .. (args['descricao'..i] or '') .. '`,' ..
local base = (
            'video:`' .. (args['video'..i] or '') .. '`},'
args.api_base
    end
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


    js = js .. [[};
local heading = args.heading or pargs.heading or ""
local wid = args.wid or pargs.wid or ""


function mostrarHabilidade(n){
local wikitext = "{{#widget:ReportModal|api_base=" .. base
  document.getElementById('habilidade-titulo').innerHTML = habilidades[n].titulo;
if heading ~= "" then
  document.getElementById('habilidade-descricao').innerHTML = habilidades[n].descricao;
wikitext = wikitext .. "|heading=" .. heading
  document.getElementById('habilidade-video').src = habilidades[n].video;
end
}
if wid ~= "" then
</script>]]
wikitext = wikitext .. "|wid=" .. wid
end
wikitext = wikitext .. "}}"


    return tostring(html) .. js
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