Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EPUB example #320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading