All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.maven.site-macros.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.

There is a newer version: 2.4.0-beta2
Show newest version
##
## Copyright 2012-2017 Andrius Velykis
##
## Licensed to the Apache Software Foundation (ASF) under one
## or more contributor license agreements.  See the NOTICE file
## distributed with this work for additional information
## regarding copyright ownership.  The ASF licenses this file
## to you 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.
##
#**
 * Convenience directive to invoke a method and ignore the return value.
 *
 * Usage:
 *    #call ( $hashtable.put("foo", "bar") )
 *#
#macro ( call $foo )#*
  *##if ($foo)#*
    ## do nothing - the 'if' is for ignoring the return value#*
  *##end#*
*##end#*
 *
 * Checks if the given link is an external one.
*##macro ( checkExtLink $href )#*
  *##set ( $checkExtLink = false )#*
  *##if ( $href && ($href.toLowerCase().startsWith("http:/") || $href.toLowerCase().startsWith("https:/")
        || $href.toLowerCase().startsWith("ftp:/") || $href.toLowerCase().startsWith("mailto:")
        || $href.toLowerCase().startsWith("file:/") || ($href.toLowerCase().indexOf("://") != -1) ))#*
  *##set ( $checkExtLink = true )#*
  *##end#*
*##end#*
 *
 * Relativizes the link
 *
*##macro ( relativeLink $href )#*
    *##if ( $href )#*
        *##set ( $relativeLink = $PathTool.calculateLink( $href, $relativePath ) )#*
        *##set ( $relativeLink = $relativeLink.replaceAll( "\\", "/" ) )#*
        *##if ( ( $relativeLink == '' ) )#*
            *##set ( $relativeLink = './' )#*
        *##end#*
            ## Attempt to normalise the relative link - this is useful for active link
            ## calculations and better relative links for subdirectories.
            ##
            ## The issue is particularly visible with pages in subdirectories,
            ## so that if you are in /dev/index.html, the relative menu link to
            ## the _same_ page would likely be ../dev/index.html instead of '' or 'index.html'.
        *##set ( $absoluteLink = $uriTool.toURI( "$currentFileLoc" ).resolve( "$relativeLink" ).normalize().toString() )#*
        *##if ( $currentFileLoc == $absoluteLink )##
                #* for matching link, use empty relative link#*
            *##set ( $relativeLink = '' )#*
        *##else#*
                ## relativize the absolute link based on current directory
                ## (uses Maven project link relativization)
            *##set ( $currentFileDir = $PathTool.getDirectoryComponent( $currentFileLoc ) )#*
            *##set ( $relativeLink = $uriTool.relativizeLink( $currentFileDir, $absoluteLink ) )#*
        *##end#*

    *##else##
        #* null $href
        *##set ( $relativeLink = false )#*
    *##end#*
*##end#*
 *
 * Checks if the given link is an external one. If not, calculates a relative link.
 *
 *##macro ( relativeExtLink $href )#*
  *##checkExtLink ( $href )#*
  *##if ( $checkExtLink )##
        #* if external, keep the original#*
      *##set ( $relativeExtLink = $href )#*
  *##else##
        #* if not external link, calculate an return the relative link#*
      *##relativeLink ( $href )#*
      *##set ( $relativeExtLink = $relativeLink )#*
  *##end#*
*##end#*
 *
 * Makes the link relative to the project URL, if one is set.
 *
 *##macro ( currentFileRelativeLink $href )#*

  *##if ( $project.url && $project.url != '' && $currentFileName )##
        ## if project URL is available, relativize the link using it as a base dir
        #* note that the current file can be nested under project URL, so take that into account
        *##set ( $currentFileDir = $uriTool.toURI( "$project.url/" ).resolve( "$currentFileName" ).resolve(".").toString() )#*
      *##set ( $currentFileRelativeLink = $uriTool.relativizeLink( $currentFileDir, $href ) )#*
  *##else##
        #* otherwise just keep the original link#*
      *##set ( $currentFileRelativeLink = $href )#*
  *##end#*
*##end#*
 *
 * Checks if the given link is the currently active one
 *
 *##macro ( activeLink $href )#*
  *##relativeLink ( $href )#*
    *##if ( $href )#*
        either empty link (pointing to a page), or if the current file is index.html,
        the link may point to the whole directory
        *##if ( '' == $relativeLink || ( $alignedFileName.endsWith("index.html") && './' == $relativeLink ) )#*
            *##set ( $activeLink = true )#*
            *##set ( $activeClass = 'active' )#*
        *##else#*
            *##set ( $activeLink = false )#*
            *##set ( $activeClass = '' )#*
        *##end#*
    *##else#*
        null href - disable the link
        *##set ( $activeLink = false )#*
        *##set ( $activeClass = 'disabled' )#*
    *##end#*
*##end#*
 *
 * Creates a class="name" attribute if the given name exists
 *
 *##macro ( classAttr $name )#*

  *##if ( $name && '' != $name )#*
      *# class="$name" #*
  *##end#*
*##end#*
 *
 * Creates dropdown menu items
 *
 *##macro ( topMenu $menus )#*

    *##foreach ( $menu in $menus )#*

      *##if ( $menu.name )#*
            ## check if one of the subtree items is the current one
            *##set ( $displayTree = false )#*
          *##displayTree ( $menu )##
            
#*      *##end#*
  *##end#*
*##end#*
 *
 * Outputs a list of links
 *
 *##macro ( links $links )#*

  *##foreach ( $item in $links )#*
      *##activeLink ( $item.href )#*
      *#
  • #link ( $relativeLink $item.name $item.target )
  • #* *##end#* *##end#* * * Shortcut to display a basic hyperlink * *##macro ( link $href $name $target )#* *##fullLink ( $href $name $target false false false false false false false )#* *##end#* * * Outputs a hyperlink with image and other attributes * *##macro ( fullLink $href $name $target $img $position $alt $border $width $height $icon)## ## ## The opening tag #* *##if ( $img && $position == "left" )#* ## Image on the left side of the name *##image ($img $alt $border $width $height)$name#* *##elseif ( $img )#* ## Image on the right side of the name *#${name}#if ($img) #image ($img $alt $border $width $height)#end#* *##else#* ## No image - optional icon though on the right of the name *#${name}#if ($icon) #end#* *##end## ## ## #end#* * * Outputs an image with attributes * *##macro ( image $img $alt $border $width $height )#* *##if ( $img )#* *#"#* *##end## #end## ## #** * Outputs a list of breadcrumbs * *##macro ( breadcrumbs $breadcrumbs )#* *##foreach ( $item in $breadcrumbs )#* *##relativeLink ( $item.href )##
  • #fullLink ( $relativeLink $item.name $item.target $item.img $item.position $item.alt $item.border $item.width $item.height false )
  • #* *##end##
  • #if ( $shortTitle )$shortTitle#else$title#end
  • #end## ## #** * Outputs the top Table of Contents ( subnav ) * *##macro ( topToc $topItems )#* ## read the top ToC max config to get the number of items to show *##if ( $config.tocTopMax )#* *##set ( $tocMax = $convert.toNumber($config.tocTopMax.getValue()) )#* *##else#* *##set ( $tocMax = -1 )#* *##end#* ## check if we flatten the first 2 levels of ToC: *##set ( $flattenConfig = $config.tocTopFlatten )#* *##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## #* *##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 ( topTocDropdown $items )#* *##foreach ( $subitem in $items )#* *##if ($subitem.items.isEmpty())##
  • $subitem.text
  • #* *##else## #* *##end#* *##end#* *##end## ## #** * Outputs Table of Contents into a list menu * *##macro ( listToc $menus )## ## #end## ## #** * Recursively outputs ToC item and its children * *##macro ( listTocItem $item )#* *##if ( $item.items.size() > 0 )## #* *##else##
  • $item.text #* *##set ( $addedDivider = false )#* *##end## #end## #** * Outputs Table of Contents into a list menu * *##macro ( listAsideToc $menus )## ## #end## ## #** * Recursively outputs ToC item and its children * *##macro ( listAsideTocItem $item )##
  • #* *##if ( $item.items.size() == 0 )#end## $item.text #* *##if ( $item.items.size() > 0 )## #* *##end#* *#
  • #end## ## #** * Outputs the top banner contents * *##macro ( banner $banner $id )#* *##if ( $banner )#* *##if ( $banner.href )#* *##relativeExtLink ( $banner.href )## #* *##else## #* *##end#* ## add slogan to correct position *##if ( $config.slogan && $config.slogan != '' )#* ## read slogan position - if not set, use 'bannerLeft' as default *##if ( $config.slogan.getAttribute("position") )#* *##set ( $sloganPos = $config.slogan.getAttribute("position") )#* *##else#* *##set ( $sloganPos = "bannerLeft" )#* *##end#* *##if ( $id == $sloganPos )##

    $config.slogan.getValue()

    #* *##end#* *##end#* *##end## #end## ## #** * Partitions the body contents into sections with possibly different representations. * Available body types, indicated in custom page config `sections` tag: * * * - the main body of the page * - sidebar (should go after the body) * x - x-column grid layout for thumbnails (first image is used as thumbnail) * x - x-column grid layout * - carousel (spinning images with captions) * * *##macro ( bodySections $bodyContent $sectionConfig )#* ## Split everything in the content on the horizontal rule tags
    *##set ( $sections = $htmlTool.split( $bodyContent, "hr" ) )#* *##set ( $sectCount = $sectionConfig.getChildCount() )#* ## Check if sidebar is indicated somewhere in the sections, need to adjust layout accordingly *##set ( $hasSidebar = $sectionConfig.getChild( 'sidebar' ) )#* ## flag to indicate that last section was a main body section (needs closing for non-body sections) *##set ( $lastBody = false )#* ## flag to indicate that a body section has already been found (to avoid multiple page-headers) *##set ( $bodyFound = false )#* *##set ( $sectIndex = 0 )#* *##foreach ($section in $sections)#* ## Determine section type from the configuration *##if ( $sectIndex < $sectCount )#* *##set ( $sectType = $sectionConfig.getChild($sectIndex).getName() )#* *##set ( $sectTypeValue = $sectionConfig.getChild($sectIndex).getValue() )#* *##else#* *##set ( $sectType = 'body' )#* *##end#* *##if ( 'sidebar' == $sectType || 'thumbs' == $sectType || 'columns' == $sectType || 'carousel' == $sectType )#* ## split section into sub-sections for each header (h1, h2, etc tag) *##set ( $subsections = $htmlTool.splitOnStarts( $section, "h1, h2, h3, h4, h5, h6") )#* *##else#* ## keep the section *##set ( $subsections = [ $section ] )#* *##end#* *##if ( 'thumbs' == $sectType || 'columns' == $sectType || 'carousel' == $sectType )#* ## for full width layouts, we first need to close the body if it is still open *##if ( $lastBody )##
    #* check if need to add explicit ToC sidebar (if ToC sidebar is needed, but no sidebar is defined) *##if ( $tocSidebar && !$hasSidebar)## #* *##tocSidebar ()#* *##end## #* *##end#* ## Print the subsections into columns *##if ( 'thumbs' == $sectType )#* *##thumbs ( $sectTypeValue $subsections )#* *##elseif ( 'columns' == $sectType )#* *##columns ( $sectTypeValue $subsections )#* *##else#* *##carousel ( $subsections )#* *##end#* ## mark that last one was not a body #set ( $lastBody = false ) *##elseif ( 'sidebar' == $sectType )#* ## for sidebar, close the body if needed but not body row - then add the sidebar *##if ( $lastBody )## #* *##else##
    #* *##end
    #* *##if ( $tocSidebar )#* *##tocSidebarContent ()#* *##end##
    #* *##set ( $lastBody = false )#* *##else#* ## handle all other cases as 'body' type *##if ( !$lastBody )##
    #* *##if ( $hasSidebar || $tocSidebar )#* ## has a sidebar - take part width *#
    #* *##else#* ## no sidebar - take full width *#
    #* *##end##
    #* *##else#* ## reinstate the horizontal rule for continuing body *#
    #* *##end#* ## set the contents *##foreach ( $subsection in $subsections )#* ## if first body section, output with page-header *##if ( !$bodyFound )#* *##bodyWithHeader ( $subsection )#* *##else#* *#$subsection#* *##end#* *##set ( $bodyFound = true )#* *##end#* *##set ( $lastBody = true )#* *##end#* ## increment the section counter (need to advance through the types) *##set ( $sectIndex = $sectIndex + 1 )#* *##end#* ## After the loop, check if body section still needs closing (if it was the last section) *##if ( $lastBody )##
    #* check if need to add explicit ToC sidebar (if ToC sidebar is needed, but no sidebar is defined) *##if ( $tocSidebar && !$hasSidebar )#* *##tocSidebar ()#* *##end##
    #* *##end## #end## #* * * Outputs subsections as thumbnail grid. Also rearranges the images to come on top. * *##macro ( thumbs $colCount $subsections )##
    #* *##set ( $colCount = $convert.toNumber($colCount) )##
      #* *##set ( $colSpan = 12 / $colCount )#* *##foreach ( $subsection in $subsections )##
    • #* bring the first image (possibly with a link) to the top of the subsection ## (to have a thumbnail with leading image) *##set ( $thumbnailContent = $htmlTool.reorderToTop( $subsection, "a:has(img), img", 1, '
      ' ) )#* *##if ( $thumbnailContent == $subsection )#* ## no image found, so at least wrap into a caption *#
      #stripEmptyP ( $thumbnailContent )
      #* *##else#* *##stripEmptyP ( $thumbnailContent )#* *##end##
    • #* *##end##
    #end## ## #** * Outputs subsections into a column grid * *##macro ( columns $colCount $subsections )#* *##set ( $colCount = $convert.toNumber($colCount) )##
    #* *##set ( $colSpan = 12 / $colCount )#* *##set ( $i = 1 )#* *##foreach ( $subsection in $subsections )##
    $subsection
    #* *##set ( $mod = $i % $colCount )#* *##if ( $mod == 0 )#* ##new row *#
    #* *##end#* *##set ( $i = $i + 1 )#* *##end##
    #end## ## #** * Outputs subsections into a sidebar one after another * *##macro ( sidebar $subsections )#* *##foreach ( $subsection in $subsections )#* *#$subsection#* *##end## #end## ## #** * Outputs subsections into a carousel. Also rearranges the layout to fit carousel. * *##macro ( carousel $subsections )#* *##if ( !$carouselCounter )#* *##set ( $carouselCounter = 0 )#* *##else#* *##set ( $carouselCounter = $carouselCounter + 1 )#* *##end#* *##set ( $carouselId = "carousel$carouselCounter" )## #end## ## #** * Outputs a sidebar containing ToC only. * Does not do anything if ToC sidebar has already been added. * *##macro ( tocSidebar )#* *##if ( !$tocSidebarAdded )##
    #* *##tocSidebarContent ()#* *#
    #* *##end## #end## ## #** * Outputs ToC sidebar contents. * Does not do anything if ToC sidebar has already been added. * *##macro ( tocSidebarContent )#* *##if ( !$tocSidebarAdded )## #* *##set ( $isFixed = $config.toc.getAttribute("type") == "fixed")


    © 2015 - 2024 Weber Informatics LLC | Privacy Policy