test_lib.ftl

And FTL lib file
Copyright
bla bla bla 2021

Macro and Function Summary

Category [Auxiliar functions ]
function
iif ( condition , value1 , value2 )
Function that emulates C/Java '?' operator
function
isStringNumber ( variable )
Checks if a String value it's a number
function
join ( seq , separator )
Function that generates a string from a sequence, putting a separator bettwen elements
function
toBool ( input )
Function that converts a value to a Boolean

Macro and Function Detail

function iif ( condition , value1 , value2 )

Function that emulates C/Java '?' operator

Category
[Auxiliar functions ]
Parameters
Name Type Description
condition Boolean Expression that evaluates on a boolean value
Source Code
<#function iif condition value1 value2>
    
<#if condition>
        
<#return value1 />
    
<#else>
        
<#return value2 />
    
</#if>
</#function>

function isStringNumber ( variable )

Checks if a String value it's a number

Category
[Auxiliar functions ]
Source Code
<#function isStringNumber variable>
    
<#attempt>
        
<#assign numberVariable = variable?number />
        
<#return numberVariable?is_number />
    
<#recover>
        
<#return false />
    
</#attempt>
</#function>

function join ( seq , separator )

Function that generates a string from a sequence, putting a separator bettwen elements

Category
[Auxiliar functions ]
Parameters
Name Type Description
seq Sequence Sequence to be converted to String
separator String (Optional) Seperator element.
Default value : " "
Source Code
<#function join seq separator = " ">
    
<#local res = "" />
    
<#list seq as e>
        
<#if e_index == 0>
            
<#local res = res + e />
        
<#else>
            
<#local res = res + separator + e />
        
</#if>
    
</#list>
    
<#return res />
</#function>

function toBool ( input )

Function that converts a value to a Boolean

Category
[Auxiliar functions ]
Parameters
Name Type Description
input String | Number | Boolean | Object String or Number to be converted to Boolean
Return value
Boolean value being true or false
Source Code
<#function toBool input>
    
<#if input?is_boolean>
        
<#return input />
    
</#if>

    
<#-- Number -->
    
<#if input?is_number>
        
<#if input != 0>
            
<#return true />
        
<#else>
            
<#return false />
        
</#if>
    
</#if>

    
<#-- String -->
    
<#if input?is_string>
        
<#if input == "" || input == "false"|| input == "not"  || input == "no" || input == "n" || input == "f" >
            
<#return false />
        
<#else>
            
<#return true />
        
</#if>
    
</#if>
    
    
<#-- != Null or not has content -->
    
<#if input?? && input?has_content>
        
<#return true />
    
<#else>
        
<#return false />
    
</#if>
</#function>