kwin commented on a change in pull request #63:
URL: https://github.com/apache/sling-site/pull/63#discussion_r677318669



##########
File path: 
src/main/jbake/content/documentation/bundles/scripting/scripting-htl.md
##########
@@ -56,6 +56,31 @@ The [HTML Template Language 
Specification](https://github.com/Adobe-Marketing-Cl
 
 The HTL implementation from Sling provides the basic POJO support through the 
[`org.apache.sling.scripting.sightly.pojo.Use`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler-java/blob/master/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java)
 interface and the 
[`JavaUseProvider`](https://github.com/apache/sling-org-apache-sling-scripting-sightly/blob/master/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java),
 whereas the `use` function is implemented by the 
`org.apache.sling.scripting.sightly.js.provider` bundle.
 
+# Type conversions
+
+The HTL Specification talks about the following types which are supported to 
be used with native Java types. The conversion rules are outlined in the table 
below.
+
+HTL Type | Conversion from Java Type | Code Link
+--- | --- | --- 
+`Boolean` | `java.lang.Boolean` (no conversion necessary). In addition it 
returns `true` for every other Java object except for `null`, 
`java.lang.Number` having value `0`, empty String, array, Collection, Map, 
Iterator or Iterable's iterator  | 
[`ObjectModel.toBoolean(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L151)
+`String` | Almost every type via `Object.toString()`. `Collections` are 
handled differently, by joining their elements. | 
[`ObjectModel.toString(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L238)
+`Date` | `java.util.Date`, `java.util.Calendar` |
+`Number` | `java.lang.Number`, every other type first converted to 
`java.lang.String` and then converted to Number via 
[`NumberUtils.createNumber(String)`](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/math/NumberUtils.html#createNumber-java.lang.String-).
 | 
[`ObjectModel.toNumber(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L204)
+`Collection` | Empty list for everything except for <br/>arrays, Collections, 
Iterators and Iterables (converted to List) and `java.lang.String` or 
`java.lang.Number` (a list containing a single item). For `java.util.Map` the 
key set is used.  | 
[`ObjectModel.toCollection(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L277)
+`Map` |

Review comment:
       @raducotescu Can you add some info for `Map` and `Enum`?

##########
File path: 
src/main/jbake/content/documentation/bundles/scripting/scripting-htl.md
##########
@@ -56,6 +56,31 @@ The [HTML Template Language 
Specification](https://github.com/Adobe-Marketing-Cl
 
 The HTL implementation from Sling provides the basic POJO support through the 
[`org.apache.sling.scripting.sightly.pojo.Use`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler-java/blob/master/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java)
 interface and the 
[`JavaUseProvider`](https://github.com/apache/sling-org-apache-sling-scripting-sightly/blob/master/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java),
 whereas the `use` function is implemented by the 
`org.apache.sling.scripting.sightly.js.provider` bundle.
 
+# Type conversions
+
+The HTL Specification talks about the following types which are supported to 
be used with native Java types. The conversion rules are outlined in the table 
below.
+
+HTL Type | Conversion from Java Type | Code Link
+--- | --- | --- 
+`Boolean` | `java.lang.Boolean` (no conversion necessary). In addition it 
returns `true` for every other Java object except for `null`, 
`java.lang.Number` having value `0`, empty String, array, Collection, Map, 
Iterator or Iterable's iterator  | 
[`ObjectModel.toBoolean(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L151)
+`String` | Almost every type via `Object.toString()`. `Collections` are 
handled differently, by joining their elements. | 
[`ObjectModel.toString(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L238)
+`Date` | `java.util.Date`, `java.util.Calendar` |
+`Number` | `java.lang.Number`, every other type first converted to 
`java.lang.String` and then converted to Number via 
[`NumberUtils.createNumber(String)`](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/math/NumberUtils.html#createNumber-java.lang.String-).
 | 
[`ObjectModel.toNumber(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L204)
+`Collection` | Empty list for everything except for <br/>arrays, Collections, 
Iterators and Iterables (converted to List) and `java.lang.String` or 
`java.lang.Number` (a list containing a single item). For `java.util.Map` the 
key set is used.  | 
[`ObjectModel.toCollection(Object)`](https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/org.apache.sling.scripting.sightly.runtime-1.2.4-1.4.0/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L277)

Review comment:
       why is Date and Boolean not converted to a single item list?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to