Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow qute.html extension for templates #71

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"));
}
}
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ private Variant trySelectVariant(RoutingContext rc, TemplateInstance instance, L
* <li>{@code /nested/item.html?foo=bar} => {@code web/nested/item}</li>
* </ul>
*
* 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
*/
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("/")) {
Expand Down