-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
417 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.quarkiverse.qute.web</groupId> | ||
<artifactId>quarkus-qute-web-asciidoc-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-qute-web-asciidoc-deployment</artifactId> | ||
<name>Quarkus Qute Web - Asciidoc - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkiverse.qute.web</groupId> | ||
<artifactId>quarkus-qute-web-asciidoc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-qute-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
...t/src/main/java/io/quarkiverse/qute/web/asciidoc/deployment/QuteWebAsciidocProcessor.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,22 @@ | ||
package io.quarkiverse.qute.web.asciidoc.deployment; | ||
|
||
import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocSectionHelperFactory; | ||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
|
||
class QuteWebAsciidocProcessor { | ||
|
||
private static final String FEATURE = "qute-web-asciidoc"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
void process(BuildProducer<AdditionalBeanBuildItem> additionalBeans) { | ||
additionalBeans.produce(new AdditionalBeanBuildItem(AsciidocSectionHelperFactory.class)); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...c/deployment/src/test/java/io/quarkiverse/qute/web/asciidoc/test/QuarkusAsciidocTest.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,78 @@ | ||
package io.quarkiverse.qute.web.asciidoc.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocSectionHelperFactory; | ||
import io.quarkus.qute.Engine; | ||
|
||
public class QuarkusAsciidocTest { | ||
|
||
@Test | ||
public void shouldConvertUsingAsciiTag() { | ||
Engine engine = Engine.builder().addDefaults() | ||
.addSectionHelper(new AsciidocSectionHelperFactory()).build(); | ||
|
||
String result = engine.parse("{#ascii}...{/ascii}").render(); | ||
|
||
assertThat(result).contains(""" | ||
<p> | ||
... | ||
</p> | ||
"""); | ||
} | ||
|
||
@Test | ||
public void shouldConvertUsingAsciidocTag() { | ||
Engine engine = Engine.builder().addDefaults() | ||
.addSectionHelper(new AsciidocSectionHelperFactory()).build(); | ||
|
||
String result = engine.parse("{#asciidoc}...{/asciidoc}").render(); | ||
|
||
assertThat(result).contains(""" | ||
<p> | ||
... | ||
</p> | ||
"""); | ||
} | ||
|
||
@Test | ||
public void testH1() { | ||
Engine engine = Engine.builder().addDefaults() | ||
.addSectionHelper(new AsciidocSectionHelperFactory()).build(); | ||
|
||
String result = engine.parse("{#ascii}= Quarkus and Roq{/ascii}").render(); | ||
|
||
assertThat(result).contains("<h1>Quarkus and Roq</h1>"); | ||
} | ||
|
||
@Test | ||
void shouldConvertWithForTagInsideAsciiTag() { | ||
|
||
Engine engine = Engine.builder().addDefaults() | ||
.addSectionHelper(new AsciidocSectionHelperFactory()).build(); | ||
|
||
String result = engine.parse(""" | ||
<h1>Quarkus and Qute</h1> | ||
{#ascii} | ||
== Qute and Roq | ||
Here is a list: | ||
{#for item in items} | ||
* an {item} as a list item | ||
{/for} | ||
{/ascii} | ||
""").data("items", List.of("apple", "banana", "cherry")) | ||
.render(); | ||
|
||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(result).contains("<h1>Quarkus and Qute</h1>"); | ||
softly.assertThat(result).contains("<h2>Qute and Roq</h2>"); | ||
softly.assertThat(result).contains("<ul>"); | ||
softly.assertThat(result).contains("<li>"); | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...nt/src/test/java/io/quarkiverse/qute/web/asciidoc/test/QuteAsciidocSectionHelperTest.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,38 @@ | ||
package io.quarkiverse.qute.web.asciidoc.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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.Template; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class QuteAsciidocSectionHelperTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest quarkusApp = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
app -> app.addAsResource(new StringAsset( | ||
"{#ascii}= Qute and Roq{/ascii}"), | ||
"templates/foo.txt")); | ||
|
||
@Inject | ||
Template foo; | ||
|
||
@Test | ||
void shouldConvertUsingAsciiTag() { | ||
String result = foo.render(); | ||
|
||
assertThat(result).contains(""" | ||
<div class="sect0" id="_qute_and_roq"> | ||
<h1>Qute and Roq</h1> | ||
<div class="sectionbody"> | ||
</div> | ||
</div> | ||
""", result); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...t/java/io/quarkiverse/qute/web/asciidoc/test/QuteAsciidocSectionWithInnerSectionTest.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,72 @@ | ||
package io.quarkiverse.qute.web.asciidoc.test; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.util.List; | ||
|
||
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.Template; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class QuteAsciidocSectionWithInnerSectionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest quarkusApp = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
app -> app.addAsResource(new StringAsset( | ||
""" | ||
<h1>Quarkus and Qute</h1> | ||
{#asciidoc} | ||
== Qute and Roq | ||
Here is a list: | ||
{#for item in items} | ||
* an {item} as a list item | ||
{/for} | ||
{/asciidoc} | ||
"""), | ||
"templates/foo.txt")); | ||
|
||
@Inject | ||
Template foo; | ||
|
||
@Test | ||
void shouldConvertWithInnerSection() { | ||
String result = foo.data("items", List.of("apple", "banana", "cherry")) | ||
.render(); | ||
|
||
assertThat(result).contains(""" | ||
<h1>Quarkus and Qute</h1> | ||
<div class="sect1" id="_qute_and_roq"> | ||
<h2>Qute and Roq</h2> | ||
<div class="sectionbody"> | ||
<div class="paragraph"> | ||
Here is a list: <div class="ulist"> | ||
<ul> | ||
<li> | ||
<p> | ||
an apple as a list item | ||
</p> | ||
</li> | ||
<li> | ||
<p> | ||
an banana as a list item | ||
</p> | ||
</li> | ||
<li> | ||
<p> | ||
an cherry as a list item | ||
</p> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
""", result); | ||
} | ||
} |
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.quarkiverse.qute.web</groupId> | ||
<artifactId>quarkus-qute-web-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>quarkus-qute-web-asciidoc-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<name>Quarkus Qute Web - Asciidoc - Parent</name> | ||
|
||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
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,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.quarkiverse.qute.web</groupId> | ||
<artifactId>quarkus-qute-web-asciidoc-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-qute-web-asciidoc</artifactId> | ||
<name>Quarkus Qute - Asciidoc - Runtime</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-qute</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.yupiik.maven</groupId> | ||
<artifactId>asciidoc-java</artifactId> | ||
<version>${asciidoc.java.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-maven-plugin</artifactId> | ||
<version>${quarkus.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>extension-descriptor</goal> | ||
</goals> | ||
<configuration> | ||
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
...doc/runtime/src/main/java/io/quarkiverse/qute/web/asciidoc/runtime/AsciidocConverter.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,21 @@ | ||
package io.quarkiverse.qute.web.asciidoc.runtime; | ||
|
||
import java.util.Map; | ||
|
||
import io.yupiik.asciidoc.model.Body; | ||
import io.yupiik.asciidoc.parser.Parser; | ||
import io.yupiik.asciidoc.renderer.html.AsciidoctorLikeHtmlRenderer; | ||
|
||
public class AsciidocConverter { | ||
|
||
private final Parser parser = new Parser(); | ||
private final AsciidoctorLikeHtmlRenderer renderer = new AsciidoctorLikeHtmlRenderer( | ||
new AsciidoctorLikeHtmlRenderer.Configuration() | ||
.setAttributes(Map.of("noheader", "true"))); | ||
|
||
public String apply(String asciidoc) { | ||
Body body = parser.parseBody(asciidoc, new Parser.ParserContext(null)); | ||
renderer.visitBody(body); | ||
return renderer.result(); | ||
} | ||
} |
Oops, something went wrong.