- All Implemented Interfaces:
JStachioExtension
,JStachioExtensionProvider
,JStachioFilter
You are probably asking yourself why do I need JMustache if I have JStachio? Unfortunately JStachio needs the annotation processor to run every time a template is changed!. While there are incremental compilers like Eclipse that do support incrementally compiling annotations they are often not triggered via editing resources. Furthermore incremental compilation often just doesn't work.
Enter JMustache. Through reflection you can edit your templates while an application is
running. Luckily JMustache and JStachio are almost entirely compatible especially
through this extension which configures JMustache to act like JStachio. Even
JStacheLambda
will work.
The only major compatibility issue is that JMustache currently does not support mustache inheritance (parents and blocks)!
If this extension is enabled which it is by default if the ServiceLoader finds it
JMustache will be used when a runtime filtered rendering call is made (see
JStachio
).
How this works is this extension is a filter that checks to see if the statically
generated renderer (template) can render and that its template is up-to-date. If it is
not then JMustache will use the template meta data to construct its own template and
then execute it. In some cases the annotation processor does not even have to run for
this to work (see Templates.getInfoByReflection(Class)
.
Strongly recommended you disable this in production via
JSTACHIO_JMUSTACHE_DISABLE
or use
- Author:
- agentgt
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jstach.jstachio.spi.JStachioFilter
JStachioFilter.FilterChain
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfilter
(TemplateInfo template, JStachioFilter.FilterChain previous) Advises or filters a previously created filter.void
init
(JStachioConfig config) Called before the extensions are used but afterJStachioExtensionProvider.provideConfig()
.A prefix to add to the output to know that JMustache is being used.final @NonNull JStachioFilter
Provide a filter or not.sourcePath
(String sourcePath) Sets the relative to the project sourcePath for runtime lookup of templates.A suffix to append to the output to know that JMustache is being used.use
(boolean flag) Enables JMustacheMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.jstach.jstachio.spi.JStachioExtensionProvider
provideConfig, provideTemplateFinder
Methods inherited from interface io.jstach.jstachio.spi.JStachioFilter
filter, order
-
Field Details
-
JSTACHIO_JMUSTACHE_SOURCE_PATH
Property key of where jmustache will try to load template files. Default issrc/main/resources
.- See Also:
-
JSTACHIO_JMUSTACHE_DISABLE
Property key to disable jmustache. Default isfalse
.- See Also:
-
-
Constructor Details
-
JMustacheRenderer
public JMustacheRenderer()No-arg constructor for ServiceLoader
-
-
Method Details
-
use
Enables JMustache- Parameters:
flag
- true enables- Returns:
- return this for builder like config
-
prefix
A prefix to add to the output to know that JMustache is being used.- Parameters:
prefix
- string to prefix output- Returns:
- return this for builder like config
-
suffix
A suffix to append to the output to know that JMustache is being used.- Parameters:
suffix
- string to suffix output- Returns:
- return this for builder like config
-
sourcePath
Sets the relative to the project sourcePath for runtime lookup of templates. By default issrc/main/resources
.- Parameters:
sourcePath
- by default issrc/main/resources
- Returns:
- sourcePath should not be null
-
init
Description copied from interface:JStachioExtensionProvider
Called before the extensions are used but afterJStachioExtensionProvider.provideConfig()
. SeeJStachioExtensionProvider.provideConfig()
on how the config is consolidated to a single config.- Parameters:
config
- the composite config never null
-
filter
public JStachioFilter.FilterChain filter(TemplateInfo template, JStachioFilter.FilterChain previous) Description copied from interface:JStachioFilter
Advises or filters a previously created filter.- Specified by:
filter
in interfaceJStachioFilter
- Parameters:
template
- info about the templateprevious
- the function returned early in the chain.- Returns:
- an advised render function or often the previous render function if no advise is needed.
-
provideFilter
Provide a filter or not. The final filter is a composite and becomes a filter chain. The implementation is a filter and provides itself.- Specified by:
provideFilter
in interfaceJStachioExtensionProvider
- Returns:
- filter if this service provider provies one or
null
-