-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute checked templates - require type-safe expressions by default
- related to #14534
- Loading branch information
Showing
8 changed files
with
226 additions
and
44 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
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
29 changes: 29 additions & 0 deletions
29
.../qute/deployment/src/main/java/io/quarkus/qute/deployment/TemplateFilePathsBuildItem.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,29 @@ | ||
package io.quarkus.qute.deployment; | ||
|
||
import java.util.Set; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
import io.quarkus.qute.runtime.QuteConfig; | ||
|
||
/** | ||
* Holds all template file paths, including the versions without suffixes configured via {@link QuteConfig#suffixes}. | ||
* <p> | ||
* For example, for the template {@code items.html} the set will contain {@code items.html} and {@code items}. | ||
*/ | ||
public final class TemplateFilePathsBuildItem extends SimpleBuildItem { | ||
|
||
private final Set<String> filePaths; | ||
|
||
public TemplateFilePathsBuildItem(Set<String> filePaths) { | ||
this.filePaths = filePaths; | ||
} | ||
|
||
public Set<String> getFilePaths() { | ||
return filePaths; | ||
} | ||
|
||
public boolean contains(String path) { | ||
return filePaths.contains(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
36 changes: 36 additions & 0 deletions
36
...est/java/io/quarkus/qute/deployment/typesafe/CheckedTemplateDoNotRequireTypeSafeTest.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,36 @@ | ||
package io.quarkus.qute.deployment.typesafe; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.CheckedTemplate; | ||
import io.quarkus.qute.TemplateInstance; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CheckedTemplateDoNotRequireTypeSafeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Templates.class) | ||
.addAsResource(new StringAsset("Hello {name}!{any}"), | ||
"templates/CheckedTemplateDoNotRequireTypeSafeTest/hola.txt")); | ||
|
||
@Test | ||
public void testValidation() { | ||
assertEquals("Hello Ondrej!!", Templates.hola("Ondrej").data("any", "!").render()); | ||
} | ||
|
||
@CheckedTemplate(requireTypeSafeExpressions = false) | ||
static class Templates { | ||
|
||
static native TemplateInstance hola(String name); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.