Rythm provides a set of built-in transformers to easy your work
Object
type. In other words, you are use them to transform variable of any type, not only String
s.
If a variable been transformed is not a String
, then it will be converted to String
and then be processed by the transformer
Use escaping transformers when needed. (Usually you don't need to as Rythm is intelligent enough to escape your emissions with property escape scheme. Check it out at here).
Emit expression using the current escape scheme.
@foo.escape()
has exactly the same effect of @foo
.
@args Bar bar
@bar.raw()
@bar.escape()
@bar
Alias:
escapeHtml()
escape("html")
Emit expression using the html escape scheme.
@args Bar bar
@raw() {
@bar
@bar.escapeHtml()
@bar.escapeHTML()
@bar.escape("html")
}
Alias:
escapeXml()
escape("xml")
Emit expression using the xml escape scheme.
@args Bar bar
@raw() {
@bar
@bar.escapeXml()
@bar.escapeXML()
@bar.escape("xml")
}
Alias:
escapeJavaScript()
escape("js")
Emit expression using the js escape scheme.
@args Bar bar
@raw() {
@bar
@bar.escapeJS()
@bar.escapeJavaScript()
@bar.escape("js")
}
Alias:
escapeJson()
escape("json")
Emit expression using the json escape scheme.
@args Bar bar
@raw() {
@bar
@bar.escapeJSON()
@bar.escapeJson()
@bar.escape("json")
}
Alias:
escapeCsv()
escape("csv")
Emit expression using the csv escape scheme.
@args Bar bar
@raw() {
@bar
@bar.escapeCSV()
@bar.escapeCsv()
@bar.escape("csv")
}
format()
format(String pattern)
format(String pattern, Locale locale)
format a number using pattern and locale. Note this transformer only applies to Number type variable.
If locale is not specified, then a call to I18N.locale() is used to fetch the locale. If pattern is specified, the locale is used to get the DecimalFormatSymbols to construct the DecimalFormat object, otherwise, the locale is used to get NumberFormat object.
@args Number x, Number y, Number z
[@x]: @x.format()
---
[@y]: @y.format("###,000,000.00")
---
[@z]: @z.format("###,000,000.0000", Locale.SIMPLIFIED_CHINESE)
format()
format(String pattern)
format(String pattern, Locale locale)
format(String pattern, Locale locale, String timezone)
format a date using pattern, locale and timezone string. Note this transformer only applies to java.util.Date type variable.
If locale is not specified, then a call to I18N.locale() is used to fetch the locale. If pattern is specified then it is used to construct the SimpleDateFormat to format the date; otherwise DateFormat.getDateInstance(DateFormat.Default, locale) will be used to create the date formatter. At last if timezone
is specified it will be set to the date format.
@args Date x = new Date()
[@x]: @x.format()
---
[@x]: @x.format("yyyy-MM-dd")
---
[@x]: @x.format(null, Locale.SIMPLIFIED_CHINESE)
---
[@x]: @x.format(null, Locale.US, "GMT")
formatCurrency()
formatCurrency(String currencyCode)
formatCurrency(String currencyCode, Locale locale)
Format currency with currency code and locale specified. Unlike format()
transformer for Number, formatCurrency
does not require the variable type be Number
or it's subtype, however formatCurrency
is NOT null safe, so you need to use null-safe expression notation if you want to make it null safe.
@args Object o, Number n
[@o]: @o?.formatCurrency()
----
[@n]: @n?.formatCurrency()
- http://docs.oracle.com/javase/6/docs/api/java/util/Currency.html
- http://docs.oracle.com/javase/6/docs/api/java/text/NumberFormat.html#getCurrency()
Use string operation transformers to manupulate the output string.
Captialize the first character of each words. Words are separated by non digits-alphabetic characters.
@args Bar bar, String s
@bar
@bar.capitalizeWords()
------------
@s
@s.capitalizeWords()
Replace accent character (usually found in European languages) with corresponding non-accent character
@args Bar bar
@bar
@bar.noAccents()
Make the first letter of the object to be lowercase or uppercase
@args Bar bar, String s
@bar
@bar.lowerFirst()
---
@s
@s.capFirst()
Change each word from underscore style to camel case style
@args Bar bar
@bar
@bar.camelCase()
TBD
TBD
TBD
TBD
Change line break to html <br/>
element
@args Bar bar
@bar
@bar.nl2br()
Encode URL using UTF-8
@args Bar bar
@bar
@bar.urlEncode()
Internationalization a string or string of an object
@args String x
//-- default locale
@x: @x.i18n()
// -- locale: en
@locale("en"){
@x: @x.i18n()
}
// -- locale: zh_CN
@locale("zh_CN") {
@x: @x.i18n()
}
join()
- join use,
join(String separator)
join(char separator)
Join an Iterable with default ,
or specified separator.
@args Bar bar
@bar
@bar.nl2br()