Module:Navbox

From Minecraft Wiki
Jump to: navigation, search
[view | edit | history | purge]DocumentationJump to code ↴
This module is deprecated. Please use {{SimpleNavbox}} instead.

This module implements {{navbox}}. It should generally be invoked directly on template pages, rather than using the navbox template.

Parent arguments are automatically merged with directly passed arguments (the latter overwriting the former) and all arguments are normalised to trim whitespace and set empty arguments to nil.

Dependencies

See also

[view | edit | history | purge]The above documentation is transcluded from 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 = '<div class="navbox-navbar">' .. f:preprocess( '{{navbar|' .. args.name .. '|mini=' .. mini .. '}}' ) .. '</div>'
		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