From 1d1a08c01c04ffd50edeadb59d8b3e182e0cbd77 Mon Sep 17 00:00:00 2001 From: Tomasz Kucharzyk Date: Thu, 4 Jan 2024 23:46:22 +0100 Subject: [PATCH] allow qute.html extension for templates --- .../qute/web/test/CustomRootPathTest.java | 39 ++++++++++++++++++- .../qute/web/test/DefaultRootPathTest.java | 38 +++++++++++++++++- docs/modules/ROOT/pages/index.adoc | 2 +- .../qute/web/runtime/QuteWebHandler.java | 4 +- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/deployment/src/test/java/io/quarkiverse/qute/web/test/CustomRootPathTest.java b/deployment/src/test/java/io/quarkiverse/qute/web/test/CustomRootPathTest.java index ccd5fb1b..d8887d0d 100644 --- a/deployment/src/test/java/io/quarkiverse/qute/web/test/CustomRootPathTest.java +++ b/deployment/src/test/java/io/quarkiverse/qute/web/test/CustomRootPathTest.java @@ -24,7 +24,13 @@ public class CustomRootPathTest { "templates/pub/foo/index.html") .addAsResource(new StringAsset( "quarkus.qute.web.root-path=ping"), - "application.properties"); + "application.properties") + .addAsResource(new StringAsset( + "Index bar!"), + "templates/pub/bar/index.qute.html") + .addAsResource(new StringAsset( + "Index bar sub!"), + "templates/pub/bar/sub.qute.html"); }); @Test @@ -49,6 +55,35 @@ public void testTemplates() { .then() .statusCode(200) .body(containsString("Index foo!")); - + given() + .when().get("/ping/foo/index.html") + .then() + .statusCode(200) + .body(containsString("Index foo!")); + given() + .when().get("/ping/bar/") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/ping/bar/index") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/ping/bar/index.qute.html") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/ping/bar/sub") + .then() + .statusCode(200) + .body(containsString("Index bar sub!")); + given() + .when().get("/ping/bar/sub.qute.html") + .then() + .statusCode(200) + .body(containsString("Index bar sub!")); } } diff --git a/deployment/src/test/java/io/quarkiverse/qute/web/test/DefaultRootPathTest.java b/deployment/src/test/java/io/quarkiverse/qute/web/test/DefaultRootPathTest.java index 268fdc3d..a4d1a600 100644 --- a/deployment/src/test/java/io/quarkiverse/qute/web/test/DefaultRootPathTest.java +++ b/deployment/src/test/java/io/quarkiverse/qute/web/test/DefaultRootPathTest.java @@ -21,7 +21,13 @@ public class DefaultRootPathTest { "templates/pub/index.html") .addAsResource(new StringAsset( "Index foo!"), - "templates/pub/foo/index.html"); + "templates/pub/foo/index.html") + .addAsResource(new StringAsset( + "Index bar!"), + "templates/pub/bar/index.qute.html") + .addAsResource(new StringAsset( + "Index bar sub!"), + "templates/pub/bar/sub.qute.html"); }); @Test @@ -46,5 +52,35 @@ public void testTemplates() { .then() .statusCode(200) .body(containsString("Index foo!")); + given() + .when().get("/foo/index.html") + .then() + .statusCode(200) + .body(containsString("Index foo!")); + given() + .when().get("/bar/") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/bar/index") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/bar/index.qute.html") + .then() + .statusCode(200) + .body(containsString("Index bar!")); + given() + .when().get("/bar/sub") + .then() + .statusCode(200) + .body(containsString("Index bar sub!")); + given() + .when().get("/bar/sub.qute.html") + .then() + .statusCode(200) + .body(containsString("Index bar sub!")); } } diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 7e3a43bf..4c77f9de 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -6,7 +6,7 @@ The goal of this extension is to expose https://quarkus.io/guides/qute-reference Automatically, no controllers needed. For example, the template `src/main/resource/templates/pub/foo.html` will be served from the paths `/foo` and `/foo.html` by default. -NOTE: The `index.html` pages are handled specifically, i.e. they are also served as a "default page" of the containing directory. For example, the template `src/main/resource/templates/pub/index.html` will be served from the paths `/index`, `/index.html` and `/` by default. +NOTE: The `index.html` and `index.qute.html` pages are handled specifically, i.e. they are also served as a "default page" of the containing directory. For example, the template `src/main/resource/templates/pub/index.html` will be served from the paths `/index`, `/index.html` and `/` by default. == Installation diff --git a/runtime/src/main/java/io/quarkiverse/qute/web/runtime/QuteWebHandler.java b/runtime/src/main/java/io/quarkiverse/qute/web/runtime/QuteWebHandler.java index a06ab92a..560267c2 100644 --- a/runtime/src/main/java/io/quarkiverse/qute/web/runtime/QuteWebHandler.java +++ b/runtime/src/main/java/io/quarkiverse/qute/web/runtime/QuteWebHandler.java @@ -225,7 +225,7 @@ private Variant trySelectVariant(RoutingContext rc, TemplateInstance instance, L *
  • {@code /nested/item.html?foo=bar} => {@code web/nested/item}
  • * * - * Note that a path that ends with {@code /} is handled specifically. The {@code index.html} is appended to the path. + * Note that a path that ends with {@code /} is handled specifically. The {@code index} is appended to the path. * * @param path * @return the template path without suffix @@ -233,7 +233,7 @@ private Variant trySelectVariant(RoutingContext rc, TemplateInstance instance, L private String extractTemplatePath(String path) { if (path.length() >= rootPath.length()) { if (path.endsWith("/")) { - path = path + "index.html"; + path = path + "index"; } path = path.substring(rootPath.length()); if (path.startsWith("/")) {