com.github.jknack.handlebars
Class Handlebars

java.lang.Object
  extended by com.github.jknack.handlebars.Handlebars

public class Handlebars
extends Object

Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.

Usage:

 Handlebars handlebars = new Handlebars();

 Template template = handlebars.compile("Hello {{name}}!");

 Person person = new Person("John", "Doe");

 String output = template.apply(person);

 assertEquals("Hello John!", output);
 

Since:
0.1.0
Author:
edgar.espina

Nested Class Summary
static class Handlebars.SafeString
          A Handlebars.SafeString tell Handlebars that the content should not be escaped as HTML.
static class Handlebars.Utils
          Utilities function like: Handlebars.Utils.escapeExpression(CharSequence) and Handlebars.Utils.isEmpty(Object).
 
Field Summary
static String DELIM_END
          The default end delimiter.
static String DELIM_START
          The default start delimiter.
static String HELPER_MISSING
          The missing helper's name.
 
Constructor Summary
Handlebars()
          Creates a new Handlebars with a ClassTemplateLoader and no cache.
Handlebars(TemplateLoader loader)
          Creates a new Handlebars with no cache.
Handlebars(TemplateLoader loader, TemplateCache cache)
          Creates a new Handlebars.
 
Method Summary
 Template compile(String input)
          Compile a handlebars template.
 Template compile(String input, String startDelimiter, String endDelimiter)
          Compile a handlebars template.
 Template compile(URI uri)
          Compile the resource located at the given uri.
 Template compile(URI uri, String startDelimiter, String endDelimiter)
          Compile the resource located at the given uri.
static void debug(String message)
          Log the given message as debug and format the message within the args.
static void debug(String message, Object... args)
          Log the given message as debug and format the message within the args.
static void error(String message)
          Log the given message as error and format the message within the args.
static void error(String message, Object... args)
          Log the given message as error and format the message within the args.
 TemplateLoader getTemplateLoader()
          The resource locator.
<C> Helper<C>
helper(String name)
          Find a helper by it's name.
 boolean isStringParams()
          If true, missing helper parameters will be resolve to their names.
static void log(String message)
          Log the given message and format the message within the args.
static void log(String message, Object... args)
          Log the given message and format the message within the args.
<H> Handlebars
registerHelper(String name, Helper<H> helper)
          Register a helper in the helper registry.
 void setStringParams(boolean stringParams)
          If true, missing helper parameters will be resolve to their names.
static void warn(String message)
          Log the given message as warn and format the message within the args.
static void warn(String message, Object... args)
          Log the given message as warn and format the message within the args.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HELPER_MISSING

public static final String HELPER_MISSING
The missing helper's name.

See Also:
Constant Field Values

DELIM_START

public static final String DELIM_START
The default start delimiter.

See Also:
Constant Field Values

DELIM_END

public static final String DELIM_END
The default end delimiter.

See Also:
Constant Field Values
Constructor Detail

Handlebars

public Handlebars(TemplateLoader loader,
                  TemplateCache cache)
Creates a new Handlebars.

Parameters:
loader - The template loader. Required.
cache - The template cache. Required.

Handlebars

public Handlebars(TemplateLoader loader)
Creates a new Handlebars with no cache.

Parameters:
loader - The template loader. Required.

Handlebars

public Handlebars()
Creates a new Handlebars with a ClassTemplateLoader and no cache.

Method Detail

compile

public Template compile(URI uri)
                 throws IOException
Compile the resource located at the given uri.

Parameters:
uri - The resource's location. Required.
Returns:
A compiled template.
Throws:
IOException - If the resource cannot be loaded.

compile

public Template compile(URI uri,
                        String startDelimiter,
                        String endDelimiter)
                 throws IOException
Compile the resource located at the given uri.

Parameters:
uri - The resource's location. Required.
startDelimiter - The start delimiter. Required.
endDelimiter - The end delimiter. Required.
Returns:
A compiled template.
Throws:
IOException - If the resource cannot be loaded.

compile

public Template compile(String input)
                 throws IOException
Compile a handlebars template.

Parameters:
input - The handlebars input. Required.
Returns:
A compiled template.
Throws:
IOException - If the resource cannot be loaded.

compile

public Template compile(String input,
                        String startDelimiter,
                        String endDelimiter)
                 throws IOException
Compile a handlebars template.

Parameters:
input - The input text. Required.
startDelimiter - The start delimiter. Required.
endDelimiter - The end delimiter. Required.
Returns:
A compiled template.
Throws:
IOException - If the resource cannot be loaded.

helper

public <C> Helper<C> helper(String name)
Find a helper by it's name.

Type Parameters:
C - The helper runtime type.
Parameters:
name - The helper's name. Required.
Returns:
A helper or null if it's not found.

registerHelper

public <H> Handlebars registerHelper(String name,
                                     Helper<H> helper)
Register a helper in the helper registry.

Type Parameters:
H - The helper runtime type.
Parameters:
name - The helper's name. Required.
helper - The helper object. Required.
Returns:
This handlebars.

getTemplateLoader

public TemplateLoader getTemplateLoader()
The resource locator.

Returns:
The resource locator.

isStringParams

public boolean isStringParams()
If true, missing helper parameters will be resolve to their names.

Returns:
If true, missing helper parameters will be resolve to their names.

setStringParams

public void setStringParams(boolean stringParams)
If true, missing helper parameters will be resolve to their names.

Parameters:
stringParams - If true, missing helper parameters will be resolve to their names.

log

public static void log(String message,
                       Object... args)
Log the given message and format the message within the args.

Parameters:
message - The log's message.
args - The optional args.
See Also:
String#format(String, Object...)

log

public static void log(String message)
Log the given message and format the message within the args.

Parameters:
message - The log's message.
See Also:
String#format(String, Object...)

warn

public static void warn(String message,
                        Object... args)
Log the given message as warn and format the message within the args.

Parameters:
message - The log's message.
args - The optional args.
See Also:
String#format(String, Object...)

warn

public static void warn(String message)
Log the given message as warn and format the message within the args.

Parameters:
message - The log's message.
See Also:
String#format(String, Object...)

debug

public static void debug(String message,
                         Object... args)
Log the given message as debug and format the message within the args.

Parameters:
message - The log's message.
args - The optional args.
See Also:
String#format(String, Object...)

debug

public static void debug(String message)
Log the given message as debug and format the message within the args.

Parameters:
message - The log's message.
See Also:
String#format(String, Object...)

error

public static void error(String message,
                         Object... args)
Log the given message as error and format the message within the args.

Parameters:
message - The log's message.
args - The optional args.
See Also:
String#format(String, Object...)

error

public static void error(String message)
Log the given message as error and format the message within the args.

Parameters:
message - The log's message.
See Also:
String#format(String, Object...)


Copyright © 2012. All Rights Reserved.