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

Module:InfoboxCat

From Silly Cats Wiki
Revision as of 22:26, 6 May 2025 by Phantom (talk | contribs)

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

local p = {}

function p.infobox(frame)
    local args = frame:getParent().args
    local html = mw.html.create('table')
        :addClass('infobox')
        :css({ width = '300px', border = '1px solid #aaa', ['background-color'] = '#f9f9f9' })

    local function addRow(label, key)
        local value = args[key]
        if value and value ~= '' then
            html:tag('tr')
                :tag('th'):wikitext(label):done()
                :tag('td'):wikitext(value)
        end
    end

    -- Title
    local title = args['title'] or mw.title.getCurrentTitle().text
    html:tag('tr')
        :tag('th')
        :attr('colspan', '2')
        :css({ ['text-align'] = 'center', ['font-size'] = '120%' })
        :wikitext(title)

    -- Image
    if args.image then
        html:tag('tr')
            :tag('td')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :wikitext('[[File:' .. args.image .. '|250px]]')
        if args['caption-image'] then
            html:tag('tr')
                :tag('td')
                :attr('colspan', '2')
                :css({ ['text-align'] = 'center', ['font-size'] = '90%' })
                :wikitext(args['caption-image'])
        end
    end

    -- Data fields (label, param name)
    local fields = {
        {'Alias', 'alias'},
        {'Sex', 'gender'},
        {'Nation from', 'nationality'},
        {'Breed', 'breed'},
        {'Coat', 'fur_color'},
        {'Born', 'born'},
        {'Abandoned', 'abandoned'},
        {'Rescued', 'rescued'},
        {'Adopted', 'adopted'},
        {'Died', 'died'},
        {'Cause of death', 'cause_of_death'},
        {'Resting place', 'resting_place'},
        {'Occupation', 'occupation'},
        {'Mate(s)', 'mate(s)'},
        {'Weight', 'weight'},
        {'Height', 'height'},
        {'Owner', 'owner'},
        {'Known for', 'known_for'},
        {'Sound', 'sound'},
        {'Social Media', 'social_media'}
    }

    for _, pair in ipairs(fields) do
        addRow(pair[1], pair[2])
    end

    return tostring(html)
end

return p