Package com.github.jknack.handlebars.io
Class URLTemplateLoader
- java.lang.Object
-
- com.github.jknack.handlebars.io.AbstractTemplateLoader
-
- com.github.jknack.handlebars.io.URLTemplateLoader
-
- All Implemented Interfaces:
TemplateLoader
- Direct Known Subclasses:
ClassPathTemplateLoader
,FileTemplateLoader
,ServletContextTemplateLoader
public abstract class URLTemplateLoader extends AbstractTemplateLoader
Strategy interface for loading resources (i.e class path or file system resources)
Templates prefix and suffix
A
TemplateLoader
provides two important properties:- prefix: useful for setting a default prefix where templates are stored.
- suffix: useful for setting a default suffix or file extension for your templates. Default is:
'.hbs'
Usage:
TemplateLoader loader = new ClassPathTemplateLoader(); loader.setPrefix("/templates"); loader.setSuffix(".html"); Handlebars handlebars = new Handlebars(loader); Template template = handlebars.compile("mytemplate"); System.out.println(template.apply("Handlebars.java"));
The template loader resolve
mytemplate
to/templates/mytemplate.html
and load it.- Since:
- 0.1.0
-
-
Field Summary
-
Fields inherited from interface com.github.jknack.handlebars.io.TemplateLoader
DEFAULT_PREFIX, DEFAULT_SUFFIX
-
-
Constructor Summary
Constructors Constructor Description URLTemplateLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TemplateSource
sourceAt(java.lang.String uri)
Get a template source from location.-
Methods inherited from class com.github.jknack.handlebars.io.AbstractTemplateLoader
getCharset, getPrefix, getSuffix, resolve, setCharset, setPrefix, setSuffix
-
-
-
-
Method Detail
-
sourceAt
public TemplateSource sourceAt(java.lang.String uri) throws java.io.IOException
Description copied from interface:TemplateLoader
Get a template source from location.- Parameters:
uri
- The location of the template source. Required.- Returns:
- A new template source.
- Throws:
java.io.IOException
- If the template's source can't be resolved.
-
-