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

De Wiki Gla
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 p.exibir(frame)
-- Retorna tabela com todas as skills válidas
    local args = frame:getParent().args
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


    local html = mw.html.create("div")
-- Gera os botões
     html:addClass("skillbox-container")
function p.renderTabs(frame)
 
     local args = frame:getParent().args
     local tabs = html:tag("div"):addClass("skillbox-tabs")
     local skills = getSkills(args)
     local content = html:tag("div"):addClass("skillbox-content")
     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


        tabs:tag("button")
    return table.concat(html, "\n")
            :addClass("skillbox-tab")
end
            :addClass(i == 1 and "active" or "")
            :attr("data-target", id)
            :wikitext(skill.nome or ("Skill " .. i))


        local panel = content:tag("div")
-- Gera os blocos com descrição + vídeo
            :addClass("skillbox-panel")
function p.renderPanels(frame)
            :addClass(i == 1 and "active" or "")
    local args = frame:getParent().args
            :attr("id", id)
    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 = {}


         panel:tag("div")
         table.insert(bloco, string.format('<div class="%s" id="%s">', class, id))
            :addClass("skillbox-desc")
        table.insert(bloco, string.format('<div class="skillbox-desc">%s</div>', skill.descricao))
            :wikitext(skill.descricao or "")


         if skill.video and skill.video ~= "" then
         if skill.video and skill.video ~= "" then
             local src = mw.text.trim(skill.video)
             local videoURL = "https://wiki.gla.com.br/index.php/Special:FilePath/" .. mw.text.trim(skill.video)
             local videoTag = panel:tag("video")
             table.insert(bloco, string.format([[
            videoTag
                 <video class="skillbox-video" controls>
                 :addClass("skillbox-video")
                    <source src="%s" type="video/mp4">
                :attr("controls", "true")
                </video>
            ]], videoURL))
        end


            videoTag:tag("source")
        table.insert(bloco, '</div>')
                :attr("src", "https://wiki.gla.com.br/index.php/Special:FilePath/" .. src)
        table.insert(html, table.concat(bloco, "\n"))
                :attr("type", "video/mp4")
        end
     end
     end


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