Module:Navbox
This is the documentation page. It will be transcluded into the main module page. See Template:Documentation for more information
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
ru:Модуль:Navbox
zh:Module:Navbox
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:expandTemplate( {
title = 'navbar',
args = {
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