ftl_highlight.ftl

This ftl macro library provides macros used to display nodes of the AST (=Abstract Syntax Tree) of a FreeMarker template. The data displayed by the macro print has to be of type TemplateNodeModel. In most cases one should use freemarker.tools.ftldoc.TemplateElementNode, which is part of the ftldoc distro.
Author
Stephan Mueller
Version
0.1

Macro and Function Summary

Category [fm4xml-style macros for TemplateElements-s ]
macro
comment
handler macro for ftl comments.
macro
directive
handler macro for ftl directives.
macro
interpolation
handler macro for ftl interpolations.
macro
textblock
handler macro for ftl text blocks.
macro
userdirective
handler macro for ftl user-defined directives.
Category [helper macros ]
function
format ( text )
macro
nobr
Removes disturbing newlines which produces a (unwanted) blank when rendered by a browser
function
removeEOL ( text )
Category [main macro ]
macro
print root
The macro <code>print(root)</code> is the entry point for highlighted syntax output in html.

Macro and Function Detail

macro comment

handler macro for ftl comments. This macro doesn't require any arguments since the FM4XML mechanism provides the current directive as <code>.node</code> variable.

Category
[fm4xml-style macros for TemplateElements-s ]
Source Code
<#macro comment>
<@nobr>
<span class="comment">
${format(.node.start?html)}
</span>
</@nobr>
</#macro>

macro directive

handler macro for ftl directives. This macro doesn't require any arguments since the FM4XML mechanism provides the current directive as <code>.node</code> variable.

Category
[fm4xml-style macros for TemplateElements-s ]
Source Code
<#macro directive>
<@nobr>
<span class="directive">
${format(.node.start?html)}
</span>
<#recurse>
<span class="directive">
${format(.node.end?html)}
</span>
</@nobr>
</#macro>

function format ( text )
Category
[helper macros ]
Source Code
<#function format text>
<#return text?replace(" ","&nbsp;")?replace("\n","<br/>")>
</#function>

macro interpolation

handler macro for ftl interpolations. This macro doesn't require any arguments since the FM4XML mechanism provides the current directive as <code>.node</code> variable.

Category
[fm4xml-style macros for TemplateElements-s ]
Source Code
<#macro interpolation>
<@nobr>
<span class="interpolation">
${format(.node.start?html)}
</span>
</@nobr>
</#macro>

macro nobr

Removes disturbing newlines which produces a (unwanted) blank when rendered by a browser

Category
[helper macros ]
Source Code
<#macro nobr>
<#assign text><#nested></#assign>
${removeEOL(text)}
</#macro>

macro print root

The macro <code>print(root)</code> is the entry point for highlighted syntax output in html. Any wrapped descendant of <code>freemarker.core.TemplateElement</code> can be root of the display process. A suitable model that could wrap <code>TemplateElement</code>-s is <code>org.visigoths.freemarker.tools.ftldoc.TemplateElementNode</code>.

Category
[main macro ]
Parameters
Name Type Description
root the root (of type node) of the template (fragment) to be displayed
Source Code
<#macro print root>
<#visit root>
</#macro>

function removeEOL ( text )
Category
[helper macros ]
Source Code
<#function removeEOL text>
<#return text?replace("\r\n","")?replace("\n","") />
</#function>

macro textblock

handler macro for ftl text blocks. This macro doesn't require any arguments since the FM4XML mechanism provides the current directive as <code>.node</code> variable.

Category
[fm4xml-style macros for TemplateElements-s ]
Source Code
<#macro textblock>
<@nobr>
<span class="textblock">
${format(.node.start?html)}
</span>
</@nobr>
</#macro>

macro userdirective

handler macro for ftl user-defined directives. This macro doesn't require any arguments since the FM4XML mechanism provides the current directive as <code>.node</code> variable.

Category
[fm4xml-style macros for TemplateElements-s ]
Source Code
<#macro userdirective>
<@nobr>
<span class="userdirective">
${format(.node.start?html)}
</span>
<#recurse>
<span class="userdirective">
${format(.node.end?html)}
</span>
</@nobr>
</#macro>