com.github.jknack.handlebars
Enum StringHelpers

java.lang.Object
  extended by java.lang.Enum<StringHelpers>
      extended by com.github.jknack.handlebars.StringHelpers
All Implemented Interfaces:
Helper<Object>, Serializable, Comparable<StringHelpers>

public enum StringHelpers
extends Enum<StringHelpers>
implements Helper<Object>

Commons string function helpers.

Since:
0.2.2
Author:
edgar.espina

Enum Constant Summary
ABBREVIATE
          Truncates a string if it is longer than the specified number of characters.
CAPITALIZE
          Capitalizes all the whitespace separated words in a String.
CAPITALIZE_FIRST
          Capitalizes the first character of the value.
CENTER
          Centers the value in a field of a given width.
CUT
          Removes all values of arg from the given string.
DATE_FORMAT
           Usage:
DEFAULT
          If value evaluates to False, uses the given default.
JOIN
          Joins a list with a string, like Python's str.join(list) For example:
LJUST
          Left-aligns the value in a field of a given width.
LOWER
          Converts a string into all lowercase.
RJUST
          Right-aligns the value in a field of a given width.
SLUGIFY
          Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens.
STRING_FORMAT
          Formats the variable according to the argument, a string formatting specifier.
STRIP_TAGS
          Strips all [X]HTML tags.
UPPER
          Converts a string into all lowercase.
WORD_WRAP
          Wraps words at specified line length.
YESNO
          Maps values for true, false and (optionally) null, to the strings "yes", "no", "maybe".
 
Method Summary
 String helperName()
          Return the helper's name.
static void register(Handlebars handlebars)
          Regiter all the text helpers.
static StringHelpers valueOf(String name)
          Returns the enum constant of this type with the specified name.
static StringHelpers[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.github.jknack.handlebars.Helper
apply
 

Enum Constant Detail

CAPITALIZE_FIRST

public static final StringHelpers CAPITALIZE_FIRST
Capitalizes the first character of the value. For example:
 {{capFirst value}}
 
If value is "handlebars.java", the output will be "Handlebars.java".


CENTER

public static final StringHelpers CENTER
Centers the value in a field of a given width. For example:
 {{center value size=19 [pad="char"] }}
 
If value is "Handlebars.java", the output will be " Handlebars.java ".


CUT

public static final StringHelpers CUT
Removes all values of arg from the given string. For example:
 {{cut value [" "]}}
 
If value is "String with spaces", the output will be "Stringwithspaces".


DEFAULT

public static final StringHelpers DEFAULT
If value evaluates to False, uses the given default. Otherwise, uses the value. For example:
 {{default value ["nothing"] }}
 If value is "" (the empty string), the output will be nothing.
 


JOIN

public static final StringHelpers JOIN
Joins a list with a string, like Python's str.join(list) For example:
 {{join value " // " [prefix=""] [suffix=""]}}
 
If value is the list ['a', 'b', 'c'], the output will be the string "a // b // c".


LJUST

public static final StringHelpers LJUST
Left-aligns the value in a field of a given width. Argument: field size For example:
 {{ljust value 20 [pad=" "] }}
 
If value is Handlebars.java, the output will be "Handlebars.java ".


RJUST

public static final StringHelpers RJUST
Right-aligns the value in a field of a given width. Argument: field size For example:
 {{rjust value 20 [pad=" "] }}
 
If value is Handlebars.java, the output will be " Handlebars.java".


LOWER

public static final StringHelpers LOWER
Converts a string into all lowercase. For example:
 {{lower value}}
 
If value is 'Still MAD At Yoko', the output will be 'still mad at yoko'.


UPPER

public static final StringHelpers UPPER
Converts a string into all lowercase. For example:
 {{upper value}}
 
If value is 'Hello', the output will be 'HELLO'.


SLUGIFY

public static final StringHelpers SLUGIFY
Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. For example:
 {{slugify value}}
 
If value is "Joel is a slug", the output will be "joel-is-a-slug".


STRING_FORMAT

public static final StringHelpers STRING_FORMAT
Formats the variable according to the argument, a string formatting specifier. For example:
 {{stringFormat string param0 param1 ... paramN}}
 
If value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".

See Also:
String.format(String, Object...)

STRIP_TAGS

public static final StringHelpers STRIP_TAGS
Strips all [X]HTML tags. For example:
 {{stripTags value}}
 


CAPITALIZE

public static final StringHelpers CAPITALIZE
Capitalizes all the whitespace separated words in a String. For example:
 {{ capitalize value [fully=false]}}
 
If value is "my first post", the output will be "My First Post".


ABBREVIATE

public static final StringHelpers ABBREVIATE
Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("..."). Argument: Number of characters to truncate to For example:
 {{abbreviate value 13 }}
 
If value is "Handlebars rocks", the output will be "Handlebars...".


WORD_WRAP

public static final StringHelpers WORD_WRAP
Wraps words at specified line length. Argument: number of characters at which to wrap the text For example:
 {{ wordWrap value 5 }}
 
If value is Joel is a slug, the output would be:
 Joel
 is a
 slug
 


YESNO

public static final StringHelpers YESNO
Maps values for true, false and (optionally) null, to the strings "yes", "no", "maybe". For example:
 {{yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}
 


DATE_FORMAT

public static final StringHelpers DATE_FORMAT

Usage:

    {{dateFormat date ["format"]}}
 
Format parameters is one of: Otherwise, the default formatter will be used.

Method Detail

values

public static StringHelpers[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (StringHelpers c : StringHelpers.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static StringHelpers valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

helperName

public String helperName()
Return the helper's name.

Returns:
The helper's name.

register

public static void register(Handlebars handlebars)
Regiter all the text helpers.

Parameters:
handlebars - The helper's owner.


Copyright © 2012. All Rights Reserved.