ratpack-thymeleaf3 instead.@Deprecated public class ThymeleafModule extends ConfigurableModule<ThymeleafModule.Config>
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 configuration of
ThymeleafModule.Config.templatesPrefix(String) and ThymeleafModule.Config.templateSuffix(String).
Response content type can be manually specified, i.e. thymeleafTemplate("template", model, "text/html") if
not specified will default to text/html.
import ratpack.guice.Guice;
import ratpack.test.embed.EphemeralBaseDir;
import ratpack.test.embed.EmbeddedApp;
import java.nio.file.Path;
import static org.junit.Assert.*;
@SuppressWarnings("deprecation")
public class Example {
public static void main(String... args) throws Exception {
EphemeralBaseDir.tmpDir().use(baseDir -> {
baseDir.write("thymeleaf/myTemplate.html", "<span th:text=\"${key}\"/>");
EmbeddedApp.of(s -> s
.serverConfig(c -> c.baseDir(baseDir.getRoot()))
.registry(Guice.registry(b -> b.module(ratpack.thymeleaf.ThymeleafModule.class)))
.handlers(chain -> chain
.get(ctx -> ctx.render(ratpack.thymeleaf.Template.thymeleafTemplate("myTemplate", m -> m.put("key", "Hello Ratpack!"))))
)
).test(httpClient -> {
assertEquals("<span>Hello Ratpack!</span>", httpClient.getText());
});
});
}
}
To register dialects, use Guice Multibindings to bind an implementation of IDialect in a module.
| Modifier and Type | Class and Description |
|---|---|
static class |
ThymeleafModule.Config
Deprecated.
The configuration object for
ThymeleafModule. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_TEMPLATE_MODE
Deprecated.
|
static java.lang.String |
DEFAULT_TEMPLATE_PREFIX
Deprecated.
|
static java.lang.String |
DEFAULT_TEMPLATE_SUFFIX
Deprecated.
|
| Constructor and Description |
|---|
ThymeleafModule()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure()
Deprecated.
|
java.lang.Integer |
getTemplatesCacheSize()
Deprecated.
|
java.lang.String |
getTemplatesMode()
Deprecated.
|
java.lang.String |
getTemplatesPrefix()
Deprecated.
|
java.lang.String |
getTemplatesSuffix()
Deprecated.
|
void |
setTemplatesCacheSize(java.lang.Integer templatesCacheSize)
Deprecated.
|
void |
setTemplatesMode(java.lang.String templatesMode)
Deprecated.
|
void |
setTemplatesPrefix(java.lang.String templatesPrefix)
Deprecated.
|
void |
setTemplatesSuffix(java.lang.String templatesSuffix)
Deprecated.
|
configure, createConfig, defaultConfig, setConfigaddError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingpublic static final java.lang.String DEFAULT_TEMPLATE_MODE
public static final java.lang.String DEFAULT_TEMPLATE_PREFIX
public static final java.lang.String DEFAULT_TEMPLATE_SUFFIX
public java.lang.String getTemplatesMode()
public void setTemplatesMode(java.lang.String templatesMode)
public java.lang.String getTemplatesPrefix()
public void setTemplatesPrefix(java.lang.String templatesPrefix)
public java.lang.String getTemplatesSuffix()
public void setTemplatesSuffix(java.lang.String templatesSuffix)
public java.lang.Integer getTemplatesCacheSize()
public void setTemplatesCacheSize(java.lang.Integer templatesCacheSize)
protected void configure()
configure in class AbstractModule