Module:InfoboxMinimal
Documentation for this module may be created at Module:InfoboxMinimal/doc
-- Module:InfoboxMinimal (patched)
local p = {}
local function isBlank(s) return not s or mw.text.trim(tostring(s)) == '' end
local function get(args1, args2, key)
-- prefer wrapper (#invoke) args, then parent (template) args
return (args1 and args1[key]) or (args2 and args2[key])
end
local function addRow(tbl, label, data)
if isBlank(data) then return end
local tr = tbl: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 invokeArgs = frame.args -- from {{#invoke:...| key = value }}
local parentArgs = frame:getParent() and frame:getParent().args or {} -- from {{Infobox_Startup|...}}
local classes = 'infobox'
local bodyclass = get(invokeArgs, parentArgs, 'bodyclass')
if not isBlank(bodyclass) then classes = classes .. ' ' .. bodyclass end
local root = mw.html.create('table'):addClass(classes):attr('role','presentation')
local title = get(invokeArgs, parentArgs, 'title') or
get(invokeArgs, parentArgs, 'name') or
mw.title.getCurrentTitle().baseText
root:tag('caption'):addClass('infobox-title'):wikitext(title)
for i = 1, 100 do
local label = get(invokeArgs, parentArgs, 'label'..i)
local data = get(invokeArgs, parentArgs, 'data' ..i)
addRow(root, label, data)
end
return tostring(root)
end
return p