Mudanças entre as edições de "Módulo:Skillbox"
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
local p = {} | local p = {} | ||
-- Converte skill formatada com Nome =, Descrição =, Vídeo = | |||
function parseSkill(text) | function parseSkill(text) | ||
local skill = { nome = '', descricao = '', video = '' } | local skill = { nome = '', descricao = '', video = '' } | ||
for line in mw.text.gsplit(text, '\n', true) do | for line in mw.text.gsplit(text or '', '\n', true) do | ||
local chave, valor = line:match("^%s*(.-)%s*=%s*(.-)%s*$") | local chave, valor = line:match("^%s*(.-)%s*=%s*(.-)%s*$") | ||
if chave and valor then | if chave and valor then | ||
| Linha 22: | Linha 23: | ||
end | end | ||
function | -- Retorna tabela com todas as skills válidas | ||
function getSkills(args) | |||
local skills = {} | local skills = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if type(k) == "string" and k:match("^skill%d*$") and v:find("Nome%s*=") then | if type(k) == "string" and k:match("^skill%d*$") and v:find("Nome%s*=") then | ||
| Linha 31: | Linha 31: | ||
end | end | ||
end | end | ||
return skills | |||
end | |||
-- Gera os botões | |||
function p.renderTabs(frame) | |||
local args = frame:getParent().args | |||
local | local skills = getSkills(args) | ||
local | local html = {} | ||
for i, skill in ipairs(skills) do | for i, skill in ipairs(skills) do | ||
local id = "skill" .. i | local id = "skill" .. i | ||
local class = (i == 1 and "skillbox-tab active" or "skillbox-tab") | |||
table.insert(html, string.format('<button class="%s" data-target="%s">%s</button>', class, id, skill.nome)) | |||
end | |||
return table.concat(html, "\n") | |||
end | |||
-- Gera os blocos com descrição + vídeo | |||
function p.renderPanels(frame) | |||
local args = frame:getParent().args | |||
local skills = getSkills(args) | |||
local html = {} | |||
for i, skill in ipairs(skills) do | |||
local id = "skill" .. i | |||
local class = (i == 1 and "skillbox-panel active" or "skillbox-panel") | |||
local bloco = {} | |||
table.insert(bloco, string.format('<div class="%s" id="%s">', class, id)) | |||
table.insert(bloco, string.format('<div class="skillbox-desc">%s</div>', skill.descricao)) | |||
if skill.video and skill.video ~= "" then | if skill.video and skill.video ~= "" then | ||
local | local videoURL = "https://wiki.gla.com.br/index.php/Special:FilePath/" .. mw.text.trim(skill.video) | ||
table.insert(bloco, string.format([[ | |||
<video class="skillbox-video" controls> | |||
<source src="%s" type="video/mp4"> | |||
</video> | |||
]], videoURL)) | |||
end | |||
table.insert(bloco, '</div>') | |||
table.insert(html, table.concat(bloco, "\n")) | |||
end | end | ||
return | return table.concat(html, "\n") | ||
end | end | ||
return p | return p | ||
Edição das 03h06min de 23 de maio de 2025
A documentação para este módulo pode ser criada em Módulo:Skillbox/doc
local p = {}
-- Converte skill formatada com Nome =, Descrição =, Vídeo =
function parseSkill(text)
local skill = { nome = '', descricao = '', video = '' }
for line in mw.text.gsplit(text or '', '\n', true) do
local chave, valor = line:match("^%s*(.-)%s*=%s*(.-)%s*$")
if chave and valor then
chave = mw.text.trim(chave:lower())
valor = mw.text.trim(valor)
if chave == "nome" then
skill.nome = valor
elseif chave == "descrição" or chave == "descricao" then
skill.descricao = valor
elseif chave == "vídeo" or chave == "video" then
skill.video = valor
end
end
end
return skill
end
-- Retorna tabela com todas as skills válidas
function getSkills(args)
local skills = {}
for k, v in pairs(args) do
if type(k) == "string" and k:match("^skill%d*$") and v:find("Nome%s*=") then
table.insert(skills, parseSkill(v))
end
end
return skills
end
-- Gera os botões
function p.renderTabs(frame)
local args = frame:getParent().args
local skills = getSkills(args)
local html = {}
for i, skill in ipairs(skills) do
local id = "skill" .. i
local class = (i == 1 and "skillbox-tab active" or "skillbox-tab")
table.insert(html, string.format('<button class="%s" data-target="%s">%s</button>', class, id, skill.nome))
end
return table.concat(html, "\n")
end
-- Gera os blocos com descrição + vídeo
function p.renderPanels(frame)
local args = frame:getParent().args
local skills = getSkills(args)
local html = {}
for i, skill in ipairs(skills) do
local id = "skill" .. i
local class = (i == 1 and "skillbox-panel active" or "skillbox-panel")
local bloco = {}
table.insert(bloco, string.format('<div class="%s" id="%s">', class, id))
table.insert(bloco, string.format('<div class="skillbox-desc">%s</div>', skill.descricao))
if skill.video and skill.video ~= "" then
local videoURL = "https://wiki.gla.com.br/index.php/Special:FilePath/" .. mw.text.trim(skill.video)
table.insert(bloco, string.format([[
<video class="skillbox-video" controls>
<source src="%s" type="video/mp4">
</video>
]], videoURL))
end
table.insert(bloco, '</div>')
table.insert(html, table.concat(bloco, "\n"))
end
return table.concat(html, "\n")
end
return p