Module:Infobox
local p = {}
local function trim(s)
if s == nil then
return nil
end
s = tostring(s)
s = s:gsub('^%s+', ):gsub('%s+$', )
if s == then
return nil
end
return s
end
local function addRow(rows, label, data)
if not data then
return
end
if label then
table.insert(rows, string.format('|-\n| style="padding:0.35em 0.6em; vertical-align:top; white-space:nowrap; font-weight:bold;" | %s\n| style="padding:0.35em 0.6em; vertical-align:top;" | %s', label, data))
else
table.insert(rows, string.format('|-\n| colspan="2" style="padding:0.35em 0.6em;" | %s', data))
end
end
function p.main(frame)
local args = frame:getParent() and frame:getParent().args or frame.args
local title = trim(args.title) or trim(args.name) or 'Infobox' local image = trim(args.image) local image_caption = trim(args.image_caption)
local rows = {}
if image then local imageCell = image if image_caption then
imageCell = image .. '
' .. image_caption .. '
'
end
table.insert(rows, string.format('|-\n| colspan="2" style="text-align:center; padding:0.6em;" | %s', imageCell))
end
local idx = 1
while true do
local label = trim(args['label' .. idx])
local data = trim(args['data' .. idx])
if not label and not data then
break
end
addRow(rows, label, data)
idx = idx + 1
end
local class = trim(args.class) or 'infobox' local style = trim(args.style) or 'float:right; clear:right; margin:0 0 1em 1em; width:320px; max-width:100%; border:1px solid #a2a9b1; background:#f8f9fa; border-collapse:separate; border-spacing:0; font-size:90%;'
local out = {}
table.insert(out, string.format('{| class="%s" style="%s"', class, style))
table.insert(out, string.format('|+ style="padding:0.5em; background:#eaecf0; font-size:110%%; text-align:center;" | %s', title))
for _, row in ipairs(rows) do
table.insert(out, row)
end
table.insert(out, '|}')
return table.concat(out, '\n')
end
return p