From c33dffa6482d4c54757f90273cacd678ce710b65 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Fri, 23 Dec 2022 16:33:52 +0100 Subject: [PATCH] Qute - built-in template extension for String plus operator --- docs/src/main/asciidoc/qute-reference.adoc | 3 +++ .../deployment/extensions/StringTemplateExtensionsTest.java | 4 ++++ .../qute/runtime/extensions/StringTemplateExtensions.java | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/docs/src/main/asciidoc/qute-reference.adoc b/docs/src/main/asciidoc/qute-reference.adoc index 91bd23616f34d..0109d8088aa3a 100644 --- a/docs/src/main/asciidoc/qute-reference.adoc +++ b/docs/src/main/asciidoc/qute-reference.adoc @@ -1987,6 +1987,9 @@ TIP: A list element can be accessed directly via an index: `{list.10}` or even ` * `str:fmt` or `str:format`: Formats the supplied string value via `java.lang.String.format()` ** `{str:format("Hello %s!",name)}` ** `{str:fmt(locale,'%tA',now)}` +* `+`: Concatenation +** `{item.name + '_' + mySuffix}` +** `{name + 10}` ===== Config diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/extensions/StringTemplateExtensionsTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/extensions/StringTemplateExtensionsTest.java index 26d27f283427a..9833dba9eff2b 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/extensions/StringTemplateExtensionsTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/extensions/StringTemplateExtensionsTest.java @@ -42,6 +42,10 @@ public void testTemplateExtensions() { engine.parse("{str:fmt(locale,'%tA',now)}") .data("now", LocalDateTime.of(2016, 7, 26, 12, 0), "locale", Locale.GERMAN) .render()); + assertEquals("barbar1", + engine.parse("{foo + 'bar' + 1}") + .data("foo", "bar") + .render()); } } diff --git a/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/extensions/StringTemplateExtensions.java b/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/extensions/StringTemplateExtensions.java index 6f15b8eed830c..01c4f305d8f26 100644 --- a/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/extensions/StringTemplateExtensions.java +++ b/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/extensions/StringTemplateExtensions.java @@ -67,4 +67,9 @@ static String fmt(String ignoredPropertyName, Locale locale, String format, Obje return String.format(locale, format, args); } + @TemplateExtension(matchName = "+") + static String plus(String str, Object val) { + return str + val; + } + }