Jump to: navigation, search

Module:Navbox

Revision as of 15:39, 14 February 2014 by MrTJP (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
function p.box( f )
	local args = require( 'Module:ProcessArgs' ).merge( true )
	local navbox = {}

	if args.title then
		local class = args.class or 'collapsible'
		local bodyStyle = args.bodystyle or ''
		if bodyStyle ~= '' then
			bodyStyle = 'style="' .. bodyStyle .. '"'
		end
		table.insert( navbox, ' {| class="navbox hlist ' .. class .. '" ' .. bodyStyle )
		
		local titleStyle = args.titlestyle or ''
		if titleStyle ~= '' then
			titleStyle = 'style="' .. titleStyle .. '"'
		end
		local navbar = args[1] or ''
		if navbar ~= '' then
			local mini = ''
			if navbar:match( 'navbar%-mini' ) then
				mini = '1'
			end
			navbar = f:preprocess( '{{navbar|' .. args.name .. '|mini=' .. mini .. '}}' )
		end
		table.insert( navbox, '! class="navbox-top" colspan="2" ' .. titleStyle .. ' | ' .. navbar .. '<span class="navbox-title">' .. args.title .. '</span>' )
	else
		table.insert( navbox, ' {| class="navbox-child"' )
	end
	
	local groupNums = {}
	for k, v in pairs( args ) do
		if type( k ) == 'string' then
			local groupNum = k:match( 'group(%d+)' )
			if groupNum and v then
				table.insert( groupNums, tonumber( groupNum ) )
			end
		end
	end
	table.sort( groupNums )
	
	local groupStyle = args.groupstyle or ''
	local listStyle = args.liststyle or ''
	for _, v in ipairs( groupNums ) do
		local list = args['list' .. v]
		if list then
			table.insert( navbox, '|-\n! class="navbox-group" style="' .. groupStyle .. '" | ' .. args['group' .. v] )
			table.insert( navbox, '| class="navbox-list" style="' .. listStyle .. '" | ' .. list:gsub( '^([*#:{])', '\n%1' ) )
		end
	end
	
	table.insert( navbox, '|}' )
	
	navbox = table.concat( navbox, '\n' ):gsub( ' style=""', '' )
	return navbox
end
return p


Cookies help us deliver our services. By using our services, you agree to our use of cookies.