From: Keith Fahlgren Date: Tue, 17 Feb 2009 04:03:20 +0000 (+0000) Subject: Liza Daly reported that the dc:identifer-generation code was garbage (she was right). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a73e41daf504288fd458bb3857f834212f0db483;p=docbook-dsssl 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 --- diff --git a/xsl/epub/bin/spec/epub_spec.rb b/xsl/epub/bin/spec/epub_spec.rb index 8174feda0..22143ddd6 100755 --- a/xsl/epub/bin/spec/epub_spec.rb +++ b/xsl/epub/bin/spec/epub_spec.rb @@ -16,6 +16,20 @@ require 'docbook' $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 @@ describe DocBook::Epub do @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[^>]+>[^<][^_<]+]+>urn:isbn:123456789X]+>urn:issn:X987654321]+>thebiblioid]+>urn:doi:thedoi + + + + Test: biblioid + + Keith + Fahlgren + +
+ keith@oreilly.com +
+
+
+ thedoi +
+ + Chapter One + This document has a biblioid assigned. + +
+ + diff --git a/xsl/epub/bin/spec/files/biblioid.xml b/xsl/epub/bin/spec/files/biblioid.xml new file mode 100644 index 000000000..d6522a2df --- /dev/null +++ b/xsl/epub/bin/spec/files/biblioid.xml @@ -0,0 +1,22 @@ + + + + + Test: biblioid + + Keith + Fahlgren + +
+ keith@oreilly.com +
+
+
+ thebiblioid +
+ + Chapter One + This document has a biblioid assigned. + +
+ diff --git a/xsl/epub/bin/spec/files/isbn.xml b/xsl/epub/bin/spec/files/isbn.xml new file mode 100644 index 000000000..7640b61ee --- /dev/null +++ b/xsl/epub/bin/spec/files/isbn.xml @@ -0,0 +1,21 @@ + + + + + Test: isbn + + Keith + Fahlgren + +
+ keith@oreilly.com +
+
+
+ 123456789X +
+ + Chapter One + This document has an ISBN assigned. + +
diff --git a/xsl/epub/bin/spec/files/issn.xml b/xsl/epub/bin/spec/files/issn.xml new file mode 100644 index 000000000..c5ae537b6 --- /dev/null +++ b/xsl/epub/bin/spec/files/issn.xml @@ -0,0 +1,21 @@ + + +
+ + Test: issn + + Keith + Fahlgren + +
+ keith@oreilly.com +
+
+
+ X987654321 +
+
+ Section One + This document has an issn assigned. +
+
diff --git a/xsl/epub/bin/spec/files/nogoodid.xml b/xsl/epub/bin/spec/files/nogoodid.xml new file mode 100644 index 000000000..7cfee19ed --- /dev/null +++ b/xsl/epub/bin/spec/files/nogoodid.xml @@ -0,0 +1,8 @@ + + + + + Chapter One + This document has nothing that looks particularly attractive as a dc:identifier. + + diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index e20786c0d..3502827ae 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -182,17 +182,26 @@ - + + - - + + _ - + + + + + + + + + @@ -217,6 +226,35 @@ + + + urn: + + : + + + + + urn:issn: + +