Skip to content

Commit

Permalink
Change html-chunker into an XProc step
Browse files Browse the repository at this point in the history
Also add an XProcSpec test.
  • Loading branch information
bertfrees committed Nov 19, 2018
1 parent 531d4e1 commit 8a2e50a
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
<artifactId>html-utils</artifactId>
<version>3.0.1</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
Expand Down
47 changes: 43 additions & 4 deletions html-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,55 @@
</parent>

<artifactId>html-utils</artifactId>
<version>3.0.2-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>DAISY Pipeline 2 module :: HTML Utilities</name>

<dependencies>
<!--
runtime dependencies
test dependencies
-->
<!-- none -->
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>calabash-adapter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.daisy.pipeline.build</groupId>
<artifactId>modules-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
<build>
<plugins>
<plugin>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>maven-paxexam-plugin</artifactId>
<executions>
<execution>
<id>generate-depends-file</id>
<goals>
<goal>generate-depends-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-before-test</id>
<phase>generate-test-resources</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
2 changes: 0 additions & 2 deletions html-utils/src/main/resources/META-INF/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
uri="../xml/xslt/html5-outliner.xsl"/>
<uri name="http://www.daisy.org/pipeline/modules/html-utils/html5-upgrade.xsl"
uri="../xml/xslt/html5-upgrade.xsl"/>
<uri name="http://www.daisy.org/pipeline/modules/html-utils/html-chunker.xsl"
uri="../xml/xslt/html-chunker.xsl"/>
<uri name="http://www.daisy.org/pipeline/modules/html-utils/html-id-fixer.xsl"
uri="../xml/xslt/html-id-fixer.xsl"/>
<uri name="http://www.daisy.org/pipeline/modules/html-utils/html-fixer.xsl"
Expand Down
23 changes: 23 additions & 0 deletions html-utils/src/main/resources/xml/xproc/html-chunker.xpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step type="px:html-chunker"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:px="http://www.daisy.org/ns/pipeline/xproc"
exclude-inline-prefixes="#all"
version="1.0">

<p:input port="source"/>
<p:output port="result" sequence="true">
<p:pipe step="xslt" port="secondary"/>
</p:output>

<p:xslt name="xslt">
<p:input port="stylesheet">
<p:document href="../xslt/html-chunker.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:sink/>

</p:declare-step>
1 change: 1 addition & 0 deletions html-utils/src/main/resources/xml/xproc/html-library.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<p:library xmlns:p="http://www.w3.org/ns/xproc" version="1.0">

<p:import href="html-load.xpl"/>
<p:import href="html-chunker.xpl"/>

</p:library>
11 changes: 11 additions & 0 deletions html-utils/src/test/java/XProcSpecTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import org.daisy.pipeline.junit.AbstractXSpecAndXProcSpecTest;

import org.junit.Test;

public class XProcSpecTest extends AbstractXSpecAndXProcSpecTest {

@Override @Test
public void runXSpec() {
// already run with xspec-maven-plugin
}
}
11 changes: 11 additions & 0 deletions html-utils/src/test/resources/config-calabash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--*- nxml -*-->
<xproc-config xmlns="http://xmlcalabash.com/ns/configuration"
xmlns:px="http://www.daisy.org/ns/pipeline/xproc"
xmlns:letex="http://www.le-tex.de/namespace">

<implementation type="px:info" class-name="com.xmlcalabash.extensions.fileutils.Info"/>
<implementation type="px:unzip" class-name="com.xmlcalabash.extensions.Unzip"/>
<implementation type="px:zip" class-name="com.xmlcalabash.extensions.Zip"/>
<implementation type="letex:unzip" class-name="org.daisy.common.xproc.calabash.steps.UnZipProvider.UnZip"/>

</xproc-config>
1 change: 1 addition & 0 deletions html-utils/src/test/resources/exam.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pax.exam.logging = none
24 changes: 24 additions & 0 deletions html-utils/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="TEST_LOG" class="ch.qos.logback.core.FileAppender">
<file>target/test.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="WARN">
<appender-ref ref="TEST_LOG"/>
</root>

<logger name="org.daisy" level="DEBUG"/>
<logger name="com.xmlcalabash" level="DEBUG"/>

</configuration>
165 changes: 165 additions & 0 deletions html-utils/src/test/xprocspec/html-chunker.xprocspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.daisy.org/ns/xprocspec"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:px="http://www.daisy.org/ns/pipeline/xproc"
xmlns:epub="http://www.idpf.org/2007/ops"
xmlns="http://www.w3.org/1999/xhtml"
script="../../main/resources/xml/xproc/html-chunker.xpl">

<x:scenario label="section based chunking">
<x:call step="px:html-chunker">
<x:input port="source">
<x:document type="inline">
<html>
<body>
<section epub:type="frontmatter">
<section/>
<section/>
</section>
<section epub:type="bodymatter">
<section/>
<p/>
<p/>
<section/>
</section>
</body>
</html>
</x:document>
</x:input>
</x:call>
<x:context label="the chunks">
<x:document type="port" port="result"/>
</x:context>
<x:expect label="frontmatter in one chunk, each bodymatter subsections in its own chunk" type="compare">
<x:document type="inline">
<html>
<body epub:type="frontmatter">
<section/>
<section/>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<body epub:type="bodymatter">
<section/>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<body epub:type="bodymatter">
<p/>
<p/>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<body epub:type="bodymatter">
<section/>
</body>
</html>
</x:document>
</x:expect>
</x:scenario>

<x:scenario label="title">
<x:call step="px:html-chunker">
<x:input port="source">
<x:document type="inline">
<html>
<head>
<title>foo</title>
</head>
<body>
<section>
<h1>A</h1>
</section>
<section>
<h1>B</h1>
</section>
<section/>
</body>
</html>
</x:document>
</x:input>
</x:call>
<x:context label="the chunks">
<x:document type="port" port="result"/>
</x:context>
<x:expect label="each chunk gets its own title based on the body contents" type="compare">
<x:document type="inline">
<html>
<head>
<title>A</title>
</head>
<body>
<h1>A</h1>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<head>
<title>B</title>
</head>
<body>
<h1>B</h1>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<head>
<title>foo</title>
</head>
<body/>
</html>
</x:document>
</x:expect>
</x:scenario>

<x:scenario label="link correction">
<x:call step="px:html-chunker">
<x:input port="source">
<x:document type="inline">
<html>
<body>
<section>
<h1>a</h1>
<a href="#x"/>
</section>
<section>
<h1>b</h1>
<p id="x"/>
</section>
</body>
</html>
</x:document>
</x:input>
</x:call>
<x:context label="the chunks">
<x:document type="port" port="result"/>
</x:context>
<x:expect label="links between chunks are corrected" type="compare">
<x:document type="inline">
<html>
<body>
<h1>a</h1>
<a href="html-chunker-2.xprocspec#x"/>
</body>
</html>
</x:document>
<x:document type="inline">
<html>
<body>
<h1>b</h1>
<p id="x"/>
</body>
</html>
</x:document>
</x:expect>
</x:scenario>

</x:description>

0 comments on commit 8a2e50a

Please sign in to comment.