public class DefaultMustacheFactory extends Object implements MustacheFactory
Modifier and Type | Field and Description |
---|---|
protected ExecutorService |
es |
protected MustacheParser |
mc
This parser should work with any MustacheFactory
|
protected ConcurrentHashMap<String,Mustache> |
mustacheCache
Create the default cache for mustache compilations.
|
protected ObjectHandler |
oh
This is the default object handler.
|
protected int |
recursionLimit |
protected ConcurrentHashMap<FragmentKey,Mustache> |
templateCache
New templates that are generated at runtime are cached here.
|
Constructor and Description |
---|
DefaultMustacheFactory() |
DefaultMustacheFactory(File fileRoot)
Use the file system to resolve mustache templates.
|
DefaultMustacheFactory(MustacheResolver mustacheResolver) |
DefaultMustacheFactory(String classpathResourceRoot)
Use the classpath to resolve mustache templates.
|
Modifier and Type | Method and Description |
---|---|
Mustache |
compile(Reader reader,
String name)
Create a mustache given a reader and a name.
|
Mustache |
compile(Reader reader,
String file,
String sm,
String em) |
Mustache |
compile(String name)
Create a mustache given a resource name.
|
Mustache |
compilePartial(String s)
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> |
createLambdaCache() |
protected ConcurrentHashMap<String,Mustache> |
createMustacheCache() |
MustacheVisitor |
createMustacheVisitor()
Creates the visitor for compilation.
|
void |
encode(String value,
Writer writer)
This defines how "encoded" values are encoded.
|
String |
filterText(String appended,
boolean startOfLine)
Override this method to apply any filtering to text that will appear
verbatim in the output template.
|
ExecutorService |
getExecutorService()
There is an ExecutorService that is used when executing parallel
operations when a Callable is returned from a mustache value or iterable.
|
Mustache |
getFragment(FragmentKey templateKey) |
protected Function<FragmentKey,Mustache> |
getFragmentCacheFunction() |
protected Function<String,Mustache> |
getMustacheCacheFunction() |
ObjectHandler |
getObjectHandler()
The object handler knows how to transform names into fields and methods.
|
Reader |
getReader(String resourceName)
Given a resource name, construct a reader.
|
int |
getRecursionLimit() |
String |
resolvePartialPath(String dir,
String name,
String extension)
Using the directory, namd and extension, resolve a partial to a name.
|
void |
setExecutorService(ExecutorService es)
If you need to specify your own executor service you can.
|
void |
setObjectHandler(ObjectHandler oh)
You can override the default object handler post construction.
|
void |
setRecursionLimit(int recursionLimit)
Maximum recursion limit for partials.
|
String |
translate(String from)
Converts your arbitrary name to another name.
|
protected final ConcurrentHashMap<String,Mustache> mustacheCache
protected ObjectHandler oh
protected final MustacheParser mc
protected final ConcurrentHashMap<FragmentKey,Mustache> templateCache
protected int recursionLimit
protected ExecutorService es
public DefaultMustacheFactory()
public DefaultMustacheFactory(MustacheResolver mustacheResolver)
public DefaultMustacheFactory(String classpathResourceRoot)
classpathResourceRoot
- the location in the resources where templates are storedpublic DefaultMustacheFactory(File fileRoot)
fileRoot
- the root of the file system where templates are storedpublic String resolvePartialPath(String dir, String name, String extension)
dir
- name
- extension
- public MustacheVisitor createMustacheVisitor()
MustacheFactory
createMustacheVisitor
in interface MustacheFactory
public Reader getReader(String resourceName)
MustacheFactory
getReader
in interface MustacheFactory
resourceName
- used to find the resourcepublic void encode(String value, Writer writer)
MustacheFactory
encode
in interface MustacheFactory
value
- the unencoded valuewriter
- where to encode the valuepublic ObjectHandler getObjectHandler()
MustacheFactory
getObjectHandler
in interface MustacheFactory
public void setObjectHandler(ObjectHandler oh)
oh
- The object handler to use.public ExecutorService getExecutorService()
public void setExecutorService(ExecutorService es)
es
- The executor service to use for Future evaluationpublic Mustache getFragment(FragmentKey templateKey)
protected Function<FragmentKey,Mustache> getFragmentCacheFunction()
public Mustache compile(String name)
MustacheFactory
compile
in interface MustacheFactory
name
- the name of the resourcepublic Mustache compile(Reader reader, String name)
MustacheFactory
compile
in interface MustacheFactory
reader
- the readername
- the name of the resourcepublic String translate(String from)
MustacheFactory
translate
in interface MustacheFactory
from
- the tag to replacepublic String filterText(String appended, boolean startOfLine)
appended
- The text to be appended to the outputstartOfLine
- Are we at the start of the line?public void setRecursionLimit(int recursionLimit)
recursionLimit
- the number of recursions we will attempt before failingpublic int getRecursionLimit()
public Mustache compilePartial(String s)
s
- the name of the partial to compileprotected ConcurrentHashMap<String,Mustache> createMustacheCache()
protected ConcurrentHashMap<FragmentKey,Mustache> createLambdaCache()
Copyright © 2018. All rights reserved.