Skip to content

Commit 05c1e69

Browse files
authored
Update EPUB example (#320)
* Remove features no longer maintained * Activate test closes #141
1 parent d4d2812 commit 05c1e69

File tree

2 files changed

+45
-61
lines changed

2 files changed

+45
-61
lines changed

asciidoctor-epub-example/pom.xml

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
</dependency>
5151
</dependencies>
5252
<configuration>
53-
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
54-
<attributes>
55-
<sourcedir>${project.build.sourceDirectory}</sourcedir>
56-
</attributes>
53+
<backend>epub3</backend>
54+
<sourceDocumentName>spine.adoc</sourceDocumentName>
55+
<!-- <sourceDirectory>src/docs/asciidoc</sourceDirectory>-->
56+
<!-- <attributes>-->
57+
<!-- <sourcedir>${project.build.sourceDirectory}</sourcedir>-->
58+
<!-- </attributes>-->
5759
<resources>
5860
<resource>
5961
<directory>.</directory>
@@ -71,67 +73,21 @@
7173
<goals>
7274
<goal>process-asciidoc</goal>
7375
</goals>
74-
<configuration>
75-
<backend>epub3</backend>
76-
<sourceDocumentName>spine.adoc</sourceDocumentName>
77-
</configuration>
7876
</execution>
79-
80-
81-
<!-- for converting asciidoc to a mobi format, asciidoc performs 2 steps. -->
82-
<!-- first, it generates a xxxx-kf8.epub file, which is then, in the second step, processed in order
83-
to create xxxx.mobi file. -->
84-
85-
<!-- general information: epub and mobi generation differs only in the attribute 'ebook-format',
86-
which is set to 'epub3' for epub and to kf8 in order to generate a special annotated epub3
87-
document which is suitable for kindlegen -->
88-
89-
<!-- per default, this attribute is set to 'epub3'. -->
90-
<!-- you can set this attribute either in the corresponding .adoc file, or provide it like showed
91-
in this execution block below -->
77+
<!-- For testing and troubleshooting you can see the
78+
contained resources in an extracted structure -->
9279
<execution>
93-
<id>generate-spine-kf8</id>
80+
<id>generate-extracted-epub</id>
9481
<phase>generate-resources</phase>
9582
<goals>
9683
<goal>process-asciidoc</goal>
9784
</goals>
9885
<configuration>
99-
<backend>epub3</backend>
100-
<sourceDocumentName>spine.adoc</sourceDocumentName>
10186
<attributes>
102-
<source-highlighter>rouge</source-highlighter>
103-
<ebook-format>kf8</ebook-format>
87+
<ebook-extract/>
10488
</attributes>
10589
</configuration>
10690
</execution>
107-
108-
109-
<!-- attention: if there are problems calling kindlegen (see discussion here https://github.com/asciidoctor/asciidoctor-maven-examples/pull/68) -->
110-
<!-- then you can call kindlegen directly via maven like showed below -->
111-
<!---
112-
113-
</executions>
114-
</plugin>
115-
<plugin>
116-
<groupId>org.codehaus.mojo</groupId>
117-
<artifactId>exec-maven-plugin</artifactId>
118-
<version>1.6.0</version>
119-
<executions>
120-
<execution>
121-
<id>generate-mobi-file</id>
122-
<phase>generate-resources</phase>
123-
<goals>
124-
<goal>exec</goal>
125-
</goals>
126-
<configuration>
127-
<workingDirectory>${project.build.directory}/generated-docs/</workingDirectory>
128-
<executable>${path.to.kindlegen}</executable>
129-
<arguments>
130-
<argument>spine.epub</argument>
131-
</arguments>
132-
</configuration>
133-
</execution>
134-
-->
13591
</executions>
13692
</plugin>
13793
</plugins>

tests/src/test/java/org/asciidoctor/maven/examples/AsciidoctorEpubTest.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,56 @@
22

33
import org.asciidoctor.maven.examples.tests.MavenProject;
44
import org.asciidoctor.maven.examples.tests.MavenTest;
5-
import org.junit.jupiter.api.Disabled;
65
import org.junit.jupiter.api.Test;
76

87
import java.io.File;
8+
import java.util.function.Predicate;
99

1010
import static org.assertj.core.api.Assertions.assertThat;
1111

12-
@Disabled("issue-141")
1312
@MavenTest(projectPath = "../asciidoctor-epub-example")
1413
class AsciidoctorEpubTest {
1514

1615
private MavenProject mavenProject;
1716

1817
@Test
19-
void shouldGenerateEpubFiles() {
18+
void shouldGenerateEpubFile() {
2019
File epub = mavenProject.getTarget(generatedDocs("spine.epub"));
20+
2121
assertThat(epub)
22-
.isNotEmpty();
22+
.isNotEmpty()
23+
.isFile();
24+
}
25+
26+
@Test
27+
void shouldGenerateExtractedDir() {
28+
File extractedDir = mavenProject.getTarget(generatedDocs("spine"));
29+
30+
assertThat(extractedDir)
31+
.isDirectory()
32+
.isDirectoryContaining(directory("EPUB"))
33+
.isDirectoryContaining(directory("META-INF"))
34+
.isDirectoryContaining(file("mimetype"));
35+
36+
assertThat(new File(extractedDir, "EPUB"))
37+
.isDirectory()
38+
.isDirectoryContaining(file("_chapter_1.xhtml"))
39+
.isDirectoryContaining(file("_chapter_2.xhtml"))
40+
.isDirectoryContaining(file("_chapter_3.xhtml"));
41+
42+
assertThat(new File(extractedDir, "EPUB/images"))
43+
.isDirectory()
44+
.isDirectoryContaining(file("sunset.jpg"));
45+
46+
extractedDir.toPath().resolve("");
47+
}
48+
49+
private static Predicate<File> directory(String name) {
50+
return file -> file.isDirectory() && file.getName().equals(name);
51+
}
2352

24-
File epubKf8 = mavenProject.getTarget(generatedDocs("spine-kf8.epub"));
25-
assertThat(epubKf8)
26-
.isNotEmpty();
53+
private static Predicate<File> file(String name) {
54+
return file -> file.isFile() && file.getName().equals(name) && file.length() > 0;
2755
}
2856

2957
private String generatedDocs(String filename) {

0 commit comments

Comments
 (0)