Skip to content

Commit

Permalink
Merge pull request #30060 from mkouba/qute-string-plus-operator
Browse files Browse the repository at this point in the history
Qute - built-in template extension for String plus operator
  • Loading branch information
mkouba authored Dec 27, 2022
2 parents 2f92298 + c33dffa commit bd66b86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/src/main/asciidoc/qute-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit bd66b86

Please sign in to comment.