Module:InfoboxMinimal
Appearance
Documentation for this module may be created at Module:InfoboxMinimal/doc
-- Module:InfoboxMinimal
local p = {}
local function blank(s) return not s or mw.text.trim(tostring(s)) == '' end
local function get(inv, par, key) return (inv and inv[key]) or (par and par[key]) end
local function addRow(root, label, data)
if blank(data) then return end
local tr = root:tag('tr')
tr:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label or '')
tr:tag('td'):addClass('infobox-data'):wikitext(data)
end
function p.infobox(frame)
local inv = frame.args -- args set in #invoke (wrapper template)
local par = frame:getParent() and frame:getParent().args or {} -- args from the calling page
local classes = 'infobox'
local bodyclass = get(inv, par, 'bodyclass')
if not blank(bodyclass) then classes = classes .. ' ' .. bodyclass end
local root = mw.html.create('table'):addClass(classes):attr('role','presentation')
local title = get(inv, par, 'title') or get(inv, par, 'name') or mw.title.getCurrentTitle().baseText
root:tag('caption'):addClass('infobox-title'):wikitext(title)
-- scan generously; stops naturally on blank data
for i = 1, 100 do
addRow(root, get(inv, par, 'label'..i), get(inv, par, 'data'..i))
end
return tostring(root)
end
return p