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

Change the default published directory from "web" to "pub" #56

Merged
merged 1 commit into from
Nov 14, 2023
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 @@ -43,19 +43,19 @@ AdditionalBeanBuildItem beans() {
@BuildStep
public void collectTemplatePaths(TemplateFilePathsBuildItem templateFilePaths,
QuteWebBuildTimeConfig config, BuildProducer<QuteWebTemplatePathBuildItem> paths) {
String webTemplatesPathPrefix = "";
String webTemplatesDir = config.webTemplatesDir();
if (!webTemplatesDir.equals("/") && !webTemplatesDir.isBlank()) {
webTemplatesPathPrefix = webTemplatesDir + "/";
String publicPathPrefix = "";
String publicDir = config.publicDir();
if (!publicDir.equals("/") && !publicDir.isBlank()) {
publicPathPrefix = publicDir + "/";
}
Optional<Pattern> hiddenTemplates = config.hiddenTemplates();
for (String path : templateFilePaths.getFilePaths()) {
if (!path.startsWith(webTemplatesPathPrefix)) {
if (!path.startsWith(publicPathPrefix)) {
continue;
}
if (hiddenTemplates.isPresent()
// Match the path relative to the webTemplatesPath
&& hiddenTemplates.get().matcher(path.substring(webTemplatesPathPrefix.length())).matches()) {
// Match the path relative to the publicPath
&& hiddenTemplates.get().matcher(path.substring(publicPathPrefix.length())).matches()) {
LOG.debugf("Template %s is hidden", path);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BlockingHandlerTest {
root
.addAsResource(new StringAsset(
"blocking={cdi:bean.isOnWorkerThread}"),
"templates/web/blocking.txt")
"templates/pub/blocking.txt")
.addAsResource(new StringAsset(
"quarkus.qute.web.use-blocking-handler=true"),
"application.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class CompressionDisabledTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot(root -> root
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/web/file.txt")
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/web/document.foo"))
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/pub/file.txt")
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/pub/document.foo"))
.overrideConfigKey("quarkus.http.enable-compression", "false")
.overrideConfigKey("quarkus.qute.suffixes", "txt,foo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class CompressionEnabledTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot(root -> root
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/web/file.txt")
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/web/document.foo"))
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/pub/file.txt")
.addAsResource(new StringAsset("{cdi:vertxRequest.getParam('id')}"), "templates/pub/document.foo"))
.overrideConfigKey("quarkus.http.enable-compression", "true")
.overrideConfigKey("quarkus.qute.suffixes", "txt,foo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

import io.quarkus.test.QuarkusUnitTest;

public class CustomWebTemplatesDirectoryTest {
public class CustomPublicDirectoryTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"Hello {name ?: 'world'}!"),
"templates/web/hello.txt")
"templates/pub/hello.txt")
.addAsResource(new StringAsset(
"Bar {name ?: 'world'}!"),
"templates/ping/pong/bar.txt")
.addAsResource(new StringAsset(
"quarkus.qute.web.web-templates-dir=ping/pong"),
"quarkus.qute.web.public-dir=ping/pong"),
"application.properties");
});

@Test
public void testCustomWebTemplatesDir() {
public void testCustomPublicDir() {
given()
.when().get("/hello")
.then()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class CustomRootPathTest {
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"Hello {name ?: 'world'}!"),
"templates/web/hello.txt")
"templates/pub/hello.txt")
.addAsResource(new StringAsset(
"Index root!"),
"templates/web/index.html")
"templates/pub/index.html")
.addAsResource(new StringAsset(
"Index foo!"),
"templates/web/foo/index.html")
"templates/pub/foo/index.html")
.addAsResource(new StringAsset(
"quarkus.qute.web.root-path=ping"),
"application.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class CustomRouteOrderTest {
root
.addAsResource(new StringAsset(
"BAZ!"),
"templates/web/baz.txt")
"templates/pub/baz.txt")
.addAsResource(new StringAsset(
"BAR!"),
"templates/web/bar.txt")
"templates/pub/bar.txt")
.addAsResource(new StringAsset(
"PING!"),
"templates/web/ping.txt")
"templates/pub/ping.txt")
.addAsResource(new StringAsset(
"STATIC PING!"),
"META-INF/resources/ping.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class DefaultRootPathTest {
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"Hello {name ?: 'world'}!"),
"templates/web/hello.txt")
"templates/pub/hello.txt")
.addAsResource(new StringAsset(
"Index root!"),
"templates/web/index.html")
"templates/pub/index.html")
.addAsResource(new StringAsset(
"Index foo!"),
"templates/web/foo/index.html");
"templates/pub/foo/index.html");
});

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DefaultRouteOrderTest {
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"BAZ!"),
"templates/web/baz.txt")
"templates/pub/baz.txt")
// Static resource is hidden by the template
.addAsResource(new StringAsset(
"STATIC BAZ!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FailureTest {
root.addClass(ErrorHandler.class)
.addAsResource(new StringAsset(
"Hello {name}!"),
"templates/web/hello.txt");
"templates/pub/hello.txt");
});

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class HiddenTemplatesTest {
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"Hello {name ?: 'world'}!"),
"templates/web/hello.txt")
"templates/pub/hello.txt")
.addAsResource(new StringAsset(
"Bar {name ?: 'world'}!"),
"templates/web/foo/bar.txt")
"templates/pub/foo/bar.txt")
.addAsResource(new StringAsset(
"Baz {name ?: 'world'}!"),
"templates/web/foo/baz/baz.txt")
"templates/pub/foo/baz/baz.txt")
.addAsResource(new StringAsset(
"quarkus.qute.web.hidden-templates=hello.*|foo/baz/.*"),
"application.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class HttpNamespaceTest {
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset(
"{http:request.path} Hello {http:param('name','foo')}! {http:param('age')}"),
"templates/web/hello.txt")
"templates/pub/hello.txt")
.addAsResource(new StringAsset(
"HX-Request={http:header('HX-Request')}::{http:headers.hx-request}"),
"templates/web/headers.txt");
"templates/pub/headers.txt");
});

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class NonblockingHandlerTest {
root
.addAsResource(new StringAsset(
"blocking={cdi:bean.isOnWorkerThread}"),
"templates/web/nonblocking.txt")
"templates/pub/nonblocking.txt")
.addAsResource(new StringAsset(
"quarkus.qute.web.use-blocking-handler=false"),
"application.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SimpleTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> {
root.addAsResource(new StringAsset("{#hello /} {name ?: 'world'}!"), "templates/web/hello.txt")
root.addAsResource(new StringAsset("{#hello /} {name ?: 'world'}!"), "templates/pub/hello.txt")
.addAsResource(new StringAsset("Hello"), "templates/tags/hello.txt");
});

Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

include::./includes/attributes.adoc[]

The goal of this extension is to expose https://quarkus.io/guides/qute-reference[Qute] templates located in the `src/main/resource/templates/web` directory via HTTP.
The goal of this extension is to expose https://quarkus.io/guides/qute-reference[Qute] templates located in the `src/main/resource/templates/pub` directory via HTTP.
Automatically, no controllers needed.
For example, the template `src/main/resource/templates/web/foo.html` will be served from the paths `/foo` and `/foo.html` by default.
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/web/index.html` will be served from the paths `/index`, `/index.html` and `/` 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.

== Installation

Expand Down Expand Up @@ -49,7 +49,7 @@ For example, if there is a template `foo.html` that defines a https://quarkus.io
== Content Negotiation

This extension attempts to serve the appropriate template and set the HTTP `Content-type` header based on the selected template variant and the value of `Accept` header.
For example, if there are templates `src/main/resource/templates/web/foo.html` and `src/main/resource/templates/web/foo.txt` and the client sends the `Accept: text/html, text/plain;q=0.9` header then `foo.html` is rendeder and the `Content-type: text/html` header is set.
For example, if there are templates `src/main/resource/templates/pub/foo.html` and `src/main/resource/templates/pub/foo.txt` and the client sends the `Accept: text/html, text/plain;q=0.9` header then `foo.html` is rendeder and the `Content-type: text/html` header is set.

[[http_namespace]]
== `http:` Namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ public interface QuteWebBuildTimeConfig {
String rootPath();

/**
* The directory from which the templates are served. The path is relative to the `src/main/resource/templates` directory.
* For example, the value `ping` is translated to `src/main/resource/templates/ping`.
* The directory from which the templates are served. The path is relative to a template root directroy, i.e. relative to
* `src/main/resource/templates` by default. For example, the value `ping` could be translated to
* `src/main/resource/templates/ping`.
*
* By default, the templates located in the `src/main/resource/templates/web` directory are served.
* By default, the templates located in the `src/main/resource/templates/pub` directory are served.
*
* @asciidoclet
*/
@WithDefault("web")
String webTemplatesDir();
@WithDefault("pub")
String publicDir();

/**
* This regular expression is used to hide template files from the web templates path. Hidden templates are not exposed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public class QuteWebHandler implements Handler<RoutingContext> {
private final LazyValue<TemplateProducer> templateProducer;
private final QuteContext quteContext;

public QuteWebHandler(String rootPath, String webTemplatesPath, Set<String> templatePaths,
public QuteWebHandler(String rootPath, String publicDir, Set<String> templatePaths,
HttpBuildTimeConfig httpBuildTimeConfig) {
this.rootPath = rootPath;
if (webTemplatesPath.equals("/") || webTemplatesPath.isBlank()) {
if (publicDir.equals("/") || publicDir.isBlank()) {
this.webTemplatesPath = "";
} else {
this.webTemplatesPath = webTemplatesPath.startsWith("/") ? webTemplatesPath.substring(1) : webTemplatesPath;
this.webTemplatesPath = publicDir.startsWith("/") ? publicDir.substring(1) : publicDir;
}
this.templatePaths = templatePaths;
this.compressMediaTypes = httpBuildTimeConfig.enableCompression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public void accept(Route r) {
}

public Handler<RoutingContext> handler(String rootPath, Set<String> templatePaths) {
return new QuteWebHandler(rootPath, quteWebConfig.webTemplatesDir(), templatePaths, httpConfig);
return new QuteWebHandler(rootPath, quteWebConfig.publicDir(), templatePaths, httpConfig);
}
}