diff --git a/docs/src/main/asciidoc/qute-reference.adoc b/docs/src/main/asciidoc/qute-reference.adoc index a71f33d0509ff..e7612b3dcfc48 100644 --- a/docs/src/main/asciidoc/qute-reference.adoc +++ b/docs/src/main/asciidoc/qute-reference.adoc @@ -567,7 +567,7 @@ A section helper that defines the logic of a section can "execute" any of the bl [[loop_section]] ==== Loop Section -The loop section makes it possible to iterate over an instance of `Iterable`, `Iterator`, array, `Map` 's entry set, `Stream` and an `Integer`. +The loop section makes it possible to iterate over an instance of `Iterable`, `Iterator`, array, `Map` (element is a `Map.Entry`), `Stream`, `Integer` and `int` (primitive value). It has two flavors. The first one is using the `each` name and `it` is an implicit alias for the iteration element. diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java index 91f850b3ec27a..9405bd75e246e 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java @@ -1647,7 +1647,9 @@ private static Expression findExpression(String helperHint, String hintPrefix, T static void processLoopElementHint(Match match, IndexView index, Expression expression, BuildProducer incorrectExpressions) { - if (match.isEmpty() || match.type().name().equals(DotNames.INTEGER)) { + if (match.isEmpty() + || match.type().name().equals(DotNames.INTEGER) + || match.type().equals(PrimitiveType.INT)) { return; } Type matchType = null; diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/loop/LoopTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/loop/LoopTest.java index 726ba98f226dd..ca3ffa7eefe2c 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/loop/LoopTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/loop/LoopTest.java @@ -8,15 +8,27 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.quarkus.qute.CheckedTemplate; import io.quarkus.qute.Template; +import io.quarkus.qute.TemplateInstance; import io.quarkus.test.QuarkusUnitTest; public class LoopTest { + static StringAsset template = new StringAsset("{#for i in total}{i}:{/for}"); + @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addAsResource(new StringAsset("{#for i in total}{i}:{/for}"), "templates/loop1.html")); + .withApplicationRoot(root -> root + .addAsResource(template, "templates/loop1.html") + .addAsResource(template, "templates/LoopTest/loopInt.html")); + + @CheckedTemplate + static class Templates { + + static native TemplateInstance loopInt(int total); + + } @Inject Template loop1; @@ -24,6 +36,7 @@ public class LoopTest { @Test public void testIntegerIsIterable() { assertEquals("1:2:3:", loop1.data("total", 3).render()); + assertEquals("1:2:3:", Templates.loopInt(3).render()); } }