Author: cbrisson
Date: Mon Feb 20 14:07:41 2017
New Revision: 1783766
URL: http://svn.apache.org/viewvc?rev=1783766&view=rev
Log:
[site/engine] document condition evaluation new config flag and behavior
Modified:
velocity/site/cms/trunk/content/engine/devel/configuration.mdtext
velocity/site/cms/trunk/content/engine/devel/user-guide.mdtext
velocity/site/cms/trunk/content/engine/devel/vtl-reference.mdtext
Modified: velocity/site/cms/trunk/content/engine/devel/configuration.mdtext
URL:
http://svn.apache.org/viewvc/velocity/site/cms/trunk/content/engine/devel/configuration.mdtext?rev=1783766&r1=1783765&r2=1783766&view=diff
==============================================================================
--- velocity/site/cms/trunk/content/engine/devel/configuration.mdtext (original)
+++ velocity/site/cms/trunk/content/engine/devel/configuration.mdtext Mon Feb
20 14:07:41 2017
@@ -66,9 +66,19 @@ Below are listed the configuration keys
### #if() Directive
-**`directive.if.tostring.nullcheck = true`**
+**`directive.if.emptycheck = true`**
-> Default behavior is to check return value of toString() and treat an object
with toString() that returns null as null. If all objects have toString()
methods that never return null, this check is unnecessary and can be disabled
to gain performance. In Velocity 1.5, no such null check was performed.
+> When evaluating if a reference resolves to `true` or `false` in a boolean
context, the engine first checks if its value is null, if it is a Boolean or if
it has a getAsBoolean() method. Then, if none of this applies, the behavior
depends upon this configuration flag:
+>
+> - if `directive.if.emptycheck` is `false`, no further check is performed and
the object resolves to `true`.
+> - if `directive.if.emptycheck` is `true`, the object is check for emptiness
and zero value:
+> - return whether an array is empty.
+> - return whether isEmpty() is false (covers String and all Collection
classes).
+> - return whether length() is zero (covers CharSequence classes other
than String).
+> - returns whether size() is zero (covers all Collections classes).
+> - return whether a Number *strictly* equals zero.
+> - return whether the result of getAsString() is empty (and false for a
null result) if it exists.
+> - return whether the result of getAsNumber() *strictly* equals zero (and
false for a null result) if it exists.
### #set() Directive
Modified: velocity/site/cms/trunk/content/engine/devel/user-guide.mdtext
URL:
http://svn.apache.org/viewvc/velocity/site/cms/trunk/content/engine/devel/user-guide.mdtext?rev=1783766&r1=1783765&r2=1783766&view=diff
==============================================================================
--- velocity/site/cms/trunk/content/engine/devel/user-guide.mdtext (original)
+++ velocity/site/cms/trunk/content/engine/devel/user-guide.mdtext Mon Feb 20
14:07:41 2017
@@ -500,11 +500,14 @@ The *#if* directive in Velocity allows f
<strong>Velocity!</strong>
#end
-The variable *$foo* is evaluated to determine whether it is true, which will
happen under one of three circumstances:
+The variable *$foo* is evaluated to determine whether it is true, which will
happen under one of those circumstances:
+ *$foo* is a boolean (true/false) which has a true value
+ *$foo* is a string or a collection which is not null **and** not empty
-+ *$foo* is an object (other than a string or a collection) which is not null
++ *$foo* is a number which equals to zero
++ *$foo* is an object (other than a string, a number or a collection) which is
not null
+
+(please note that this is the default behavior, but Velocity can be configured
to [skip all checks beyond boolean and nullity
ones](configuration.html#if-directive)).
Remember that the Velocity context only contains Objects, so when we say
'boolean', it will be represented as a Boolean (the class). This is true even
for methods that return `boolean` - the introspection infrastructure will
return a `Boolean` of the same logical value.
Modified: velocity/site/cms/trunk/content/engine/devel/vtl-reference.mdtext
URL:
http://svn.apache.org/viewvc/velocity/site/cms/trunk/content/engine/devel/vtl-reference.mdtext?rev=1783766&r1=1783765&r2=1783766&view=diff
==============================================================================
--- velocity/site/cms/trunk/content/engine/devel/vtl-reference.mdtext (original)
+++ velocity/site/cms/trunk/content/engine/devel/vtl-reference.mdtext Mon Feb
20 14:07:41 2017
@@ -88,7 +88,18 @@ Format:
Usage:
-+ *condition* - If a boolean, considered true if it has a true false; if not a
boolean, considered true if not null.
++ *condition* - Expression to evaluate. When tis result is null, evaluate to
false. Otherwise, check for conversion towards Boolean and non-emptiness as
follow:
+ - return its value for a Boolean object, or the result of the
getAsBoolean() method if it exists.
+ - if `directive.if.emptycheck` = `false` (`true` by default), stop here
and consider it true.
+ - return whether an array is empty.
+ - return whether isEmpty() is false (covers String and all Collection
classes).
+ - return whether length() is zero (covers CharSequence classes other than
String).
+ - returns whether size() is zero (covers all Collection classes).
+ - return whether a Number *strictly* equals zero.
+ - return whether the result of getAsString() is empty (and false for a
null result) if it exists.
+ - return whether the result of getAsNumber() *strictly* equals zero (and
false for a null result) if it exists.
+ - consider the condition is `true`
+
+ *output* - May contain VTL.
Examples (showing different operators):