From: <abd...@us...> - 2009-02-17 04:03:38
|
Revision: 8245 http://docbook.svn.sourceforge.net/docbook/?rev=8245&view=rev Author: abdelazer Date: 2009-02-17 04:03:20 +0000 (Tue, 17 Feb 2009) Log Message: ----------- Liza Daly reported that the dc:identifer-generation code was garbage (she was right). Added new tests: - should include at least one dc:identifier - should include an ISBN as URN for dc:identifier if an ISBN was in the metadata - should include an ISSN as URN for dc:identifier if an ISSN was in the metadata - should include an biblioid as a dc:identifier if an biblioid was in the metadata - should include a URN for a biblioid with @class attribute as a dc:identifier if an biblioid was in the metadata Modified Paths: -------------- trunk/xsl/epub/bin/spec/epub_spec.rb trunk/xsl/epub/docbook.xsl Added Paths: ----------- trunk/xsl/epub/bin/spec/files/biblioid.doi.xml trunk/xsl/epub/bin/spec/files/biblioid.xml trunk/xsl/epub/bin/spec/files/isbn.xml trunk/xsl/epub/bin/spec/files/issn.xml trunk/xsl/epub/bin/spec/files/nogoodid.xml Modified: trunk/xsl/epub/bin/spec/epub_spec.rb =================================================================== --- trunk/xsl/epub/bin/spec/epub_spec.rb 2009-02-15 12:56:43 UTC (rev 8244) +++ trunk/xsl/epub/bin/spec/epub_spec.rb 2009-02-17 04:03:20 UTC (rev 8245) @@ -16,6 +16,20 @@ $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')) @@ -136,6 +150,32 @@ @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 Added: trunk/xsl/epub/bin/spec/files/biblioid.doi.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/biblioid.doi.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/biblioid.doi.xml 2009-02-17 04:03:20 UTC (rev 8245) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> +<book> + <bookinfo> + <title>Test: biblioid</title> + <author> + <firstname>Keith</firstname> + <surname>Fahlgren</surname> + <affiliation> + <address> + <email>ke...@or...</email> + </address> + </affiliation> + </author> + <biblioid class="doi">thedoi</biblioid> + </bookinfo> + <chapter> + <title>Chapter One</title> + <para>This document has a biblioid assigned.</para> + </chapter> +</book> + + Property changes on: trunk/xsl/epub/bin/spec/files/biblioid.doi.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: trunk/xsl/epub/bin/spec/files/biblioid.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/biblioid.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/biblioid.xml 2009-02-17 04:03:20 UTC (rev 8245) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> +<book> + <bookinfo> + <title>Test: biblioid</title> + <author> + <firstname>Keith</firstname> + <surname>Fahlgren</surname> + <affiliation> + <address> + <email>ke...@or...</email> + </address> + </affiliation> + </author> + <biblioid>thebiblioid</biblioid> + </bookinfo> + <chapter> + <title>Chapter One</title> + <para>This document has a biblioid assigned.</para> + </chapter> +</book> + Property changes on: trunk/xsl/epub/bin/spec/files/biblioid.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: trunk/xsl/epub/bin/spec/files/isbn.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/isbn.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/isbn.xml 2009-02-17 04:03:20 UTC (rev 8245) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> +<book> + <bookinfo> + <title>Test: isbn</title> + <author> + <firstname>Keith</firstname> + <surname>Fahlgren</surname> + <affiliation> + <address> + <email>ke...@or...</email> + </address> + </affiliation> + </author> + <isbn>123456789X</isbn> + </bookinfo> + <chapter> + <title>Chapter One</title> + <para>This document has an ISBN assigned.</para> + </chapter> +</book> Property changes on: trunk/xsl/epub/bin/spec/files/isbn.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: trunk/xsl/epub/bin/spec/files/issn.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/issn.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/issn.xml 2009-02-17 04:03:20 UTC (rev 8245) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> +<article> + <articleinfo> + <title>Test: issn</title> + <author> + <firstname>Keith</firstname> + <surname>Fahlgren</surname> + <affiliation> + <address> + <email>ke...@or...</email> + </address> + </affiliation> + </author> + <issn>X987654321</issn> + </articleinfo> + <section> + <title>Section One</title> + <para>This document has an issn assigned.</para> + </section> +</article> Property changes on: trunk/xsl/epub/bin/spec/files/issn.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: trunk/xsl/epub/bin/spec/files/nogoodid.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/nogoodid.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/nogoodid.xml 2009-02-17 04:03:20 UTC (rev 8245) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> +<book> + <chapter> + <title>Chapter One</title> + <para>This document has nothing that looks particularly attractive as a dc:identifier.</para> + </chapter> +</book> Property changes on: trunk/xsl/epub/bin/spec/files/nogoodid.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Modified: trunk/xsl/epub/docbook.xsl =================================================================== --- trunk/xsl/epub/docbook.xsl 2009-02-15 12:56:43 UTC (rev 8244) +++ trunk/xsl/epub/docbook.xsl 2009-02-17 04:03:20 UTC (rev 8245) @@ -182,17 +182,26 @@ <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')]/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')]/issn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/issn"/> </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" /> @@ -217,6 +226,35 @@ <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| @@ -242,6 +280,31 @@ <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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |