public enum StringHelpers extends java.lang.Enum<StringHelpers> implements Helper<java.lang.Object>
Enum Constant and Description |
---|
abbreviate
Truncates a string if it is longer than the specified number of characters.
|
capitalize
Capitalizes all the whitespace separated words in a String.
|
capitalizeFirst
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.
|
dateFormat
Usage:
|
defaultIfEmpty
If value evaluates to False, uses the given default.
|
join
Joins an array, iterator or an iterable with a string.
|
ljust
Left-aligns the value in a field of a given width.
|
lower
Converts a string into all lowercase.
|
now
Usage:
|
numberFormat
Usage:
|
replace
Replaces each substring of this string that matches the literal target
sequence with the specified literal replacement sequence.
|
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.
|
stringFormat
Formats the variable according to the argument, a string formatting
specifier.
|
stripTags
Strips all [X]HTML tags.
|
substring
Returns a new
CharSequence that is a subsequence of this sequence. |
upper
Converts a string into all lowercase.
|
wordWrap
Wraps words at specified line length.
|
yesno
Maps values for true, false and (optionally) null, to the strings "yes",
"no", "maybe".
|
Modifier and Type | Method and Description |
---|---|
java.lang.CharSequence |
apply(java.lang.Object context,
Options options)
Apply the helper to the context.
|
static void |
register(Handlebars handlebars)
Register all the text helpers.
|
void |
registerHelper(Handlebars handlebars)
Register the helper in a handlebars instance.
|
static StringHelpers |
valueOf(java.lang.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.
|
public static final StringHelpers capitalizeFirst
{{capFirst value}}If value is "handlebars.java", the output will be "Handlebars.java".
public static final StringHelpers center
{{center value size=19 [pad="char"] }}If value is "Handlebars.java", the output will be " Handlebars.java ".
public static final StringHelpers cut
{{cut value [" "]}}If value is "String with spaces", the output will be "Stringwithspaces".
public static final StringHelpers defaultIfEmpty
{{defaultIfEmpty value ["nothing"] }} If value is "" (the empty string), the output will be nothing.
public static final StringHelpers join
{{join value " // " [prefix=""] [suffix=""]}}
If value is the list ['a', 'b', 'c'], the output will be the string "a // b // c".
Or:{{join "a" "b" "c" " // " [prefix=""] [suffix=""]}} Join the "a", "b", "c", the output will be the string "a // b // c".
public static final StringHelpers ljust
{{ljust value 20 [pad=" "] }}If value is Handlebars.java, the output will be "Handlebars.java ".
public static final StringHelpers rjust
{{rjust value 20 [pad=" "] }}If value is Handlebars.java, the output will be " Handlebars.java".
public static final StringHelpers substring
CharSequence
that is a subsequence of this sequence.
The subsequence starts with the char
value at the specified index and
ends with the char
value at index end - 1
Argument: start offset
end offset
For example:
{{substring value 11 }}If value is Handlebars.java, the output will be "java". or
{{substring value 0 10 }}If value is Handlebars.java, the output will be "Handlebars".
public static final StringHelpers lower
{{lower value}}If value is 'Still MAD At Yoko', the output will be 'still mad at yoko'.
public static final StringHelpers upper
{{upper value}}If value is 'Hello', the output will be 'HELLO'.
public static final StringHelpers slugify
{{slugify value}}If value is "Joel is a slug", the output will be "joel-is-a-slug".
public static final StringHelpers stringFormat
{{stringFormat string param0 param1 ... paramN}}If value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".
String.format(String, Object...)
public static final StringHelpers stripTags
{{stripTags value}}
public static final StringHelpers capitalize
{{ capitalize value [fully=false]}}If value is "my first post", the output will be "My First Post".
public static final StringHelpers abbreviate
{{abbreviate value 13 }}If value is "Handlebars rocks", the output will be "Handlebars...".
public static final StringHelpers wordWrap
{{ wordWrap value 5 }}If value is Joel is a slug, the output would be:
Joel is a slug
public static final StringHelpers replace
{{ replace value "..." "rocks" }}If value is "Handlebars ...", the output will be "Handlebars rocks".
public static final StringHelpers yesno
{{yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}
public static final StringHelpers dateFormat
Usage:
{{dateFormat date ["format"] [format="format"][tz=timeZone|timeZoneId]}}Format parameters is one of:
public static final StringHelpers numberFormat
Usage:
{{numberFormat number ["format"] [locale=default]}}Format parameters is one of:
More options:
RoundingMode
used in this NumberFormat.NumberFormat
,
DecimalFormat
public static final StringHelpers now
Usage:
{{now ["format"] [tz=timeZone|timeZoneId]}}Format parameters is one of:
public static StringHelpers[] values()
for (StringHelpers c : StringHelpers.values()) System.out.println(c);
public static StringHelpers valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic java.lang.CharSequence apply(java.lang.Object context, Options options) throws java.io.IOException
Helper
public void registerHelper(Handlebars handlebars)
handlebars
- A handlebars object. Required.public static void register(Handlebars handlebars)
handlebars
- The helper's owner. Required.Copyright © 2010 - 2020 Adobe. All Rights Reserved