Class MustacheTemplateEngine

java.lang.Object
org.springframework.restdocs.templates.mustache.MustacheTemplateEngine
All Implemented Interfaces:
TemplateEngine

public class MustacheTemplateEngine extends Object implements TemplateEngine
A Mustache-based TemplateEngine implemented using JMustache.

Note that JMustache has been repackaged and embedded to prevent classpath conflicts.

Author:
Andy Wilkinson
  • Constructor Details

    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve template paths. Templates will be read as UTF-8.
      Parameters:
      templateResourceResolver - the resolver to use
    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, Charset templateEncoding)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve template paths, reading them using the given templateEncoding.
      Parameters:
      templateResourceResolver - the resolver to use
      templateEncoding - the charset to use when reading the templates
      Since:
      2.0.5
    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, org.springframework.restdocs.mustache.Mustache.Compiler compiler)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve templates and the given compiler to compile them. Templates will be read as UTF-8.
      Parameters:
      templateResourceResolver - the resolver to use
      compiler - the compiler to use
    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, Charset templateEncoding, org.springframework.restdocs.mustache.Mustache.Compiler compiler)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve templates and the given compiler to compile them. Templates will be read using the given templateEncoding.
      Parameters:
      templateResourceResolver - the resolver to use
      templateEncoding - the charset to use when reading the templates
      compiler - the compiler to use
      Since:
      2.0.5
    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, org.springframework.restdocs.mustache.Mustache.Compiler compiler, Map<String,Object> context)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve templates. Templates will be read as UTF-8. Once read, the given compiler will be used to compile them. Compiled templates will be created with the given context.
      Parameters:
      templateResourceResolver - the resolver to use
      compiler - the compiler to use
      context - the context to pass to compiled templates
      See Also:
    • MustacheTemplateEngine

      public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, Charset templateEncoding, org.springframework.restdocs.mustache.Mustache.Compiler compiler, Map<String,Object> context)
      Creates a new MustacheTemplateEngine that will use the given templateResourceResolver to resolve templates. Template will be read using the given templateEncoding. Once read, the given compiler will be used to compile them. Compiled templates will be created with the given context.
      Parameters:
      templateResourceResolver - the resolver to use
      templateEncoding - the charset to use when reading the templates
      compiler - the compiler to use
      context - the context to pass to compiled templates
      Since:
      2.0.5
      See Also:
  • Method Details

    • compileTemplate

      public Template compileTemplate(String name) throws IOException
      Description copied from interface: TemplateEngine
      Compiles the template at the given path. Typically, a TemplateResourceResolver will be used to resolve the path into a resource that can be read and compiled.
      Specified by:
      compileTemplate in interface TemplateEngine
      Parameters:
      name - the path of the template
      Returns:
      the compiled Template
      Throws:
      IOException - if compilation fails
    • getCompiler

      protected final org.springframework.restdocs.mustache.Mustache.Compiler getCompiler()
      Returns the Mustache.Compiler used to compile Mustache templates.
      Returns:
      the compiler
    • getTemplateResourceResolver

      protected final TemplateResourceResolver getTemplateResourceResolver()
      Returns the TemplateResourceResolver used to resolve the template resources prior to compilation.
      Returns:
      the resolver