Module:LocationInfo

From Little Tail Wiki
Revision as of 21:27, 19 February 2025 by Admin (talk | contribs) (Created page with "local capiunto = require 'capiunto' local p = {} function p.main(frame) local args = frame:getParent().args -- Set header style, defaulting to 'background-color:grey' if not provided local headerStyle = args.headerstyle and args.headerstyle ~= '' and string.format('background-color:%s;', args.headerstyle) or 'background-color:grey;' -- Create the infobox local retval = capiunto.create({ title = tostring(mw.title.getCurrentTitle()),...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

local capiunto = require 'capiunto'

local p = {}

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

    -- Set header style, defaulting to 'background-color:grey' if not provided
    local headerStyle = args.headerstyle and args.headerstyle ~= '' and
        string.format('background-color:%s;', args.headerstyle) or 'background-color:grey;'

    -- Create the infobox
    local retval = capiunto.create({
        title = tostring(mw.title.getCurrentTitle()),
        headerStyle = headerStyle,
    })

    -- Add image and caption
    if args.image then
        retval:addImage(args.image, args.caption or '')
    end

    -- Add a general header
    retval:addHeader('Info.')

    -- Add rows only for fields that are not empty
    local rows = {
        { 'Origin Country', args.origin },
        { 'Namesake', args.namesake },
        { 'Greater Area', args.greaterarea },
        { 'Country', args.country },
        { 'Capital', args.capital },
        { 'Ruler', args.ruler },
        { 'Demographic', args.demographic },
        { 'Inhabitants', args.inhabitants },
    }

    for _, row in ipairs(rows) do
        local label, value = row[1], row[2]
        if value and value ~= '' then
            retval:addRow(label, value)
        end
    end

    return retval
end

return p