Module:Infobox: Difference between revisions
Appearance
the non-chatgpt base class |
fixed label implementation |
||
| Line 15: | Line 15: | ||
end | end | ||
local function add_field(data) | local function add_field(label, data) | ||
table.insert(out, '|-\n| ' .. label .. ' || ' .. data) | table.insert(out, '|-\n| ' .. label .. ' || ' .. data) | ||
end | end | ||
| Line 26: | Line 26: | ||
if component[1] == 't' then add_title(component[2]) | if component[1] == 't' then add_title(component[2]) | ||
elseif component[1] == 's' then add_section(component[2]) | elseif component[1] == 's' then add_section(component[2]) | ||
elseif component[1] == 'f' then add_field(component[2]) | elseif component[1] == 'f' then add_field(component[2], component[3]) | ||
end | end | ||
end | end | ||
Revision as of 20:21, 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: 250px;"')
local function add_title(data)
table.insert(out, '|-\n! colspan="2" style="font-size:120%; background:#ccc;" | ' .. data)
end
local function add_section(data)
table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. data)
end
local function add_field(label, data)
table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
end
if args.title then
table.insert(out, '|-\n! colspan="2" style="font-size:120%; background:#ccc;" | ' .. args.title)
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])
end
end
table.insert(out, '|}')
return table.concat(out, '\n')
end
return p