Package io.quarkus.qute
Class Qute
- java.lang.Object
-
- io.quarkus.qute.Qute
-
public final class Qute extends Object
Provides quick and convenient access to the engine instance stored in a static variable. If a specific engine instance is not set via thesetEngine(Engine)method a default engine is created lazily.Moreover, the convenient
fmt()methods that can be used to format messages easily.Qute.fmt("Hello {}!", "Quarkus"); // => Hello Quarkus! Qute.fmt("Hello {name} {surname ?: 'Default'}!", Map.of("name", "Martin")); // => Hello Martin Default! Qute.fmt("<html>{header}</html>").contentType("text/html").data("header", "<h1>Header</h1>").render(); // <html><h1>Header</h1></html> // Note that for a "text/html" template the special chars are replaced with html entities by default.- See Also:
fmt(String),fmt(String, Map),fmt(String, Object...)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQute.FmtThis construct is not thread-safe.static classQute.IndexedArgumentsParserHook
-
Constructor Summary
Constructors Constructor Description Qute()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclearCache()Clears the template cache.static voiddisableCache()The template cache will not be used by default.static voidenableCache()The template cache will be used by default.static Engineengine()If needed, a default engine is created lazily.static Qute.Fmtfmt(String template)static Stringfmt(String template, Object... data)The data array is accessibe via thedatakey, e.g.static Stringfmt(String template, Map<String,Object> data)static voidsetEngine(Engine engine)Set a specific engine instance.
-
-
-
Method Detail
-
engine
public static Engine engine()
If needed, a default engine is created lazily.The default engine has in addition to
EngineBuilder.addDefaults():ReflectionValueResolverQute.IndexedArgumentsParserHookHtmlEscaperregistered fortext/htmlandtext/xmlcontent types
- Returns:
- the engine
- See Also:
setEngine(Engine)
-
setEngine
public static void setEngine(Engine engine)
Set a specific engine instance.Note that the engine should have a
Qute.IndexedArgumentsParserHookregistered so that thefmt(String, Object...)method works correcly.The cache is always cleared when a new engine is set.
- Parameters:
engine-- See Also:
engine()
-
fmt
public static String fmt(String template, Map<String,Object> data)
- Parameters:
template-data-- Returns:
- the rendered template
-
fmt
public static String fmt(String template, Object... data)
The data array is accessibe via thedatakey, e.g. {data[0]} is resolved to the first argument.An empty expression
{}is a placeholder that is replaced with an index-based array accessor{data[n]}wherenis the index of the placeholder. The first placeholder is replace with{data[0]}, the second with{data[1]}, and so on. For example,"Hello {}!"becomesHello {data[0]}!.- Parameters:
template-data-- Returns:
- the rendered template
-
fmt
public static Qute.Fmt fmt(String template)
- Parameters:
template-- Returns:
- a new format object
-
enableCache
public static void enableCache()
The template cache will be used by default.- See Also:
Qute.Fmt.cache(),clearCache()
-
disableCache
public static void disableCache()
The template cache will not be used by default.- See Also:
Qute.Fmt.noCache(),clearCache()
-
clearCache
public static void clearCache()
Clears the template cache.
-
-