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

De Wiki Gla
Ir para navegação Ir para pesquisar
(Criou página com 'local p = {} function p.render(frame) local args = frame:getParent().args local nome = mw.text.trim(args['nome'] or '') local root = mw.html.create('div'):attr('...')
 
Linha 5: Linha 5:
     local nome = mw.text.trim(args['nome'] or '')
     local nome = mw.text.trim(args['nome'] or '')


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


    -- Título
     if nome ~= '' then
     if nome ~= '' then
         root:tag('div'):attr('class','lk-titulo'):wikitext(nome)
         root:tag('div'):attr('class', 'lk-titulo'):wikitext(nome)
     end
     end


     -- Coleta baús existentes
     -- coleta baús (para no primeiro bauNtipo ausente)
     local baus = {}
     local baus = {}
     local i = 1
     local i = 1
     while true do
     while true do
         local tipo = mw.text.trim(args['bau'..i..'tipo'] or '')
         local tipo = mw.text.trim(args['bau' .. i .. 'tipo'] or '')
         if tipo == '' then break end
         if tipo == '' then break end
         baus[#baus+1] = i
         baus[#baus + 1] = i
         i = i + 1
         i = i + 1
     end
     end


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


     -- Tabs
     -- tabs
     local tabs = root:tag('div'):attr('class','lk-tabs')
     local tabs = root:tag('div'):attr('class', 'lk-tabs')
     for idx, n in ipairs(baus) do
     for idx, n in ipairs(baus) do
         local tab = tabs:tag('span')
         tabs:tag('span')
             :attr('class', idx == 1 and 'lk-tab active' or 'lk-tab')
             :attr('class', idx == 1 and 'lk-tab active' or 'lk-tab')
             :attr('data-tab', 'b'..n)
             :attr('data-tab', 'b' .. n)
             :wikitext('Baú '..string.format('%02d', n))
             :wikitext('Baú ' .. string.format('%02d', n))
     end
     end


     -- Painéis
     -- painéis
     for idx, n in ipairs(baus) do
     for idx, n in ipairs(baus) do
         local prefix = 'bau'..n
         local px    = 'bau' .. n
         local tipo  = mw.text.trim(args[prefix..'tipo'] or '')
         local tipo  = mw.text.trim(args[px .. 'tipo']   or '')
         local img    = mw.text.trim(args[prefix..'img'] or '')
         local img    = mw.text.trim(args[px .. 'img']   or '')
         local video  = mw.text.trim(args[prefix..'video']   or '')
         local video  = mw.text.trim(args[px .. 'video'] or '')
         local imagem = mw.text.trim(args[prefix..'imagem'] or '')
         local imagem = mw.text.trim(args[px .. 'imagem'] or '')


         local panel = root:tag('div')
         local panel = root:tag('div')
             :attr('class', idx == 1 and 'lk-panel active' or 'lk-panel')
             :attr('class', idx == 1 and 'lk-panel active' or 'lk-panel')
             :attr('data-panel', 'b'..n)
             :attr('data-panel', 'b' .. n)


         -- Coluna esquerda
         -- esquerda
         local left = panel:tag('div'):attr('class','lk-left')
         local left = panel:tag('div'):attr('class', 'lk-left')
         local baubox = left:tag('div'):attr('class','lk-bau-box')
         local baubox = left:tag('div'):attr('class', 'lk-bau-box')
         if img ~= '' then
         if img ~= '' then
             baubox:tag('img'):attr('src',img):attr('alt','baú')
             baubox:tag('img'):attr('src', img):attr('alt', 'baú')
         end
         end
         left:tag('span'):attr('class','lk-badge '..tipo):wikitext(tipo)
         left:tag('span'):attr('class', 'lk-badge ' .. tipo):wikitext(tipo)


         -- Coluna direita
         -- direita
         local right = panel:tag('div'):attr('class','lk-right')
         local right = panel:tag('div'):attr('class', 'lk-right')


         -- Recompensas
         -- recompensas
         local rewardSec = right:tag('div')
         local rsec = right:tag('div')
         rewardSec:tag('div'):attr('class','lk-slabel'):wikitext('Recompensas')
         rsec:tag('div'):attr('class', 'lk-slabel'):wikitext('Recompensas')
         local grid = rewardSec:tag('div'):attr('class','lk-rewards')
         local grid = rsec:tag('div'):attr('class', 'lk-rewards')


         local j = 1
         local j = 1
         while true do
         while true do
             local qty   = mw.text.trim(args[prefix..'reward'..j]   or '')
             local qty = mw.text.trim(args[px .. 'reward'   .. j] or '')
             local rimg   = mw.text.trim(args[prefix..'rewardimg'..j] or '')
             local rimg = mw.text.trim(args[px .. 'rewardimg' .. j] or '')
             if qty == '' and rimg == '' then break end
             if qty == '' and rimg == '' then break end
             local item = grid:tag('div'):attr('class','lk-reward')
             local item   = grid:tag('div'):attr('class', 'lk-reward')
             local sprite = item:tag('div'):attr('class','lk-rsprite')
             local sprite = item:tag('div'):attr('class', 'lk-rsprite')
             if rimg ~= '' then
             if rimg ~= '' then
                 sprite:tag('img'):attr('src',rimg):attr('alt','')
                 sprite:tag('img'):attr('src', rimg):attr('alt', '')
             end
             end
             if qty ~= '' then
             if qty ~= '' then
                 item:tag('span'):attr('class','lk-rqty'):wikitext(qty)
                 item:tag('span'):attr('class', 'lk-rqty'):wikitext(qty)
             end
             end
             j = j + 1
             j = j + 1
         end
         end


         -- Mídia
         -- mídia
         if video ~= '' or imagem ~= '' then
         if video ~= '' or imagem ~= '' then
             right:tag('div'):attr('class','lk-divider')
             right:tag('div'):attr('class', 'lk-divider')
             local mediaSec = right:tag('div')
             local msec = right:tag('div')
             mediaSec:tag('div'):attr('class','lk-slabel'):wikitext('Como chegar')
             msec:tag('div'):attr('class', 'lk-slabel'):wikitext('Como chegar')
             local wrap = mediaSec:tag('div'):attr('class','lk-media-wrap')
             local mwrap = msec:tag('div'):attr('class', 'lk-media-wrap')
             if video ~= '' then
             if video ~= '' then
                 wrap:tag('iframe')
                 mwrap:tag('iframe')
                     :attr('src','https://www.youtube.com/embed/'..video)
                     :attr('src', 'https://www.youtube.com/embed/' .. video)
                     :attr('allowfullscreen','')
                     :attr('allowfullscreen', '')
                     :wikitext('')
                     :wikitext('')
             else
             else
                 wrap:tag('img'):attr('src',imagem):attr('alt','como chegar')
                 mwrap:tag('img'):attr('src', imagem):attr('alt', 'como chegar')
             end
             end
         end
         end

Edição das 18h38min de 16 de março de 2026

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

local p = {}

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', 'lk-wrap')

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

    -- coleta baús (para no primeiro bauNtipo ausente)
    local baus = {}
    local i = 1
    while true do
        local tipo = mw.text.trim(args['bau' .. i .. 'tipo'] or '')
        if tipo == '' then break end
        baus[#baus + 1] = i
        i = i + 1
    end

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

    -- tabs
    local tabs = root:tag('div'):attr('class', 'lk-tabs')
    for idx, n in ipairs(baus) do
        tabs:tag('span')
            :attr('class', idx == 1 and 'lk-tab active' or 'lk-tab')
            :attr('data-tab', 'b' .. n)
            :wikitext('Baú ' .. string.format('%02d', n))
    end

    -- painéis
    for idx, n in ipairs(baus) do
        local px     = 'bau' .. n
        local tipo   = mw.text.trim(args[px .. 'tipo']   or '')
        local img    = mw.text.trim(args[px .. 'img']    or '')
        local video  = mw.text.trim(args[px .. 'video']  or '')
        local imagem = mw.text.trim(args[px .. 'imagem'] or '')

        local panel = root:tag('div')
            :attr('class', idx == 1 and 'lk-panel active' or 'lk-panel')
            :attr('data-panel', 'b' .. n)

        -- esquerda
        local left = panel:tag('div'):attr('class', 'lk-left')
        local baubox = left:tag('div'):attr('class', 'lk-bau-box')
        if img ~= '' then
            baubox:tag('img'):attr('src', img):attr('alt', 'baú')
        end
        left:tag('span'):attr('class', 'lk-badge ' .. tipo):wikitext(tipo)

        -- direita
        local right = panel:tag('div'):attr('class', 'lk-right')

        -- recompensas
        local rsec = right:tag('div')
        rsec:tag('div'):attr('class', 'lk-slabel'):wikitext('Recompensas')
        local grid = rsec:tag('div'):attr('class', 'lk-rewards')

        local j = 1
        while true do
            local qty  = mw.text.trim(args[px .. 'reward'    .. j] or '')
            local rimg = mw.text.trim(args[px .. 'rewardimg' .. j] or '')
            if qty == '' and rimg == '' then break end
            local item   = grid:tag('div'):attr('class', 'lk-reward')
            local sprite = item:tag('div'):attr('class', 'lk-rsprite')
            if rimg ~= '' then
                sprite:tag('img'):attr('src', rimg):attr('alt', '')
            end
            if qty ~= '' then
                item:tag('span'):attr('class', 'lk-rqty'):wikitext(qty)
            end
            j = j + 1
        end

        -- mídia
        if video ~= '' or imagem ~= '' then
            right:tag('div'):attr('class', 'lk-divider')
            local msec = right:tag('div')
            msec:tag('div'):attr('class', 'lk-slabel'):wikitext('Como chegar')
            local mwrap = msec:tag('div'):attr('class', 'lk-media-wrap')
            if video ~= '' then
                mwrap:tag('iframe')
                    :attr('src', 'https://www.youtube.com/embed/' .. video)
                    :attr('allowfullscreen', '')
                    :wikitext('')
            else
                mwrap:tag('img'):attr('src', imagem):attr('alt', 'como chegar')
            end
        end
    end

    return tostring(root)
end

return p