The idea is really good.
It would be nice to support the template data coming from an InputStream
(or Reader
or StreamResource
). This way, someone can even keep template data in a database or elsewhere. I can see from the code that caching of the parsed templates needs to be changed for this. Maybe, caching can be made open by introducing a ParsedHtmlTemplate class and providing a constructor new HtmlTemplate(ParsedHtmlTemplate)
.
I’d like to keep the used HTML parser, and thus also the format of the parsed HTML template, as an implementation detail. It also feels like it would be quite useful to always have caching available so that you wouldn’t have to implement that yourself.
Would it make sense to have a HtmlTemplate(String cacheKey, Supplier<InputStream> streamSupplier)
constructor? The supplier would be run for a cache miss (or if caching is disabled because production mode isn’t enabled) but would be ignored if the key is already present in the cache.
The suggested solution looks good.
Released as version 1.2.0. Thank you for your suggestion!
Thank you