Module:NonCombatPet

From August Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:NonCombatPet/doc

-- Module:NonCombatPet
local p = {}
-- Main function to generate the pet effects table
function p.main(frame)
    local args = frame.args
    -- Start building the table HTML
    local html = [[
<table class="wikitable sortable align-left-2 jquery-tablesorter" style="text-align:center;">
  <tr>
    <th colspan="2" class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Pet</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Source</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Effect</th>
  </tr>
]]
    -- Generate rows dynamically
    local index = 1
    while args['pet' .. index] do
        -- Get parameters for this pet
        local pet = args['pet' .. index] or ''
        local image = args['image' .. index] or ''
        local source = args['source' .. index] or ''
        local effect = args['effect' .. index] or ''
        
        -- Skip empty entries
        if pet ~= '' then
            -- Build the row HTML
            html = html .. '  <tr>\n'
            
            -- Image cell
            html = html .. '    <td class="plinkt-image">'
            if image ~= '' then
                html = html .. '[[File:' .. image .. '|center|32px]]'
            end
            html = html .. '</td>\n'
            
            -- Pet name cell
            html = html .. '    <td>' .. pet .. '</td>\n'
            
            -- Source cell
            html = html .. '    <td>' .. source .. '</td>\n'
            
            -- Effect cell
            html = html .. '    <td>' .. effect .. '</td>\n'
            
            html = html .. '  </tr>\n'
        end
        
        -- Move to next index
        index = index + 1
    end
    
    -- Close the table
    html = html .. '</table>'
    return html
end
-- Function to render HTML from template-style parameters
function p.render(frame)
    -- Get all arguments from parent template
    local parentArgs = frame:getParent().args
    return p.main({args = parentArgs})
end
return p