Package com.github.mustachejava
Class DefaultMustacheFactory
java.lang.Object
com.github.mustachejava.DefaultMustacheFactory
- All Implemented Interfaces:
MustacheFactory
- Direct Known Subclasses:
DeferringMustacheFactory,FallbackMustacheFactory,SafeMustacheFactory,SpecMustacheFactory
Simplest possible code factory
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorServiceprotected final MustacheParserThis parser should work with any MustacheFactoryprotected final ConcurrentHashMap<String, Mustache> Create the default cache for mustache compilations.private final MustacheResolverprotected ObjectHandlerThis is the default object handler.private final ThreadLocal<Map<String, Mustache>> protected intprotected final ConcurrentHashMap<FragmentKey, Mustache> New templates that are generated at runtime are cached here. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultMustacheFactory(MustacheResolver mustacheResolver) DefaultMustacheFactory(File fileRoot) Use the file system to resolve mustache templates.DefaultMustacheFactory(String classpathResourceRoot) Use the classpath to resolve mustache templates. -
Method Summary
Modifier and TypeMethodDescriptionCreate a mustache given a reader and a name.Create a mustache given a resource name.In order to handle recursion, we need a temporary thread local cache during compilation that is ultimately thrown away after the top level partial is complete.protected ConcurrentHashMap<FragmentKey, Mustache> protected ConcurrentHashMap<String, Mustache> Creates the visitor for compilation.protected MustacheParservoidThis defines how "encoded" values are encoded.private static StringensureForwardSlash(String path) filterText(String appended, boolean startOfLine) Override this method to apply any filtering to text that will appear verbatim in the output template.There is an ExecutorService that is used when executing parallel operations when a Callable is returned from a mustache value or iterable.getFragment(FragmentKey templateKey) protected Function<FragmentKey, Mustache> The object handler knows how to transform names into fields and methods.Given a resource name, construct a reader.intresolvePartialPath(String dir, String name, String extension) Using the directory, namd and extension, resolve a partial to a name.voidIf you need to specify your own executor service you can.voidYou can override the default object handler post construction.voidsetRecursionLimit(int recursionLimit) Maximum recursion limit for partials.Converts your arbitrary name to another name.
-
Field Details
-
mustacheCache
Create the default cache for mustache compilations. This is basically required by the specification to handle recursive templates. -
oh
This is the default object handler. -
mc
This parser should work with any MustacheFactory -
templateCache
New templates that are generated at runtime are cached here. The template key includes the text of the template and the context so we get proper error messages and debugging information. -
recursionLimit
protected int recursionLimit -
mustacheResolver
-
es
-
partialCache
-
-
Constructor Details
-
DefaultMustacheFactory
public DefaultMustacheFactory() -
DefaultMustacheFactory
-
DefaultMustacheFactory
Use the classpath to resolve mustache templates.- Parameters:
classpathResourceRoot- the location in the resources where templates are stored
-
DefaultMustacheFactory
Use the file system to resolve mustache templates.- Parameters:
fileRoot- the root of the file system where templates are stored
-
-
Method Details
-
resolvePartialPath
Using the directory, namd and extension, resolve a partial to a name.- Parameters:
dir-name-extension-- Returns:
-
ensureForwardSlash
-
createMustacheVisitor
Description copied from interface:MustacheFactoryCreates the visitor for compilation.- Specified by:
createMustacheVisitorin interfaceMustacheFactory- Returns:
- visitor
-
getReader
Description copied from interface:MustacheFactoryGiven a resource name, construct a reader.- Specified by:
getReaderin interfaceMustacheFactory- Parameters:
resourceName- used to find the resource- Returns:
- a reader
-
encode
Description copied from interface:MustacheFactoryThis defines how "encoded" values are encoded. It defaults to something appropriate for HTML output.- Specified by:
encodein interfaceMustacheFactory- Parameters:
value- the unencoded valuewriter- where to encode the value
-
getObjectHandler
Description copied from interface:MustacheFactoryThe object handler knows how to transform names into fields and methods.- Specified by:
getObjectHandlerin interfaceMustacheFactory- Returns:
- the handler
-
setObjectHandler
You can override the default object handler post construction.- Parameters:
oh- The object handler to use.
-
getExecutorService
There is an ExecutorService that is used when executing parallel operations when a Callable is returned from a mustache value or iterable.- Returns:
- the executor service
-
setExecutorService
If you need to specify your own executor service you can.- Parameters:
es- The executor service to use for Future evaluation
-
getFragment
-
getFragmentCacheFunction
-
compile
Description copied from interface:MustacheFactoryCreate a mustache given a resource name.- Specified by:
compilein interfaceMustacheFactory- Parameters:
name- the name of the resource- Returns:
- the compiled mustache
-
compile
Description copied from interface:MustacheFactoryCreate a mustache given a reader and a name.- Specified by:
compilein interfaceMustacheFactory- Parameters:
reader- the readername- the name of the resource- Returns:
- the compiled mustache
-
compile
-
translate
Description copied from interface:MustacheFactoryConverts your arbitrary name to another name.- Specified by:
translatein interfaceMustacheFactory- Parameters:
from- the tag to replace- Returns:
- the new tag
-
filterText
Override this method to apply any filtering to text that will appear verbatim in the output template.- Parameters:
appended- The text to be appended to the outputstartOfLine- Are we at the start of the line?- Returns:
- the filtered string
-
setRecursionLimit
public void setRecursionLimit(int recursionLimit) Maximum recursion limit for partials.- Parameters:
recursionLimit- the number of recursions we will attempt before failing
-
getRecursionLimit
public int getRecursionLimit() -
compilePartial
In order to handle recursion, we need a temporary thread local cache during compilation that is ultimately thrown away after the top level partial is complete.- Parameters:
s- the name of the partial to compile- Returns:
- the compiled partial
-
createParser
-
getMustacheCacheFunction
-
createMustacheCache
-
createLambdaCache
-