Skip to content

Commit

Permalink
Add quarkus-qute-web-asciidoctor extension.
Browse files Browse the repository at this point in the history
Leverage asciidoctoj and asciidoctorj-diagram libraries to render asciidoc content.
  • Loading branch information
jtama committed Nov 14, 2024
1 parent 1329535 commit 62847fa
Show file tree
Hide file tree
Showing 37 changed files with 823 additions and 549 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties

# Asciidoctor
.asciidoctor
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import java.util.ArrayList;
import java.util.List;

import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocConverter;
import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocRendererFactory;
import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocSectionHelperFactory;
import io.quarkiverse.qute.web.asciidoc.runtime.kroki.KrokiClient;
import io.quarkiverse.qute.web.asciidoc.runtime.kroki.ObjectMapperConfig;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
Expand All @@ -25,19 +20,9 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void addToIndex(BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClassesBuildItemBuildProducer) {
additionalIndexedClassesBuildItemBuildProducer
.produce(new AdditionalIndexedClassesBuildItem(KrokiClient.class.getName()));
}

@BuildStep
void process(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(new AdditionalBeanBuildItem(
AsciidocSectionHelperFactory.class,
AsciidocRendererFactory.class,
AsciidocConverter.class,
ObjectMapperConfig.class));
additionalBeans.produce(new AdditionalBeanBuildItem(AsciidocSectionHelperFactory.class));
}

@BuildStep
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@

import java.util.List;

import jakarta.inject.Inject;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkiverse.qute.web.asciidoc.runtime.AsciidocSectionHelperFactory;
import io.quarkus.qute.Engine;
import io.quarkus.test.QuarkusUnitTest;

public class QuarkusAsciidocTest {

@RegisterExtension
static final QuarkusUnitTest quarkusApp = new QuarkusUnitTest();

@Inject
Engine engine;

@Test
public void shouldConvertUsingAsciiTag() {
Engine engine = Engine.builder().addDefaults()
.addSectionHelper(new AsciidocSectionHelperFactory()).build();

String result = engine.parse("{#ascii}...{/ascii}").render();

Expand All @@ -35,6 +28,8 @@ public void shouldConvertUsingAsciiTag() {

@Test
public void shouldConvertUsingAsciidocTag() {
Engine engine = Engine.builder().addDefaults()
.addSectionHelper(new AsciidocSectionHelperFactory()).build();

String result = engine.parse("{#asciidoc}...{/asciidoc}").render();

Expand All @@ -47,6 +42,8 @@ public void shouldConvertUsingAsciidocTag() {

@Test
public void testH1() {
Engine engine = Engine.builder().addDefaults()
.addSectionHelper(new AsciidocSectionHelperFactory()).build();

String result = engine.parse("{#ascii}= Quarkus and Roq{/ascii}").render();

Expand All @@ -56,6 +53,9 @@ public void testH1() {
@Test
void shouldConvertWithForTagInsideAsciiTag() {

Engine engine = Engine.builder().addDefaults()
.addSectionHelper(new AsciidocSectionHelperFactory()).build();

String result = engine.parse("""
<h1>Quarkus and Qute</h1>
{#ascii}
Expand All @@ -75,30 +75,4 @@ void shouldConvertWithForTagInsideAsciiTag() {
softly.assertThat(result).contains("<li>");
});
}

@Test
void shouldNotPrerenderDiagram() {

String result = engine.parse("""
<h1>Quarkus and Qute</h1>
{#ascii}
== Qute and Diagram
Here is a list:
[plantuml, format=svg]
----
@startuml
@enduml
----
{/ascii}
""")
.render();

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(result).contains("<h1>Quarkus and Qute</h1>");
softly.assertThat(result).contains("<h2>Qute and Diagram</h2>");
softly.assertThat(result).contains("@startuml");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void testTemplates() {
.body("html.body.p[0]", equalTo("Hello world!"))
.body("html.body.div.div.div.ul.li[0].p", equalToCompressingWhiteSpace("Joe"))
.body("html.body.div.h2", equalTo("Installation"))
.body("html.body.div.div.div.div.pre.code.@class", equalTo("language-xml hljs"))
.body("html.body.div.div.div.div.pre.code[0].@class", equalTo("language-xml hljs"))
.body(containsString(" &lt;groupId&gt;io.quarkiverse.qute.web&lt;/groupId&gt;"));

}
Expand Down
2 changes: 1 addition & 1 deletion asciidoc/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-qute-web-asciidoc</artifactId>
<name>Quarkus Qute - Asciidoc - Runtime</name>
<name>Quarkus Qute Web - Asciidoc - Runtime</name>

<dependencies>
<dependency>
Expand Down
Loading

0 comments on commit 62847fa

Please sign in to comment.