Module:Infobox: Difference between revisions
Appearance
Adds slight padding to border |
Adds padding to fields |
||
| Line 28: | Line 28: | ||
local function add_field(label, data) | local function add_field(label, data) | ||
if not data then return end | if not data then return end | ||
local | local left = 'style="width:50%; padding:0.3em; text-align:left; font-weight:bold;" | ' .. label | ||
local | local right = 'style="width:50%; padding:0.3em; text-align:right;" | ' .. data | ||
table.insert(out, '|-\n|' .. | table.insert(out, '|-\n|'..left..'||'..right) | ||
end | end | ||
local function add_image(data) | local function add_image(data) | ||
Revision as of 21:29, 21 June 2025
Documentation for this module may be created at Module:Infobox/doc
local p = {}
function p.infobox(frame)
local args = frame:getParent().args
local out = {}
table.insert(out,
'{| class="infobox" style="'
.. 'width:300px; '
.. 'float:right; '
.. 'margin:0 0 1em 1em; '
.. 'padding:0.5em; '
.. 'border:1px solid #aaa; ' -- outer box
.. 'border-collapse:collapse;' -- collapse cell borders
.. '"'
)
local function add_title(data)
if not data then return end
table.insert(out, '|-\n! colspan="2" style="font-size:120%; background:#F4BB44;" | ' .. data)
end
local function add_section(data)
if not data then return end
table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. data)
end
local function add_field(label, data)
if not data then return end
local left = 'style="width:50%; padding:0.3em; text-align:left; font-weight:bold;" | ' .. label
local right = 'style="width:50%; padding:0.3em; text-align:right;" | ' .. data
table.insert(out, '|-\n|'..left..'||'..right)
end
local function add_image(data)
if not data then return end
table.insert(out, '|-\n| colspan="2" style="text-align:center;" | ' .. data)
end
for i, component in ipairs(args) do
if component[1] == 't' then add_title(component[2])
elseif component[1] == 's' then add_section(component[2])
elseif component[1] == 'f' then add_field(component[2], component[3])
elseif component[1] == 'i' then add_image(component[2])
end
end
table.insert(out, '|}')
return table.concat(out, '\n')
end
return p