Módulo:Lari1

De Wiki Gla
Revisão de 03h04min de 17 de março de 2026 por Larifk (discussão | contribs)
Ir para navegação Ir para pesquisar

A documentação para este módulo pode ser criada em Módulo:Lari1/doc

local p = {}

local VIDEO_EXTS = { mp4 = true, webm = true, ogv = true }

local function detectMedia(valor)
    if not valor or valor == '' then return nil, nil end
    local ext = valor:match('%.(%w+)$')
    if ext and VIDEO_EXTS[ext:lower()] then
        return 'video', valor
    end
    return 'youtube', valor
end

function p.render(frame)
    local args = frame:getParent().args
    local nome = mw.text.trim(args['nome'] or '')

    local root = mw.html.create('div'):attr('class', 'sv-wrap')

    root:tag('span'):attr('class', 'tema-btn'):wikitext('☾ Dark')

    if nome ~= '' then
        root:tag('div'):attr('class', 'sv-titulo'):wikitext(nome)
    end

    local skills = {}
    local i = 1
    while true do
        local titulo = mw.text.trim(args['skill' .. i .. 'titulo'] or '')
        if titulo == '' then break end
        skills[#skills + 1] = i
        i = i + 1
    end

    if #skills == 0 then return tostring(root) end

    local box = root:tag('div'):attr('class', 'sv-box')

    local tabbar = box:tag('div'):attr('class', 'sv-tabs')
    for idx, n in ipairs(skills) do
        local img = mw.text.trim(args['skill' .. n .. 'img'] or '')
        local tab = tabbar:tag('span')
            :attr('class', idx == 1 and 'sv-tab active' or 'sv-tab')
            :attr('data-skill', tostring(n))
        if img ~= '' then
            tab:node(mw.html.create(''):wikitext('[[File:' .. img .. '|32px|link=]]'))
        else
            tab:wikitext(tostring(n))
        end
    end

    for idx, n in ipairs(skills) do
        local px     = 'skill' .. n
        local titulo = mw.text.trim(args[px .. 'titulo'] or '')
        local media  = mw.text.trim(args[px .. 'media']  or '')

        local panel = box:tag('div')
            :attr('class', idx == 1 and 'sv-panel active' or 'sv-panel')
            :attr('data-panel', tostring(n))

        panel:tag('h2'):attr('class', 'sv-skill-titulo'):wikitext(titulo)

        local descsec = panel:tag('div'):attr('class', 'sv-desc')
        local j = 1
        while true do
            local desc = mw.text.trim(args[px .. 'desc' .. j] or '')
            if desc == '' then break end
            descsec:tag('p'):wikitext(desc)
            j = j + 1
        end

        local tipo, valor = detectMedia(media)
        if tipo == 'youtube' then
            panel:tag('div')
                :attr('class', 'sv-media')
                :attr('data-youtube', valor)
        elseif tipo == 'video' then
            local mediaDiv = panel:tag('div'):attr('class', 'sv-media')
            mediaDiv:tag('video')
                :attr('data-wikivideo', valor)
                :attr('controls', '')
                :attr('loop', '')
                :attr('muted', '')
                :wikitext('')
        end
    end

    return tostring(root)
end

return p