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
testing new section capabilities
the non-chatgpt base class
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 14: Line 6:


table.insert(out, '{| class="infobox" style="width: 250px;"')
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(data)
table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
end


if args.title then
if args.title then
Line 19: Line 23:
end
end
for i, name in ipairs(p.order) do
for i, component in ipairs(args) do
        table.insert(out, '|-\n! colspan="2" style="background: #F4BB44;" | ' .. args['section' .. i])
if component[1] == 't' then add_title(component[2])
        for j, field in ipairs(p.map[name]) do
elseif component[1] == 's' then add_section(component[2])
            table.insert(out, '|-\n| ' .. label .. ' || ' .. data)
elseif component[1] == 'f' then add_field(component[2])
        end
end
    end
end


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

Revision as of 19: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: 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(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])
		end
	end

	table.insert(out, '|}')

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

return p