Differences between revisions 1 and 2
Revision 1 as of 2004-05-28 21:03:11
Size: 1890
Editor: sjcd-dmzweb-ce8
Comment:
Revision 2 as of 2004-05-28 21:43:03
Size: 76
Editor: sjcd-dmzweb-ce8
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
A collection of Velocimacros of a non-web nature that may be useful in *any* Velocity application. These may make use of the VelocityTools' Generic tools.
----
{{{
#**
 * For displaying an alternate value when the primary one is "null".
 *
 * @param the primary variable
 * @param the alternate value or variable
 * @author <a href="mailto:nathan@esha.com">Nathan Bubna</a>
 *#
#macro( altnull $variable $alternate )
#if( "$!variable" == "" )$!alternate#else$variable#end##
#end

}}}

{{{


#**
 * For truncating a variable's output at a specific length.
 *
 * Usage:
 * "#truncate( 'this is too long' 10 )" -> "this is to..."
 *
 * @param the variable to be truncated
 * @param the length of the output (not including the ellipses!)
 * @author <a href="mailto:nathan@esha.com">Nathan Bubna</a>
 *#
#macro( truncate $stringVariable $length )
#set( $truncateMe = "$!stringVariable" )
#if( $truncateMe.length() <= $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
#end

}}}

{{{

#**
 * Convenience directive to invoke a method and ignore the return value.
 *
 * Usage:
 * #call( $hashtable.put("foo", "bar") )
 *
 *#
#macro( call $foo )#if($foo)#**##end#end


}}}

{{{
#*
 * Convenience macro to return "unknown" if null value
 * @author Ted Husted
*#
#macro (unknown $name $code)
    #if($code )
        $!name [$code]
    #else
        <i>Unknown</i>
    #end
#end
}}}

{{{
#*
 * Convenience macro to return "unknown" if null value
 * @author Ted Husted
*#
#macro (notSpecified $value)
    #if($value )
        $value
    #else
        <i>Not Specified</i>
    #end
#end
}}}

{{{
#*
 * Convenience macro to return "Pending" if null value
 * @author Ted Husted
*#
#macro (pending $value)
    #if($value )
        $value
    #else
        <i>Pending</i>
    #end
#end
}}}
Moved to VelocityGenericMacros -- but do not know how to delete this page!

Moved to VelocityGenericMacros -- but do not know how to delete this page!

GenericVelocimacros (last edited 2009-09-20 22:06:19 by localhost)