Class HandlebarsViewResolver
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractCachingViewResolver
org.springframework.web.servlet.view.UrlBasedViewResolver
org.springframework.web.servlet.view.AbstractTemplateViewResolver
com.github.jknack.handlebars.springmvc.HandlebarsViewResolver
- All Implemented Interfaces:
com.github.jknack.handlebars.HelperRegistry,org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.core.Ordered,org.springframework.web.context.ServletContextAware,org.springframework.web.servlet.ViewResolver
public class HandlebarsViewResolver
extends org.springframework.web.servlet.view.AbstractTemplateViewResolver
implements org.springframework.beans.factory.InitializingBean, com.github.jknack.handlebars.HelperRegistry
A Handlebars
view resolver.- Since:
- 0.1
- Author:
- edgar.espina
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
org.springframework.web.servlet.view.AbstractCachingViewResolver.CacheFilter -
Field Summary
FieldsFields inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver
FORWARD_URL_PREFIX, REDIRECT_URL_PREFIXFields inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
DEFAULT_CACHE_LIMITFields inherited from interface com.github.jknack.handlebars.HelperRegistry
HELPER_MISSINGFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newHandlebarsViewResolver.HandlebarsViewResolver(com.github.jknack.handlebars.Handlebars handlebars) Creates a newHandlebarsViewResolverthat utilizes the parameter handlebars for the underlying template lifecycle management.HandlebarsViewResolver(com.github.jknack.handlebars.Handlebars handlebars, Class<? extends HandlebarsView> viewClass) Creates a newHandlebarsViewResolverthat utilizes the parameter handlebars for the underlying template lifecycle management.HandlebarsViewResolver(Class<? extends HandlebarsView> viewClass) Creates a newHandlebarsViewResolver. -
Method Summary
Modifier and TypeMethodDescriptionvoidcom.github.jknack.handlebars.Decoratorcom.github.jknack.handlebars.HandlebarsA handlebars instance.<C> com.github.jknack.handlebars.Helper<C>helpers()registerDecorator(String name, com.github.jknack.handlebars.Decorator decorator) registerHelper(String name, com.github.jknack.handlebars.Helper<H> helper) registerHelperMissing(com.github.jknack.handlebars.Helper<H> helper) registerHelpers(File input) registerHelpers(Class<?> helperSource) Register all the helper methods for the given helper source.registerHelpers(Object helperSource) Register all the helper methods for the given helper source.registerHelpers(String filename, InputStream source) registerHelpers(String filename, Reader source) registerHelpers(String filename, String source) registerHelpers(URI location) voidsetBindI18nToMessageSource(boolean bindI18nToMessageSource) voidsetCache(boolean cache) setCharset(Charset charset) voidsetDeletePartialAfterMerge(boolean deletePartialAfterMerge) If true, templates will be deleted once applied.voidsetFailOnMissingFile(boolean failOnMissingFile) True, if the view resolver should fail on missing files.voidsetFormatters(com.github.jknack.handlebars.Formatter... formatters) Set variable formatters.voidsetHandlebarsJsFile(String location) Set the handlebars.js location used it to compile/precompile template to JavaScript.voidsetHelpers(Map<String, com.github.jknack.handlebars.Helper<?>> helpers) Register all the helpers in the map.voidsetHelperSources(List<?> helpers) Register all the helpers in the list.voidsetRegisterMessageHelper(boolean registerMessageHelper) True, if the message helper (based onMessageSource) should be registered.voidsetTemplateCache(com.github.jknack.handlebars.cache.TemplateCache templateCache) voidsetValueResolvers(com.github.jknack.handlebars.ValueResolver... valueResolvers) Set the value resolvers.Same assetRegisterMessageHelper(boolean)with a false argument.Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateViewResolver
setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpersMethods inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver
getAttributesMap, getOrder, getRedirectHosts, setAttributes, setAttributesMap, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setOrder, setPrefix, setRedirectContextRelative, setRedirectHosts, setRedirectHttp10Compatible, setRequestContextAttribute, setSuffix, setViewClass, setViewNamesMethods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
clearCache, getCacheFilter, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCacheFilter, setCacheLimit, setCacheUnresolvedMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, setApplicationContext
-
Field Details
-
DEFAULT_CONTENT_TYPE
The default content type.- See Also:
-
-
Constructor Details
-
HandlebarsViewResolver
Creates a newHandlebarsViewResolver.- Parameters:
viewClass- The view's class. Required.
-
HandlebarsViewResolver
public HandlebarsViewResolver()Creates a newHandlebarsViewResolver. -
HandlebarsViewResolver
public HandlebarsViewResolver(com.github.jknack.handlebars.Handlebars handlebars) Creates a newHandlebarsViewResolverthat utilizes the parameter handlebars for the underlying template lifecycle management.- Parameters:
handlebars- TheHandlebarsinstance used for template lifecycle management. Required.
-
HandlebarsViewResolver
public HandlebarsViewResolver(com.github.jknack.handlebars.Handlebars handlebars, Class<? extends HandlebarsView> viewClass) Creates a newHandlebarsViewResolverthat utilizes the parameter handlebars for the underlying template lifecycle management.- Parameters:
handlebars- TheHandlebarsinstance used for template lifecycle management. Required.viewClass- The view's class. Required.
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
getHandlebars
public com.github.jknack.handlebars.Handlebars getHandlebars()A handlebars instance.- Returns:
- A handlebars instance.
-
setValueResolvers
public void setValueResolvers(com.github.jknack.handlebars.ValueResolver... valueResolvers) Set the value resolvers.- Parameters:
valueResolvers- The value resolvers. Required.
-
setFormatters
public void setFormatters(com.github.jknack.handlebars.Formatter... formatters) Set variable formatters.- Parameters:
formatters- Formatters to add.
-
setHandlebarsJsFile
Set the handlebars.js location used it to compile/precompile template to JavaScript.Using handlebars.js 2.x:
Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v2.0.0.js");Using handlebars.js 1.x:
Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v4.7.7.js");Default handlebars.js ishandlebars-v4.7.7.js.- Parameters:
location- A classpath location of the handlebar.js file.
-
setFailOnMissingFile
public void setFailOnMissingFile(boolean failOnMissingFile) True, if the view resolver should fail on missing files. Default is: true.- Parameters:
failOnMissingFile- True, if the view resolver should fail on missing files. Default is: true.
-
setHelpers
Register all the helpers in the map.- Parameters:
helpers- The helpers to be registered. Required.- See Also:
-
Handlebars.registerHelper(String, Helper)
-
setHelperSources
Register all the helpers in the list. Each element of the list must be a helper source.- Parameters:
helpers- The helpers to be registered. Required.- See Also:
-
Handlebars.registerHelpers(Class)Handlebars.registerHelpers(Object)
-
registerHelpers
Register all the helper methods for the given helper source.A helper method looks like:
public static? CharSequence methodName(context?, parameter*, options?) { }Where:- A method can/can't be static
- The method's name became the helper's name
- Context, parameters and options are all optionals
- If context and options are present they must be the first and last arguments of the method
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Parameters:
helperSource- The helper source. Required.- Returns:
- This handlebars object.
-
registerHelpers
Register all the helper methods for the given helper source.A helper method looks like:
public static? CharSequence methodName(context?, parameter*, options?) { }Where:- A method can/can't be static
- The method's name became the helper's name
- Context, parameters and options are all optionals
- If context and options are present they must be the first and last arguments of the method
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Parameters:
helperSource- The helper source. Required.- Returns:
- This handlebars object.
-
helper
- Specified by:
helperin interfacecom.github.jknack.handlebars.HelperRegistry
-
helpers
- Specified by:
helpersin interfacecom.github.jknack.handlebars.HelperRegistry
-
registerHelper
public <H> HandlebarsViewResolver registerHelper(String name, com.github.jknack.handlebars.Helper<H> helper) - Specified by:
registerHelperin interfacecom.github.jknack.handlebars.HelperRegistry
-
registerHelperMissing
public <H> HandlebarsViewResolver registerHelperMissing(com.github.jknack.handlebars.Helper<H> helper) - Specified by:
registerHelperMissingin interfacecom.github.jknack.handlebars.HelperRegistry
-
registerHelpers
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Throws:
Exception
-
registerHelpers
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Throws:
Exception
-
registerHelpers
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Throws:
Exception
-
registerHelpers
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Throws:
Exception
-
registerHelpers
- Specified by:
registerHelpersin interfacecom.github.jknack.handlebars.HelperRegistry- Throws:
IOException
-
withoutMessageHelper
Same assetRegisterMessageHelper(boolean)with a false argument. The message helper wont be registered when you call this method.- Returns:
- This handlebars view resolver.
-
setRegisterMessageHelper
public void setRegisterMessageHelper(boolean registerMessageHelper) True, if the message helper (based onMessageSource) should be registered. Default is: true.- Parameters:
registerMessageHelper- True, if the message helper (based onMessageSource) should be registered. Default is: true.
-
setBindI18nToMessageSource
public void setBindI18nToMessageSource(boolean bindI18nToMessageSource) - Parameters:
bindI18nToMessageSource- If true, the i18n helpers will use aMessageSourceinstead of a plainResourceBundle. Default is: false.
-
setDeletePartialAfterMerge
public void setDeletePartialAfterMerge(boolean deletePartialAfterMerge) If true, templates will be deleted once applied. Useful, in some advanced template inheritance use cases. Used by{{#block}} helper. Default is: false. At any time you can override the default setup with:{{#block "footer" delete-after-merge=true}}- Parameters:
deletePartialAfterMerge- True for clearing up templates once they got applied. Used by{{#block}} helper.
-
setCache
public void setCache(boolean cache) - Overrides:
setCachein classorg.springframework.web.servlet.view.AbstractCachingViewResolver
-
setTemplateCache
public void setTemplateCache(com.github.jknack.handlebars.cache.TemplateCache templateCache) - Parameters:
templateCache- Set a template cache. Default is:HighConcurrencyTemplateCache.
-
decorator
- Specified by:
decoratorin interfacecom.github.jknack.handlebars.HelperRegistry
-
registerDecorator
public HandlebarsViewResolver registerDecorator(String name, com.github.jknack.handlebars.Decorator decorator) - Specified by:
registerDecoratorin interfacecom.github.jknack.handlebars.HelperRegistry
-
setCharset
- Specified by:
setCharsetin interfacecom.github.jknack.handlebars.HelperRegistry
-