google / escapevelocity

A subset reimplementation of Apache Velocity with a much simpler API.
Apache License 2.0
33 stars 11 forks source link

Defer `#parse` until the containing template is evaluated. #34

Closed copybara-service[bot] closed 1 year ago

copybara-service[bot] commented 1 year ago

Defer #parse until the containing template is evaluated.

This removes a major difference from Velocity. It means that we can have #parse($variable) or use #if to select which #parse to do. Previously we applied #parse when the containing template was parsed, which meant we had to require its argument to be a constant, and we always expanded every #parse regardless of whether it might be in an #if or #foreach.

The change also means we support templates that #parse themselves, assuming of course that #if or #foreach is used to prevent infinite recursion.

Also fix some small mistakes in the public javadoc, and add a little more detail to the intro in README.md about why you might prefer EscapeVelocity to Velocity.

RELNOTES=#parse directives now take effect when the containing template is evaluated rather than when it is parsed. That means that the argument no longer has to be a constant string.