samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
841 stars 128 forks source link

Support index access on primitive arrays #70

Closed monae closed 9 years ago

monae commented 9 years ago

On v1.10, the template {{#foo}}{{this}}{{/foo}} works well for both primitive arrays and wrapper arrays:

System.out.println(template.execute(new Object() {
    int[] foo = new int[]{1, 2, 3, 4};
})); // prints "1234"

System.out.println(template.execute(new Object() {
    Integer[] foo = new Integer[]{1, 2, 3, 4};
})); // prints "1234"

On the other hand, the indexing {{foo.2}} does not work for primitive arrays:

System.out.println(template.execute(new Object() {
    int[] foo = new int[]{1, 2, 3, 4};
})); // throws an exception

System.out.println(template.execute(new Object() {
    Integer[] foo = new Integer[]{1, 2, 3, 4};
})); // prints "3"

This patch adds support for such index access on primitive arrays.