Class MustacheWhoEmailRenderer
- All Implemented Interfaces:
WhoEmailRenderer
An email whose WhoEmail.template() is sign-in renders sign-in.txt as
its text and, when it exists, sign-in.html as its HTML. Each file is looked for in the
given template locations, in order, then among who's built-in templates at BUILT_IN_LOCATION; the first that has it wins, so an application or a library replaces one file
without touching the others. Partials ({{> footer}}) are found the same way, with the
including template's extension.
A template sees three names: email, the email record itself; app, the
application-wide values; and extra, the values from WhoEmailModelContributors. A
variable the model lacks fails the render; a value that is null renders empty. Text templates are
not escaped; HTML templates escape their values.
The subject is the message who.email.<template>.subject in the email's locale,
rendered as a text template with the same three names, then put on one line: every run of control
characters, line breaks included, becomes one space. The message is read without arguments, so
MessageFormat does not touch it, unless the MessageSource always applies it (as
Spring's spring.messages.always-use-message-format does), which breaks a subject that
uses Mustache tags.
Every template in every location, and each template's subject in Locale.ROOT when it
has one, is compiled when the renderer is created, so a template or subject that does not compile
fails startup rather than the first send.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringWhere feature modules put their built-in templates, on the classpath. -
Constructor Summary
ConstructorsConstructorDescriptionMustacheWhoEmailRenderer(org.springframework.core.io.support.ResourcePatternResolver resources, List<String> templateLocations, org.springframework.context.MessageSource messages, Map<String, String> app, List<WhoEmailModelContributor> contributors) Creates the renderer and compiles every template it can find. -
Method Summary
Modifier and TypeMethodDescriptionRenders the email in the locale.
-
Field Details
-
BUILT_IN_LOCATION
Where feature modules put their built-in templates, on the classpath.- See Also:
-
-
Constructor Details
-
MustacheWhoEmailRenderer
public MustacheWhoEmailRenderer(org.springframework.core.io.support.ResourcePatternResolver resources, List<String> templateLocations, org.springframework.context.MessageSource messages, Map<String, String> app, List<WhoEmailModelContributor> contributors) Creates the renderer and compiles every template it can find.- Parameters:
resources- finds the templatestemplateLocations- the locations searched before who's own, in order: the application's, then the libraries'; a missing trailing/is addedmessages- supplies the subjectsapp- the application-wide values, seen asappcontributors- supply the values seen asextra, in order- Throws:
IllegalStateException- if a template, or a subject inLocale.ROOT, does not compile
-
-
Method Details
-
render
Description copied from interface:WhoEmailRendererRenders the email in the locale.- Specified by:
renderin interfaceWhoEmailRenderer- Parameters:
email- the email to renderlocale- the language to render it in- Returns:
- the rendered email
-