public sealed interface TemplateModel
A template and model combined with convenience methods.
This tuple like object is useful way to combine the correct template with a model if
you have programmatic access to the template. This can be useful to a web framework
perhaps as the return type of a web controller and because the template is already
located the web framework does not have to re-find the template. An analog in the
Spring framework would be ModelAndView.
It is purposely not parameterized for ease of use as dealing with generics via reflection can be difficult.
- Author:
- agentgt
- API Note
- the interface is purposely sealed for now to see usage and feedback and one
can make their own similar version with
JStacheInterfaces.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Stringexecute()Renders the template to a String.execute(A output) Renders the passed in model directly to an appendable like output.model()Model.static <T> TemplateModelof(Template.EncodedTemplate<T> template, T model) Creates a template model pair.static <T> TemplateModelCreates a template model pair.Template<?>template()Template.default <A extends Output.EncodedOutput<E>,E extends Exception>
Awrite(A output) Renders the passed in model directly to a binary stream possibly leveraging pre-encoded parts of the template.default voidwrite(OutputStream outputStream) Convenience method to write directly to an outputstream with the templates character encoding.
-
Method Details
-
template
Template.- Returns:
- template to use for execution
-
model
Model.- Returns:
- model to be executed on
-
execute
Renders the passed in model directly to an appendable like output.- Type Parameters:
A- output typeE- error type- Parameters:
output- to write to.- Returns:
- the passed in output
- Throws:
E- if an error occurs while writing to output
-
write
Renders the passed in model directly to a binary stream possibly leveraging pre-encoded parts of the template.- Type Parameters:
A- output typeE- error type- Parameters:
output- to write to.- Returns:
- the passed in output
- Throws:
E- if an error occurs while writing to output
-
write
Convenience method to write directly to an outputstream with the templates character encoding.- Parameters:
outputStream- outputStream to write to- Throws:
IOException- if an error happens while writting to the stream.
-
execute
Renders the template to a String.- Returns:
- the executed template as a string.
-
of
Creates a template model pair.- Type Parameters:
T- model type- Parameters:
template- encoded templatemodel- model instance- Returns:
- the template executable designed for encoded templates.
-
of
Creates a template model pair.- Type Parameters:
T- model type- Parameters:
template- encoded templatemodel- model instance- Returns:
- the template executable.
-