public class ThymeleafModule extends AbstractModule
To use it one has to register the module and then render Template instances.
Instances of Template can be created using one of the
Template.thymeleafTemplate(java.util.Map, String, String)
static methods.
By default templates are looked up in the thymeleaf directory of the application root with a .html suffix.
So thymeleafTemplate("my/template/path") maps to thymeleaf/my/template/path.html in the application root directory.
This can be configured using setTemplatesPrefix(String) and setTemplatesSuffix(String) as well as
other.thymeleaf.templatesPrefix and other.thymeleaf.templatesSuffix configuration properties.
Response content type can be manually specified, i.e. thymeleafTemplate("template", model, "text/html") if
not specified will default to text/html.
import ratpack.handling.*;
import ratpack.guice.*;
import ratpack.util.*;
import ratpack.launch.*;
import ratpack.thymeleaf.ThymeleafModule;
import static ratpack.thymeleaf.Template.thymeleafTemplate;
class MyHandler implements Handler {
void handle(final Context context) {
context.render(thymeleafTemplate("my/template/path", key: "it works!"));
}
}
class ModuleBootstrap implements Action<ModuleRegistry> {
public void execute(ModuleRegistry modules) {
modules.register(new ThymeleafModule());
}
}
LaunchConfig launchConfig = LaunchConfigBuilder.baseDir(new File("appRoot"))
.build(new HandlerFactory() {
public Handler create(LaunchConfig launchConfig) {
return Guice.handler(launchConfig, new ModuleBootstrap(), new Action<Chain>() {
public void execute(Chain chain) {
chain.handler(chain.getRegistry().get(MyHandler.class));
}
});
}
});
Example usage: (Groovy DSL)
import ratpack.thymeleaf.ThymeleafModule
import static ratpack.thymeleaf.Template.thymeleafTemplate
import static ratpack.groovy.Groovy.ratpack
ratpack {
modules {
register new ThymeleafModule()
}
handlers {
get {
render thymeleafTemplate('my/template/path', key: 'it works!')
}
}
}
| Constructor and Description |
|---|
ThymeleafModule() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure() |
Integer |
getTemplatesCacheSize() |
String |
getTemplatesMode() |
String |
getTemplatesPrefix() |
String |
getTemplatesSuffix() |
void |
setTemplatesCacheSize(Integer templatesCacheSize) |
void |
setTemplatesMode(String templatesMode) |
void |
setTemplatesPrefix(String templatesPrefix) |
void |
setTemplatesSuffix(String templatesSuffix) |
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingpublic String getTemplatesMode()
public void setTemplatesMode(String templatesMode)
public String getTemplatesPrefix()
public void setTemplatesPrefix(String templatesPrefix)
public String getTemplatesSuffix()
public void setTemplatesSuffix(String templatesSuffix)
public Integer getTemplatesCacheSize()
public void setTemplatesCacheSize(Integer templatesCacheSize)
protected void configure()
configure in class AbstractModule