Module:SimpleInfobox

From Chalo Chatu, Zambia online encyclopedia
Jump to navigationJump to search

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

-- Module:SimpleInfobox (for Chalo Chatu)
local p = {}

function p.infobox(frame)
    local args = frame:getParent().args
    local root = mw.html.create('table')
        :addClass('infobox')
        :css('border','1px solid #aaa')
        :css('border-collapse','collapse')
        :css('background','#f8f8f8')
        :css('font-size','90%')
        :css('line-height','1.4')
        :css('width','23em')
        :css('margin','0.5em')

    -- Title
    if args.title and args.title:match('%S') then
        root:tag('caption')
            :css('font-size','110%')
            :css('font-weight','bold')
            :css('padding','.25em')
            :wikitext(args.title)
    end

    -- Image
    if args.image and args.image:match('%S') then
        root:tag('tr')
            :tag('td')
            :attr('colspan','2')
            :css('text-align','center')
            :css('padding','.25em')
            :wikitext('[[File:' .. args.image .. '|' .. (args.image_size or '200px') .. ']]')
    end

    -- Fields (label/data pairs)
    for i=1,30 do
        local label = args['label'..i]
        local data  = args['data'..i]
        if (label and label:match('%S')) or (data and data:match('%S')) then
            local tr = root:tag('tr')
            tr:tag('th')
                :css('background','#eaeaea')
                :css('text-align','left')
                :css('padding','.2em .5em')
                :wikitext(label or '')
            tr:tag('td')
                :css('padding','.2em .5em')
                :wikitext(data or '')
        end
    end

    return tostring(root)
end

-- Alias so Template wrappers can call either function name
p.infoboxTemplate = p.infobox

return p