$DEBUG = false
+def opf_lines(filename, filedir)
+ shortname = filename.gsub(/\W/, '')
+ tmpdir = File.join(Dir::tmpdir(), shortname); Dir.mkdir(tmpdir) rescue Errno::EEXIST
+ epub = DocBook::Epub.new(File.join(filedir, filename), tmpdir)
+ epubfile = File.join(tmpdir, shortname + ".epub")
+ epub.render_to_file(epubfile, $DEBUG)
+ FileUtils.copy(epubfile, "." + shortname + ".epub") if $DEBUG
+ success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{File.expand_path(epubfile)}")
+ raise "Could not unzip #{epubfile}" unless success
+ opf_file = Dir.glob(File.join(tmpdir, "**", "*.opf")).first
+ opf_lines = File.open(opf_file).readlines
+ return opf_lines
+end
+
describe DocBook::Epub do
before(:all) do
@filedir = File.expand_path(File.join(File.dirname(__FILE__), 'files'))
@valid_epub.should_not satisfy {|ve| DocBook::Epub.invalid?(ve)}
end
+ it "should include at least one dc:identifier" do
+ # TODO Consider UUID
+ opf_lns = opf_lines('nogoodid.xml', @filedir)
+ opf_lns.to_s.should =~ /identifier[^>]+>[^<][^_<]+</
+ end
+
+ it "should include an ISBN as URN for dc:identifier if an ISBN was in the metadata" do
+ opf_lns = opf_lines('isbn.xml', @filedir)
+ opf_lns.to_s.should =~ /identifier[^>]+>urn:isbn:123456789X</
+ end
+
+ it "should include an ISSN as URN for dc:identifier if an ISSN was in the metadata" do
+ opf_lns = opf_lines('issn.xml', @filedir)
+ opf_lns.to_s.should =~ /identifier[^>]+>urn:issn:X987654321</
+ end
+
+ it "should include an biblioid as a dc:identifier if an biblioid was in the metadata" do
+ opf_lns = opf_lines('biblioid.xml', @filedir)
+ opf_lns.to_s.should =~ /identifier[^>]+>thebiblioid</
+ end
+
+ it "should include a URN for a biblioid with @class attribute as a dc:identifier if an biblioid was in the metadata" do
+ opf_lns = opf_lines('biblioid.doi.xml', @filedir)
+ opf_lns.to_s.should =~ /identifier[^>]+>urn:doi:thedoi</
+ end
+
it "should not include PDFs in rendered epub files as valid image inclusions" do
begin
tmpdir = File.join(Dir::tmpdir(), "epubinclusiontest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
<xsl:variable name="unique-id">
<xsl:choose>
<xsl:when test="/*/*[contains(name(.), 'info')]/biblioid"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/biblioid"/> </xsl:when>
- <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/invpartnumber"/> </xsl:when>
+ <xsl:when test="/*/*[contains(name(.), 'info')]/isbn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/isbn"/> </xsl:when>
<xsl:when test="/*/*[contains(name(.), 'info')]/issn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/issn"/> </xsl:when>
+ <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/invpartnumber"/> </xsl:when>
<xsl:when test="/*/*[contains(name(.), 'info')]/issuenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/issuenum"/> </xsl:when>
<xsl:when test="/*/*[contains(name(.), 'info')]/productnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/productnumber"/> </xsl:when>
- <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/pubsnumber"/> </xsl:when>
<xsl:when test="/*/*[contains(name(.), 'info')]/seriesvolnums"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/seriesvolnums"/> </xsl:when>
<xsl:when test="/*/*[contains(name(.), 'info')]/volumenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/volumenum"/> </xsl:when>
- <xsl:when test="/*/*[contains(name(.), 'info')]/isbn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/isbn"/> </xsl:when>
+ <!-- Deprecated -->
+ <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/pubsnumber"/> </xsl:when>
</xsl:choose>
<xsl:text>_</xsl:text>
- <xsl:value-of select="/*/@id"/>
+ <xsl:choose>
+ <xsl:when test="/*/@id">
+ <xsl:value-of select="/*/@id"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- TODO: Do UUIDs here -->
+ <xsl:value-of select="generate-id(/*)"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:variable>
<xsl:variable name="doc.title">
<xsl:call-template name="get.doc.title" />
<xsl:element name="dc:identifier">
<xsl:attribute name="id"><xsl:value-of select="$package-id"/></xsl:attribute>
<xsl:choose>
+ <xsl:when test="/appendix/appendixinfo/biblioid|
+ /article/articleinfo/biblioid|
+ /book/bookinfo/biblioid|
+ /chapter/chapterinfo/biblioid|
+ /glossary/glossaryinfo/biblioid|
+ /part/partinfo/biblioid|
+ /preface/prefaceinfo/biblioid|
+ /refentry/refentryinfo/biblioid|
+ /reference/referenceinfo/biblioid|
+ /refsect1/refsect1info/biblioid|
+ /refsect2/refsect2info/biblioid|
+ /refsect3/refsect3info/biblioid|
+ /refsection/refsectioninfo/biblioid|
+ /refsynopsisdiv/refsynopsisdivinfo/biblioid|
+ /sect1/sect1info/biblioid|
+ /sect2/sect2info/biblioid|
+ /sect3/sect3info/biblioid|
+ /sect4/sect4info/biblioid|
+ /sect5/sect5info/biblioid|
+ /section/sectioninfo/biblioid|
+ /setindex/setindexinfo/biblioid|
+ /set/setinfo/biblioid">
+ <xsl:if test="/*/*/biblioid[1]/@class = 'doi' or /*/*/biblioid[1]/@class = 'isbn' or /*/*/biblioid[1]/@class = 'isrn' or /*/*/biblioid[1]/@class = 'issn'">
+ <xsl:text>urn:</xsl:text>
+ <xsl:value-of select="/*/*/biblioid[1]/@class"/>
+ <xsl:text>:</xsl:text>
+ </xsl:if>
+ <xsl:value-of select="/*/*/biblioid[1]"/>
+ </xsl:when>
<xsl:when test="/appendix/appendixinfo/isbn|
/article/articleinfo/isbn|
/book/bookinfo/isbn|
<xsl:text>urn:isbn:</xsl:text>
<xsl:value-of select="/*/*/isbn"/>
</xsl:when>
+ <xsl:when test="/appendix/appendixinfo/issn|
+ /article/articleinfo/issn|
+ /book/bookinfo/issn|
+ /chapter/chapterinfo/issn|
+ /glossary/glossaryinfo/issn|
+ /part/partinfo/issn|
+ /preface/prefaceinfo/issn|
+ /refentry/refentryinfo/issn|
+ /reference/referenceinfo/issn|
+ /refsect1/refsect1info/issn|
+ /refsect2/refsect2info/issn|
+ /refsect3/refsect3info/issn|
+ /refsection/refsectioninfo/issn|
+ /refsynopsisdiv/refsynopsisdivinfo/issn|
+ /sect1/sect1info/issn|
+ /sect2/sect2info/issn|
+ /sect3/sect3info/issn|
+ /sect4/sect4info/issn|
+ /sect5/sect5info/issn|
+ /section/sectioninfo/issn|
+ /setindex/setindexinfo/issn|
+ /set/setinfo/issn">
+ <xsl:text>urn:issn:</xsl:text>
+ <xsl:value-of select="/*/*/issn"/>
+ </xsl:when>
<xsl:otherwise>
<xsl:value-of select="$unique-id"/>
</xsl:otherwise>