Module:Navbox

From The Big Cartoon Wiki
Jump to navigation Jump to search

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

local p = {}
local wikitext = {}

function push(text)
	wikitext[#wikitext + 1] = text
end

function pushf(s, ...)
	wikitext[#wikitext + 1] = s:format(...)
end

function p.navbox(frame)
	local args = frame.args

	-- Add header, template color and template title
	push('{| class="navbox mw-collapsible mw-collapsed"')
	push('|-')
	pushf('! class="navbox-header" style="background-color:%s" colspan="2" | %s', args.color, args.title)

	-- Iterate through template rows
	for i=1,5 do
		if args['group' .. i] then
			-- Add row header
			push('|-')
			pushf('! %s', args['group' .. i])
			-- Add row data
			pushf('| [[%s]]', args['list' .. i]:gsub(' *\* *', ']] • [['))
		else
			break
		end
	end

	-- Add template footer
	push('|}')
	return table.concat(wikitext, '\n')
end

return p