-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add link support to QuteWebTemplateBuildItem
- Loading branch information
Showing
9 changed files
with
190 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
deployment/src/main/java/io/quarkiverse/qute/web/deployment/QuteWebTemplateBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkiverse.qute.web.deployment; | ||
|
||
import static io.quarkiverse.qute.web.runtime.PathUtils.removeLeadingSlash; | ||
import static io.quarkiverse.qute.web.runtime.PathUtils.removeTrailingSlash; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class QuteWebTemplateBuildItem extends MultiBuildItem { | ||
|
||
/** | ||
* templateId is used as path if link is null | ||
*/ | ||
private final String templateId; | ||
|
||
/** | ||
* The link to use for this template | ||
*/ | ||
private final String link; | ||
|
||
public QuteWebTemplateBuildItem(String templateId, String link) { | ||
this.templateId = templateId; | ||
this.link = normalizeLink(link); | ||
} | ||
|
||
public String templateId() { | ||
return templateId; | ||
} | ||
|
||
public String link() { | ||
return link; | ||
} | ||
|
||
private static String normalizeLink(String link) { | ||
if (link == null) { | ||
return null; | ||
} | ||
return removeTrailingSlash(removeLeadingSlash(link)); | ||
} | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
...oyment/src/main/java/io/quarkiverse/qute/web/deployment/QuteWebTemplatePathBuildItem.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
deployment/src/test/java/io/quarkiverse/qute/web/test/LinkedTemplateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkiverse.qute.web.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.qute.web.deployment.QuteWebTemplateBuildItem; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.builder.BuildStepBuilder; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LinkedTemplateTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot(root -> { | ||
root.addAsResource(new StringAsset( | ||
"Hello {name ?: 'world'}!"), | ||
"templates/pub/hello.txt"); | ||
}).addBuildChainCustomizer(buildChainBuilder -> { | ||
final BuildStepBuilder stepBuilder = buildChainBuilder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new QuteWebTemplateBuildItem("pub/hello", "/foo/bar")); | ||
context.produce(new QuteWebTemplateBuildItem("pub/hello", "/")); | ||
} | ||
}); | ||
stepBuilder.produces(QuteWebTemplateBuildItem.class).build(); | ||
}); | ||
|
||
@Test | ||
public void testFixedLink() { | ||
given() | ||
.when().get("/hello") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("Hello world!")); | ||
given() | ||
.when().get("/foo/bar") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("Hello world!")); | ||
given() | ||
.when().get("/") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("Hello world!")); | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
runtime/src/main/java/io/quarkiverse/qute/web/runtime/PathUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkiverse.qute.web.runtime; | ||
|
||
public final class PathUtils { | ||
|
||
public static String toUnixPath(String path) { | ||
return path.replaceAll("\\\\", "/"); | ||
} | ||
|
||
public static String prefixWithSlash(String path) { | ||
return path.startsWith("/") ? path : "/" + path; | ||
} | ||
|
||
public static String surroundWithSlashes(String path) { | ||
return prefixWithSlash(addTrailingSlash(path)); | ||
} | ||
|
||
public static String addTrailingSlash(String path) { | ||
return path.endsWith("/") ? path : path + "/"; | ||
} | ||
|
||
public static String join(String path1, String path2) { | ||
return addTrailingSlash(path1) + removeLeadingSlash(path2); | ||
} | ||
|
||
public static String removeLeadingSlash(String path) { | ||
return path.startsWith("/") ? path.substring(1) : path; | ||
} | ||
|
||
public static String removeTrailingSlash(String path) { | ||
return path.endsWith("/") ? path.substring(0, path.length() - 1) : path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.