Skip to content

Commit

Permalink
Update EPUB example (#320)
Browse files Browse the repository at this point in the history
* Remove features no longer maintained
* Activate test

closes #141
  • Loading branch information
abelsromero authored Jan 4, 2025
1 parent d4d2812 commit 05c1e69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 61 deletions.
64 changes: 10 additions & 54 deletions asciidoctor-epub-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
</dependency>
</dependencies>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<attributes>
<sourcedir>${project.build.sourceDirectory}</sourcedir>
</attributes>
<backend>epub3</backend>
<sourceDocumentName>spine.adoc</sourceDocumentName>
<!-- <sourceDirectory>src/docs/asciidoc</sourceDirectory>-->
<!-- <attributes>-->
<!-- <sourcedir>${project.build.sourceDirectory}</sourcedir>-->
<!-- </attributes>-->
<resources>
<resource>
<directory>.</directory>
Expand All @@ -71,67 +73,21 @@
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>epub3</backend>
<sourceDocumentName>spine.adoc</sourceDocumentName>
</configuration>
</execution>


<!-- for converting asciidoc to a mobi format, asciidoc performs 2 steps. -->
<!-- first, it generates a xxxx-kf8.epub file, which is then, in the second step, processed in order
to create xxxx.mobi file. -->

<!-- general information: epub and mobi generation differs only in the attribute 'ebook-format',
which is set to 'epub3' for epub and to kf8 in order to generate a special annotated epub3
document which is suitable for kindlegen -->

<!-- per default, this attribute is set to 'epub3'. -->
<!-- you can set this attribute either in the corresponding .adoc file, or provide it like showed
in this execution block below -->
<!-- For testing and troubleshooting you can see the
contained resources in an extracted structure -->
<execution>
<id>generate-spine-kf8</id>
<id>generate-extracted-epub</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>epub3</backend>
<sourceDocumentName>spine.adoc</sourceDocumentName>
<attributes>
<source-highlighter>rouge</source-highlighter>
<ebook-format>kf8</ebook-format>
<ebook-extract/>
</attributes>
</configuration>
</execution>


<!-- attention: if there are problems calling kindlegen (see discussion here https://github.com/asciidoctor/asciidoctor-maven-examples/pull/68) -->
<!-- then you can call kindlegen directly via maven like showed below -->
<!---
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>generate-mobi-file</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.build.directory}/generated-docs/</workingDirectory>
<executable>${path.to.kindlegen}</executable>
<arguments>
<argument>spine.epub</argument>
</arguments>
</configuration>
</execution>
-->
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,56 @@

import org.asciidoctor.maven.examples.tests.MavenProject;
import org.asciidoctor.maven.examples.tests.MavenTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.function.Predicate;

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

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

private MavenProject mavenProject;

@Test
void shouldGenerateEpubFiles() {
void shouldGenerateEpubFile() {
File epub = mavenProject.getTarget(generatedDocs("spine.epub"));

assertThat(epub)
.isNotEmpty();
.isNotEmpty()
.isFile();
}

@Test
void shouldGenerateExtractedDir() {
File extractedDir = mavenProject.getTarget(generatedDocs("spine"));

assertThat(extractedDir)
.isDirectory()
.isDirectoryContaining(directory("EPUB"))
.isDirectoryContaining(directory("META-INF"))
.isDirectoryContaining(file("mimetype"));

assertThat(new File(extractedDir, "EPUB"))
.isDirectory()
.isDirectoryContaining(file("_chapter_1.xhtml"))
.isDirectoryContaining(file("_chapter_2.xhtml"))
.isDirectoryContaining(file("_chapter_3.xhtml"));

assertThat(new File(extractedDir, "EPUB/images"))
.isDirectory()
.isDirectoryContaining(file("sunset.jpg"));

extractedDir.toPath().resolve("");
}

private static Predicate<File> directory(String name) {
return file -> file.isDirectory() && file.getName().equals(name);
}

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

private String generatedDocs(String filename) {
Expand Down

0 comments on commit 05c1e69

Please sign in to comment.