META-INF.maven.components.toc-topbar.vm Maven / Gradle / Ivy
Go to download
Reflow is an Apache Maven site skin built on Twitter Bootstrap.
It allows various structural and stylistic customizations to create
a modern-looking Maven-generated website. Requires Reflow Velocity Tools.
##
## Copyright 2012-2018 Christophe Friederich
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
#**
* output top table fo content
*##macro( renderTopToc )
#if ( $pageContext.toc.enabled && $pageContext.toc.type == "top")
#end
#end
#**
* Outputs the top Table of Contents ( subnav )
*
*##macro ( renderTopTocItems $topItems )
#set ( $tocMax = $pageContext.toc.numberItems )#*
## check if we flatten the first 2 levels of ToC:
*##set ( $flattenConfig = $pageContext.toc.flatten )#*
*##if ( !$flattenConfig )#*
flatten config not available - calculate if need flattening:
only flatten if the top level has not more than 2 elements
*##set ( $topItemsCount = $topItems.size() )#*
*##set ( $flattenLevel2 = $topItemsCount <= 2 )#*
*##elseif ( "true" == $flattenConfig.getValue() )#*
*##set ( $flattenLevel2 = true )#*
*##else#*
*##set ( $flattenLevel2 = false )#*
*##end#*
## count items at top and the next level that will be displayed in the ToC bar
*##set ( $tocBarItems = [] )#*
*##set ( $tocBarMaxItems = [] )#*
*##set ( $tocCount = 0 )#*
*##foreach ( $topItem in $topItems )#*
*##if ( ($tocCount < $tocMax) || ($tocMax < 0) )#*
## only add items if not after the maximum
*##call ( $tocBarItems.add( $topItem ) )#*
*##set ( $topInMax = false )#*
*##else#*
*##call ( $tocBarMaxItems.add( $topItem ) )#*
*##set ( $topInMax = true )#*
*##end#*
*##set ( $tocCount = $tocCount + 1 )#*
## if level 2 is flattened, traverse for subitems
*##if ( $flattenLevel2 )#*
*##foreach ( $item in $topItem.items )#*
*##if ( ($tocCount < $tocMax) || ($tocMax < 0) )#*
## only add subitems if not after the maximum
*##call ( $tocBarItems.add( $item ) )#*
*##elseif ( !$topInMax )#*
## top is not in the max - so add these directly to the max
*##call ( $tocBarMaxItems.add( $item ) )#*
*##end#*
*##set ( $tocCount = $tocCount + 1 )#*
*##end#*
*##end#*
*##end#*
## count items at top and the next level that will be displayed in the ToC bar
*##set ( $tocCount = 0 )#*
*##set ( $tocDivider = false )#*
*##foreach ( $topItem in $tocBarItems )#*
*##if ( $topItems.contains( $topItem ) && $tocDivider )##
#* *##end#*
*##if ( $topItem.items.isEmpty() )##
$topItem.text
#* *##elseif ( $topItems.contains( $topItem ) && $flattenLevel2 )##
## top level item, but flattened: put it as a link, because its children are also in top bar
$topItem.text
#* *##else##
$topItem.text
#* *##end#*
*##set ( $tocDivider = true )#*
*##end#*
*##if ( $tocBarMaxItems.size() > 0 )##
## put the max items into an extra dropdown
…
#* *##end##
#end##
#**
* Recursively outputs the contents of top bar ToC dropdown item
*
*#
#macro ( renderTopTocDropdown $items )#*
*##foreach ( $subitem in $items )#*
*##if ($subitem.items.isEmpty())##
$subitem.text
#* *##else##
$subitem.text
#* *##end#*
*##end#*
*##end##