Class MustacheTemplateEngine
java.lang.Object
org.springframework.restdocs.templates.mustache.MustacheTemplateEngine
- All Implemented Interfaces:
TemplateEngine
A Mustache-based
TemplateEngine
implemented using JMustache.
Note that JMustache has been repackaged and embedded to prevent classpath conflicts.
- Author:
- Andy Wilkinson
-
Constructor Summary
ConstructorDescriptionMustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve template paths.MustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver, Charset templateEncoding) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve template paths, reading them using the giventemplateEncoding
.MustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver, Charset templateEncoding, org.springframework.restdocs.mustache.Mustache.Compiler compiler) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates and the givencompiler
to compile them.MustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver, Charset templateEncoding, org.springframework.restdocs.mustache.Mustache.Compiler compiler, Map<String, Object> context) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates.MustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver, org.springframework.restdocs.mustache.Mustache.Compiler compiler) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates and the givencompiler
to compile them.MustacheTemplateEngine
(TemplateResourceResolver templateResourceResolver, org.springframework.restdocs.mustache.Mustache.Compiler compiler, Map<String, Object> context) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates. -
Method Summary
Modifier and TypeMethodDescriptioncompileTemplate
(String name) Compiles the template at the givenpath
.protected final org.springframework.restdocs.mustache.Mustache.Compiler
Returns theMustache.Compiler
used to compile Mustache templates.protected final TemplateResourceResolver
Returns theTemplateResourceResolver
used to resolve the template resources prior to compilation.
-
Constructor Details
-
MustacheTemplateEngine
Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
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 newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve template paths, reading them using the giventemplateEncoding
.- Parameters:
templateResourceResolver
- the resolver to usetemplateEncoding
- 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 newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates and the givencompiler
to compile them. Templates will be read as UTF-8.- Parameters:
templateResourceResolver
- the resolver to usecompiler
- the compiler to use
-
MustacheTemplateEngine
public MustacheTemplateEngine(TemplateResourceResolver templateResourceResolver, Charset templateEncoding, org.springframework.restdocs.mustache.Mustache.Compiler compiler) Creates a newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates and the givencompiler
to compile them. Templates will be read using the giventemplateEncoding
.- Parameters:
templateResourceResolver
- the resolver to usetemplateEncoding
- the charset to use when reading the templatescompiler
- 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 newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates. Templates will be read as UTF-8. Once read, the givencompiler
will be used to compile them. Compiled templates will be created with the givencontext
.- Parameters:
templateResourceResolver
- the resolver to usecompiler
- the compiler to usecontext
- 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 newMustacheTemplateEngine
that will use the giventemplateResourceResolver
to resolve templates. Template will be read using the giventemplateEncoding
. Once read, the givencompiler
will be used to compile them. Compiled templates will be created with the givencontext
.- Parameters:
templateResourceResolver
- the resolver to usetemplateEncoding
- the charset to use when reading the templatescompiler
- the compiler to usecontext
- the context to pass to compiled templates- Since:
- 2.0.5
- See Also:
-
-
Method Details
-
compileTemplate
Description copied from interface:TemplateEngine
Compiles the template at the givenpath
. Typically, aTemplateResourceResolver
will be used to resolve the path into a resource that can be read and compiled.- Specified by:
compileTemplate
in interfaceTemplateEngine
- 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 theMustache.Compiler
used to compile Mustache templates.- Returns:
- the compiler
-
getTemplateResourceResolver
Returns theTemplateResourceResolver
used to resolve the template resources prior to compilation.- Returns:
- the resolver
-