Skip to content

Commit ba4257d

Browse files
ante003pivovarit
authored andcommitted
Introduction to Ascii doctor (eugenp#2069)
* - added classes for asciidoctor article - added tests for that article - added exclusion in pom.xml in libraries * - fixed test * - fixed formating in pom
1 parent 7e315d8 commit ba4257d

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@
180180
<artifactId>serenity-core</artifactId>
181181
<version>${serenity.version}</version>
182182
<scope>test</scope>
183+
<exclusions>
184+
<exclusion>
185+
<groupId>org.asciidoctor</groupId>
186+
<artifactId>asciidoctor-java-integration</artifactId>
187+
</exclusion>
188+
</exclusions>
183189
</dependency>
184190
<dependency>
185191
<groupId>net.serenity-bdd</groupId>
@@ -323,6 +329,16 @@
323329
<artifactId>netty-all</artifactId>
324330
<version>${netty.version}</version>
325331
</dependency>
332+
<dependency>
333+
<groupId>org.asciidoctor</groupId>
334+
<artifactId>asciidoctorj</artifactId>
335+
<version>1.5.4</version>
336+
</dependency>
337+
<dependency>
338+
<groupId>org.asciidoctor</groupId>
339+
<artifactId>asciidoctorj-pdf</artifactId>
340+
<version>1.5.0-alpha.11</version>
341+
</dependency>
326342
<!-- OpenNLP -->
327343
<dependency>
328344
<groupId>org.apache.opennlp</groupId>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.asciidoctor;
2+
3+
import static org.asciidoctor.Asciidoctor.Factory.create;
4+
import static org.asciidoctor.OptionsBuilder.options;
5+
6+
import java.io.File;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
import org.asciidoctor.Asciidoctor;
11+
12+
public class AsciidoctorDemo {
13+
14+
private final Asciidoctor asciidoctor;
15+
16+
public AsciidoctorDemo() {
17+
asciidoctor = create();
18+
}
19+
20+
public void generatePDFFromString(final String input) {
21+
22+
final Map<String, Object> options = options().inPlace(true)
23+
.backend("pdf")
24+
.asMap();
25+
26+
final String outfile = asciidoctor.convertFile(new File("sample.adoc"), options);
27+
}
28+
29+
public String generateHTMLFromString(final String input) {
30+
final String output = asciidoctor.convert("Hello _Baeldung_!", new HashMap<String, Object>());
31+
return output;
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.asciidoctor;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class AsciidoctorDemoTest {
7+
8+
@Test
9+
public void givenString_whenConverting_thenResultingHTMLCode() {
10+
final AsciidoctorDemo asciidoctorDemo = new AsciidoctorDemo();
11+
Assert.assertEquals(asciidoctorDemo.generateHTMLFromString("Hello _Baeldung_!"), "<div class=\"paragraph\">\n<p>Hello <em>Baeldung</em>!</p>\n</div>");
12+
}
13+
}

0 commit comments

Comments
 (0)