Jump to content

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

Module:Infobox

From CrabCraft Wiki
Revision as of 21:07, 21 June 2025 by Max (talk | contribs) (Position infobox right)

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;"')
    
	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)
	    local left_cell  = 'style="width:50%; text-align:left; font-weight:bold;" | ' .. label
	    local right_cell = 'style="width:50%; text-align:left;" | ' .. data
	    table.insert(out, '|-\n|' .. left_cell .. ' || ' .. right_cell)
	end
	
	local function add_image(data)
		table.insert(out, '|-\n| colspan="2" style="text-align:center;" | ' .. 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])
		elseif component[1] == 'i' then add_image(component[2])
		end
	end

	table.insert(out, '|}')

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

return p