Package ninja.template
Class TemplateEngineFreemarker
- java.lang.Object
-
- ninja.template.TemplateEngineFreemarker
-
- All Implemented Interfaces:
TemplateEngine
@Singleton public class TemplateEngineFreemarker extends Object implements TemplateEngine
-
-
Field Summary
Fields Modifier and Type Field Description static String
FREEMARKER_CONFIGURATION_FILE_SUFFIX
static String
FREEMARKER_CONFIGURATION_OLDVERSION
-
Constructor Summary
Constructors Constructor Description TemplateEngineFreemarker(Messages messages, Lang lang, org.slf4j.Logger logger, TemplateEngineHelper templateEngineHelper, TemplateEngineManager templateEngineManager, TemplateEngineFreemarkerReverseRouteMethod templateEngineFreemarkerReverseRouteMethod, TemplateEngineFreemarkerAssetsAtMethod templateEngineFreemarkerAssetsAtMethod, TemplateEngineFreemarkerWebJarsAtMethod templateEngineFreemarkerWebJarsAtMethod, NinjaProperties ninjaProperties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description freemarker.template.Configuration
getConfiguration()
Allows to modify the FreeMarker configuration.String
getContentType()
Get the content type this template engine rendersString
getSuffixOfTemplatingEngine()
For instance returns ".ftl.html" Or .ftl.json.void
invoke(Context context, Result result)
Render the given object to the given contextvoid
throwRenderingException(Context context, Result result, Exception cause, String knownTemplateSourcePath)
-
-
-
Field Detail
-
FREEMARKER_CONFIGURATION_FILE_SUFFIX
public static final String FREEMARKER_CONFIGURATION_FILE_SUFFIX
- See Also:
- Constant Field Values
-
FREEMARKER_CONFIGURATION_OLDVERSION
public static final String FREEMARKER_CONFIGURATION_OLDVERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TemplateEngineFreemarker
@Inject public TemplateEngineFreemarker(Messages messages, Lang lang, org.slf4j.Logger logger, TemplateEngineHelper templateEngineHelper, TemplateEngineManager templateEngineManager, TemplateEngineFreemarkerReverseRouteMethod templateEngineFreemarkerReverseRouteMethod, TemplateEngineFreemarkerAssetsAtMethod templateEngineFreemarkerAssetsAtMethod, TemplateEngineFreemarkerWebJarsAtMethod templateEngineFreemarkerWebJarsAtMethod, NinjaProperties ninjaProperties) throws Exception
- Throws:
Exception
-
-
Method Detail
-
invoke
public void invoke(Context context, Result result)
Description copied from interface:TemplateEngine
Render the given object to the given context- Specified by:
invoke
in interfaceTemplateEngine
- Parameters:
context
- The context to render toresult
- The result to render
-
throwRenderingException
public void throwRenderingException(Context context, Result result, Exception cause, String knownTemplateSourcePath)
-
getContentType
public String getContentType()
Description copied from interface:TemplateEngine
Get the content type this template engine renders- Specified by:
getContentType
in interfaceTemplateEngine
- Returns:
- The content type this template engine renders
-
getSuffixOfTemplatingEngine
public String getSuffixOfTemplatingEngine()
Description copied from interface:TemplateEngine
For instance returns ".ftl.html" Or .ftl.json.Or anything else. To display error messages in a nice way...
But Gson for instance does not use a template to render stuff. Therefore it will return null
- Specified by:
getSuffixOfTemplatingEngine
in interfaceTemplateEngine
- Returns:
- name of suffix or null if engine is not using a template on disk.
-
getConfiguration
public freemarker.template.Configuration getConfiguration()
Allows to modify the FreeMarker configuration. According to the FreeMarker documentation, the configuration will be thread-safe once all settings have been set via a safe publication technique. Therefore, consider modifying this configuration only within the configure() method of your application Module singleton.- Returns:
- the freemarker configuration object
-
-