Jump to content

📢 Please make sure to read our Style Guide before editing. For questions, suggestions, or technical issues, please contact Noah.

Module:Infobox: Difference between revisions

From CrabCraft Wiki
Added support for categories
testing new section capabilities
Line 1: Line 1:
local p = {}
local p = {}
p.order = {}
p.map = {}
function p.add_section(name, fields)
table.insert(p.order, name)
map[name] = fields
end


function p.infobox(frame)
function p.infobox(frame)
Line 11: Line 19:
end
end
local rows = tonumber(args.rows) or 10
for i, name in ipairs(p.order) do
local categories = tonumber(args.categories) or 5
        table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. args['section' .. i])
 
        for j, field in ipairs(p.map[name]) do
for i = 1, rows do
            table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
local label = args['label' .. i]
        end
local data = args['data' .. i]
    end
if label and data then
table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
end
end
for i = 1, categories do
local category = args['category' .. i]
table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. args['category' .. i])
end


table.insert(out, '|}')
table.insert(out, '|}')

Revision as of 19:10, 21 June 2025

Documentation for this module may be created at Module:Infobox/doc

local p = {}

p.order = {}
p.map = {}

function p.add_section(name, fields)
	table.insert(p.order, name)
	map[name] = fields
end

function p.infobox(frame)
	local args = frame:getParent().args
	local out = {}

	table.insert(out, '{| class="infobox" style="width: 250px;"')

	if args.title then
		table.insert(out, '|-\n! colspan="2" style="font-size:120%; background:#ccc;" | ' .. args.title)
	end
	
	for i, name in ipairs(p.order) do
        table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. args['section' .. i])
        for j, field in ipairs(p.map[name]) do
            table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
        end
    end

	table.insert(out, '|}')

	return table.concat(out, '\n')
end

return p