org.webbitserver.handler
Interface TemplateEngine
- All Known Implementing Classes:
- StaticFile
public interface TemplateEngine
Abstract interface for template engines. It can be passed as an argument to the constructors of
StaticFileHandler and EmbeddedResourceHandler.
Webbit itself doesn't provide any template engines. Look at Webbit-REST
for implementations.
|
Method Summary |
byte[] |
process(byte[] template,
String templatePath,
Object templateContext)
Renders a template. |
TEMPLATE_CONTEXT
static final String TEMPLATE_CONTEXT
- See Also:
- Constant Field Values
process
byte[] process(byte[] template,
String templatePath,
Object templateContext)
throws RuntimeException
- Renders a template.
Most template engines merge a
templateContext with a template to produce output. What constitutes a valid
context is template-engine specific.
Rendering happens on your main thread, so it is important that this method is not IO-bound. For example,
rendering a template using a context that is some sort of active record
that makes trips to the database will block Webbit preventing it from handling other requests. It's important to
make sure any remote data is pre-fetched.
Webbit will pass the request data value keyed with TEMPLATE_CONTEXT as the templateContext argument.
It's the programmer's responsibility to make sure the data value is set before the template is rendered,
i.e. before the StaticFileHandler or EmbeddedResourceHandler handler instance handles a request.
- Parameters:
length - number of bytes in the templatetemplate - the template sourcetemplatePath - the path the template is read from. Allows implementations to cache compiled templates.templateContext - object to merge into the template
- Returns:
- a rendered template
- Throws:
RuntimeException- See Also:
DataHolder.data(String),
HttpRequest.data(String, Object)
Copyright © 2013. All Rights Reserved.