Package io.quarkus.qute
Class Qute
java.lang.Object
io.quarkus.qute.Qute
Provides quick and convenient access to the engine instance stored in a static variable. If a specific engine instance is not
set via the
setEngine(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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
This construct is not thread-safe.static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the template cache.static void
The template cache will not be used by default.static void
The template cache will be used by default.static Engine
engine()
If needed, a default engine is created lazily.static Qute.Fmt
static String
The data array is accessibe via thedata
key, e.g.static String
static void
Set a specific engine instance.
-
Constructor Details
-
Qute
public Qute()
-
-
Method Details
-
engine
If needed, a default engine is created lazily.The default engine has in addition to
EngineBuilder.addDefaults()
:ReflectionValueResolver
Qute.IndexedArgumentsParserHook
HtmlEscaper
registered fortext/html
andtext/xml
content types
- Returns:
- the engine
- See Also:
-
setEngine
Set a specific engine instance.Note that the engine should have a
Qute.IndexedArgumentsParserHook
registered so that thefmt(String, Object...)
method works correcly.The cache is always cleared when a new engine is set.
- Parameters:
engine
-- See Also:
-
fmt
- Parameters:
template
-data
-- Returns:
- the rendered template
-
fmt
The data array is accessibe via thedata
key, 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]}
wheren
is 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
- Parameters:
template
-- Returns:
- a new format object
-
enableCache
public static void enableCache()The template cache will be used by default.- See Also:
-
disableCache
public static void disableCache()The template cache will not be used by default.- See Also:
-
clearCache
public static void clearCache()Clears the template cache.
-