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.
##
## Copyright 2012-2018 Christophe Friederich
##
## 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##
#*
*
* Shortcut to display a basic hyperlink
*
*##macro ( link $href $name $target $className)#*
*##fullLink ( $href $name $target false false false false false false false $className)#*
*##end#*
*
* Outputs a hyperlink with image and other attributes
*
*##macro ( fullLink $href $name $target $img $position $alt $border $width $height $icon $className)##
##
## 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##
##
#**
* Recursively checks if any of the submenu items is the current one
*
*##macro ( displayTree $item )#*
*##if ( $item && $item.items && $item.items.size() > 0 )#*
*##foreach ( $subitem in $item.items )#*
*##activeLink ( $subitem.href )#*
*##if ( $activeLink )#*
*##set ( $displayTree = true )#*
*##end#*
*##displayTree ( $subitem )#*
*##end#*
*##end##
#end##
##
#**
* Filters menus by their ref or name, and returns the matching results.
* The regex is used to check the match
*
*##macro ( filterMenus $menus $filterRegex )#*
*##set ( $filterMenus = [] )#*
*##foreach ($menu in $menus)#*
*##if ( ( $menu.ref && $menu.ref.matches($filterRegex) ) || ( $menu.name && $menu.name.matches($filterRegex) ) )#*
*##call ( $filterMenus.add( $menu ) )#*
*##end#*
*##end##
#end##
##
#**
* Displays a 'Last published' date message.
*
*##macro ( publishDate )#*
*##if ( $decoration.publishDate.format )#*
*##set ( $format = $decoration.publishDate.format )#*
*##else#*
*##set ( $format = "yyyy-MM-dd" )#*
*##end#*
*#$dateFormat.applyPattern( $format )#*
*##if ( $publishDate )#*
*##set ( $dateValue = $dateFormat.format( $publishDate ) )#*
*##elseif ( $config.publishDate )#*
*##set ( $dateValue = $config.publishDate.getValue() )#*
*##else#*
*##set ( $dateValue = $dateFormat.format( $currentDate ) )#*
*##end#*
## render with internationalization support *#
$i18n.getString( "site-renderer", $locale, "template.lastpublished" ): $dateValue
#end##
##
#**
* Displays a site version message.
*
*##macro ( version )#*
## render with internationalization support
*#$i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version}##
#end##
##
#**
* Outputs XML DOM objects as html elements into the rendered document.
* Taken from maven-fluido-skin.
*
*##macro ( htmlContent $items )#*
*##foreach ( $item in $items )#*
*##set ( $itemHtml = $item.toString().trim() )#*
*##set ( $documentHeader = '' )#*
*##if ( $item.name == "script" )#*
*##set ( $itemHtml = $StringUtils.replace( $item.toUnescapedString(), $documentHeader, "" ) )#*
*##else#*
*##set ( $itemHtml = $StringUtils.replace( $item.toString(), $documentHeader, "" ) )#*
*##end#*
## eval the HTML - this will allow users to specify Velocity variables
*##evaluate ( $itemHtml )#*
*##end##
#end##
##
#**
* Marks the first header inside the content as page header, by wrapping it into
* a div with `page-header` class
*
*##macro ( bodyWithHeader $content )#*
*##if ( $config.not( "markPageHeader" ) )#*
## do not mark page header, just print the content
*##set ( $bodyWithHeader = $content )#*
*##else#*
## try marking the header
*##set ( $bodyWithHeader = $htmlTool.wrap($content, "h1", '', 1) )#*
*##if ( $bodyWithHeader == $content )#*
## nothing's changed - try with h2
*##set ( $bodyWithHeader = $htmlTool.wrap($content, "h2", '', 1) )#*
*##end#*
*##end#*
*#$bodyWithHeader##
#end##
##
#**
* Strips empty paragraphs from the content and outputs the result
*
*##macro ( stripEmptyP $content )#*
## use CSS selector for paragraphs that have no text content (only whitespace - \s),
## neither nested elements
*#$htmlTool.remove($content, "p:matchesOwn(^${esc.backslash}s*$):not(*:has(*))")##
#end##
##
#**
* Adds Google analytics tracker with the given account ID
*
*##macro ( googleAnalytics $accountId )#*
*##if( $accountId && $accountId != "" )##
#*
*##end##
#end##
##
#**
* Fixes info collapse for Dependencies report.
*
* Uses Javascript toggle for "more information" in the dependency tree.
*
*##macro ( depsCollapse )#*
*##set( $collapseCalls = $htmlTool.getAttr( $bodyContent, 'img[onclick^=toggleDependencyDetail]', "onclick") )#*
*##set( $iconReplacements = {} )#*
*##set( $collapseSelector = "" )#*
*##foreach ( $collapseCall in $collapseCalls )#*
*##set ( $funSplit = $collapseCall.split("'") )#*
*##if ( $funSplit.size() >= 4 )#*
*##set ( $divId = $funSplit.get(1) )#*
*##set ( $imgId = $funSplit.get(3) )#*
*##set ( $replBefore = '' )#*
*##call ( $iconReplacements.put("#$imgId", "$replBefore$divId$replAfter") )#*
*##set ( $collapseSelector = "${collapseSelector}, #$divId" )#*
*##end#*
*##end#*
*##if ( $iconReplacements.size() > 0 )#*
*##set ( $bodyContent = $htmlTool.replaceAll( $bodyContent, $iconReplacements ) )#*
*##set ( $bodyContent = $htmlTool.addClass( $bodyContent, $collapseSelector, "collapse" ) )#*
*##set ( $bodyContent = $htmlTool.setAttr( $bodyContent, $collapseSelector, "style", "" ) )#*
*##end##
#end##
#*
* Adapt bodyContent.
*#
#macro ( adaptBodyContent )#*
*##if ( !$config.not( "imgLightbox" ) )#*
## lightbox is enabled by default, so check for false and negate
## TODO explain more?
*##set ( $bodyContent = $htmlTool.setAttr( $bodyContent, "a[href$=jpg], a[href$=JPG], a[href$=jpeg], a[href$=JPEG], a[href$=png], a[href$=gif], a[href$=bmp]:has(img)", "data-lightbox", "page" ))#*
*##end##
##
#if ( !$config.not( "html5Anchor" ) )##
## HTML5-style anchors are enabled by default, so check for false and negate
#set ( $bodyContent = $htmlTool.headingAnchorToId( $bodyContent ) )##
#end##
##
#if ( !$config.not( "bootstrapCss" ) )##
## Bootstrap CSS class conversion is enabled by default, so check for false and negate
#set ( $bodyContent = $htmlTool.addClass( $bodyContent, "table.bodyTable", ["table", "table-striped", "table-hover"] ) )##
## image is responsive by default
#set ( $bodyContent = $htmlTool.addClass( $bodyContent, "img", ["img-fluid"] ) )##
#set ( $bodyContent = $htmlTool.fixTableHeads( $bodyContent ) )##
#end##
##
#if ( !$config.not( "bootstrapIcons" ) )##
## Bootstrap Icons are enabled by default, so check for false and negate
#* *##depsCollapse ()##
#set ( $iconReplacements = { 'img[src$=images/add.gif]' : '',
'img[src$=images/remove.gif]' : '',
'img[src$=images/fix.gif]' : '',
'img[src$=images/update.gif]' : '',
'img[src$=images/icon_help_sml.gif]' : '',
'img[src$=images/icon_success_sml.gif]' : '',
'img[src$=images/icon_warning_sml.gif]' : '',
'img[src$=images/icon_error_sml.gif]' : '',
'img[src$=images/icon_info_sml.gif]' : '' } )##
#set ( $bodyContent = $htmlTool.replaceAll( $bodyContent, $iconReplacements ) )##
## The tag is not supported in HTML5 (see https://www.w3schools.com/tags/tag_tt.asp).
#set ( $bodyContent = $htmlTool.replaceWith( $bodyContent, 'tt', '' ) )##
#end##
#if ( $pageContext.toc.enabled )##
## Ensure IDs on all headings to refer to them in TOC
#set ( $bodyContent = $htmlTool.ensureHeadingIds( $pageContext.type, $config.fileId, $bodyContent, "_" ) )##
#set ( $tocItems = $htmlTool.headingTree( $bodyContent, $config.getChildren( $config.sections ) ) )##
#end##
#end##
#*
* Add Edit button if content is editable
*#
#macro ( renderFeedbackLink )
#end##