forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute: extend the
@EngineConfiguration
support to ParserHook
Co-authored-by: George Gastaldi <[email protected]>
- Loading branch information
Showing
14 changed files
with
192 additions
and
41 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
71 changes: 71 additions & 0 deletions
71
...io/quarkus/qute/deployment/engineconfigurations/parserhook/CustomParserHookBuildTest.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,71 @@ | ||
package io.quarkus.qute.deployment.engineconfigurations.parserhook; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.EngineConfiguration; | ||
import io.quarkus.qute.ParserHelper; | ||
import io.quarkus.qute.ParserHook; | ||
import io.quarkus.qute.TemplateException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CustomParserHookBuildTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
root -> root.addClasses(CustomParserHook.class, Foo.class) | ||
.addAsResource(new StringAsset("{foo.bar}"), "templates/foo.html")) | ||
.assertException(t -> { | ||
Throwable e = t; | ||
TemplateException te = null; | ||
while (e != null) { | ||
if (e instanceof TemplateException) { | ||
te = (TemplateException) e; | ||
break; | ||
} | ||
e = e.getCause(); | ||
} | ||
assertNotNull(te); | ||
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage()); | ||
assertTrue(te.getMessage().contains("{foo.bar}"), te.getMessage()); | ||
});; | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
@EngineConfiguration | ||
public static class CustomParserHook implements ParserHook { | ||
|
||
@Override | ||
public void beforeParsing(ParserHelper helper) { | ||
if (helper.getTemplateId().contains("foo")) { | ||
helper.addParameter("foo", Foo.class.getName()); | ||
} | ||
} | ||
|
||
} | ||
|
||
public static class Foo { | ||
|
||
// package-private method is ignored | ||
String bar() { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
.../quarkus/qute/deployment/engineconfigurations/parserhook/CustomParserHookRuntimeTest.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,48 @@ | ||
package io.quarkus.qute.deployment.engineconfigurations.parserhook; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.EngineConfiguration; | ||
import io.quarkus.qute.ParserHelper; | ||
import io.quarkus.qute.ParserHook; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CustomParserHookRuntimeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
root -> root.addClasses(CustomParserHook.class) | ||
.addAsResource(new StringAsset("{foo}"), "templates/foo.html")); | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testParserHook() { | ||
assertEquals("42", engine.getTemplate("foo").data("bar", 42).render()); | ||
} | ||
|
||
@EngineConfiguration | ||
public static class CustomParserHook implements ParserHook { | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Override | ||
public void beforeParsing(ParserHelper helper) { | ||
if (helper.getTemplateId().contains("foo") && engine != null) { | ||
helper.addContentFilter(c -> "{bar}"); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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
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
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