Class ThymeleafModule

  • All Implemented Interfaces:
    Module

    @Deprecated
    public class ThymeleafModule
    extends ConfigurableModule<ThymeleafModule.Config>
    Deprecated.
    since 1.7.0. Use ratpack-thymeleaf3 instead.
    An extension module that provides support for Thymeleaf templating engine.

    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.

    See Also:
    Thymeleaf, Guice Multibindings
    • Field Detail

      • DEFAULT_TEMPLATE_MODE

        public static final java.lang.String DEFAULT_TEMPLATE_MODE
        Deprecated.
        See Also:
        Constant Field Values
      • DEFAULT_TEMPLATE_PREFIX

        public static final java.lang.String DEFAULT_TEMPLATE_PREFIX
        Deprecated.
        See Also:
        Constant Field Values
      • DEFAULT_TEMPLATE_SUFFIX

        public static final java.lang.String DEFAULT_TEMPLATE_SUFFIX
        Deprecated.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ThymeleafModule

        public ThymeleafModule()
        Deprecated.
    • Method Detail

      • getTemplatesMode

        public java.lang.String getTemplatesMode()
        Deprecated.
      • setTemplatesMode

        public void setTemplatesMode​(java.lang.String templatesMode)
        Deprecated.
      • getTemplatesPrefix

        public java.lang.String getTemplatesPrefix()
        Deprecated.
      • setTemplatesPrefix

        public void setTemplatesPrefix​(java.lang.String templatesPrefix)
        Deprecated.
      • getTemplatesSuffix

        public java.lang.String getTemplatesSuffix()
        Deprecated.
      • setTemplatesSuffix

        public void setTemplatesSuffix​(java.lang.String templatesSuffix)
        Deprecated.
      • getTemplatesCacheSize

        public java.lang.Integer getTemplatesCacheSize()
        Deprecated.
      • setTemplatesCacheSize

        public void setTemplatesCacheSize​(java.lang.Integer templatesCacheSize)
        Deprecated.