Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Card

From Vault Hunters Official Wiki
Revision as of 06:46, 6 July 2025 by Mnooseman (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame:getParent().args return p._main(args) end function p._main(args) local cardType = args.type or 'default' local icon = args.icon or '' local title = args.title or '' local content = args.content or '' local footer = args.footer or '' local link = args.link or '' -- Validate card type local validTypes = { ['default'] = true, ['primary'] = true, ['su...")
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)

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

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    return p._main(args)
end

function p._main(args)
    local cardType = args.type or 'default'
    local icon = args.icon or ''
    local title = args.title or ''
    local content = args.content or ''
    local footer = args.footer or ''
    local link = args.link or ''
    
    -- Validate card type
    local validTypes = {
        ['default'] = true,
        ['primary'] = true,
        ['success'] = true,
        ['warning'] = true,
        ['destructive'] = true
    }
    
    if not validTypes[cardType] then
        cardType = 'default'
    end
    
    -- Build the card HTML
    local html = mw.html.create('div')
        :addClass('vh-card')
        :addClass('vh-card--' .. cardType)
    
    -- Add header if title or icon exists
    if title ~= '' or icon ~= '' then
        local header = html:tag('div')
            :addClass('vh-card-header')
        
        if icon ~= '' then
            header:tag('span')
                :addClass('vh-card-icon')
                :wikitext(icon)
        end
        
        if title ~= '' then
            local titleElement = header:tag('h3')
                :addClass('vh-card-title')
            
            if link ~= '' then
                titleElement:wikitext('[[' .. link .. '|' .. title .. ']]')
            else
                titleElement:wikitext(title)
            end
        end
    end
    
    -- Add content
    if content ~= '' then
        html:tag('div')
            :addClass('vh-card-content')
            :wikitext(content)
    end
    
    -- Add footer if exists
    if footer ~= '' then
        html:tag('div')
            :addClass('vh-card-footer')
            :wikitext(footer)
    end
    
    return tostring(html)
end

function p.group(frame)
    local args = frame:getParent().args
    local content = args.content or args[1] or ''
    
    local html = mw.html.create('div')
        :addClass('vh-card-group')
        :wikitext(content)
    
    return tostring(html)
end

function p.quickLink(frame)
    local args = frame:getParent().args
    local icon = args.icon or ''
    local title = args.title or ''
    local link = args.link or ''
    local description = args.description or ''
    
    local html = mw.html.create('div')
        :addClass('vh-quick-link-card')
    
    if icon ~= '' then
        html:tag('div')
            :addClass('vh-quick-link-icon')
            :wikitext(icon)
    end
    
    if title ~= '' then
        local titleDiv = html:tag('div')
            :addClass('vh-quick-link-title')
        
        if link ~= '' then
            titleDiv:wikitext('[[' .. link .. '|' .. title .. ']]')
        else
            titleDiv:wikitext(title)
        end
    end
    
    if description ~= '' then
        html:tag('div')
            :addClass('vh-quick-link-desc')
            :wikitext(description)
    end
    
    return tostring(html)
end

return p