From: Keith Fahlgren Date: Fri, 30 May 2008 17:20:11 +0000 (+0000) Subject: Changes to OPF spine to not duplicate idrefs for documents with parts not at the... X-Git-Tag: release/1.79.1~6^2~1333 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fd56abf73a8d098aed4b8188aff50703619597f;p=docbook-dsssl Changes to OPF spine to not duplicate idrefs for documents with parts not at the root; regression specs for same --- diff --git a/xsl/epub/bin/dbtoepub b/xsl/epub/bin/dbtoepub old mode 100644 new mode 100755 index 111b61c5c..7de2be79d --- a/xsl/epub/bin/dbtoepub +++ b/xsl/epub/bin/dbtoepub @@ -1,10 +1,21 @@ #!/usr/bin/env ruby +# This program converts DocBook documents into .epub files. +# +# Usage: dbtoepub [OPTIONS] [DocBook Files] +# +# .epub is defined by the IDPF at www.idpf.org and is made up of 3 standards: +# - Open Publication Structure (OPS) +# - Open Packaging Format (OPF) +# - Open Container Format (OCF) +# +# Specific options: +# -d, --debug Show debugging output. +# -h, --help Display usage info +# -v, --verbose Make output verbose + lib = File.expand_path(File.join(File.dirname(__FILE__), 'lib')) $LOAD_PATH.unshift(lib) if File.exist?(lib) -# Keith Fahlgren -# Sat Feb 23 17:22:35 PST 2008 - require 'optparse' require 'docbook' diff --git a/xsl/epub/bin/lib/docbook.rb b/xsl/epub/bin/lib/docbook.rb index de45eca84..423e3eafe 100755 --- a/xsl/epub/bin/lib/docbook.rb +++ b/xsl/epub/bin/lib/docbook.rb @@ -37,7 +37,7 @@ module DocBook end def self.invalid?(file) - # obnoxiously, we can't just check for a non-zero output... + # Obnoxiously, we can't just check for a non-zero output... cmd = "#{CHECKER} #{file}" output = `#{cmd} 2>&1` @@ -69,12 +69,12 @@ module DocBook def bundle_epub(output_file, verbose) quiet = verbose ? "" : "-q" - # zip -X -r ../book.epub mimetype META-INF OEBPS mimetype_filename = write_mimetype() meta = File.basename(@meta_dir) oebps = File.basename(@oebps_dir) images = copy_images() callouts = copy_callouts() + # zip -X -r ../book.epub mimetype META-INF OEBPS zip_cmd = "cd #{@output_dir} && #{ZIPPER} #{quiet} -X -r #{File.expand_path(output_file)} #{mimetype_filename} #{meta} #{oebps}" puts zip_cmd if $DEBUG success = system(zip_cmd) diff --git a/xsl/epub/bin/spec/epub_realbook_spec.rb b/xsl/epub/bin/spec/epub_realbook_spec.rb index e893504ac..2b1d7433d 100755 --- a/xsl/epub/bin/spec/epub_realbook_spec.rb +++ b/xsl/epub/bin/spec/epub_realbook_spec.rb @@ -6,8 +6,8 @@ require 'spec/spec_helper' lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(lib) if File.exist?(lib) -require 'tmpdir' require 'fileutils' +require 'tmpdir' require 'rubygems' require 'spec' diff --git a/xsl/epub/bin/spec/epub_regressions_spec.rb b/xsl/epub/bin/spec/epub_regressions_spec.rb new file mode 100755 index 000000000..1d1ed137c --- /dev/null +++ b/xsl/epub/bin/spec/epub_regressions_spec.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby +spec = File.expand_path(File.dirname(__FILE__)) +$LOAD_PATH.unshift(spec) if File.exist?(spec) +require 'spec/spec_helper' + +lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH.unshift(lib) if File.exist?(lib) + +require 'fileutils' +require 'rexml/document' +require 'tmpdir' + +require 'rubygems' +require 'spec' + +require 'docbook' + +$DEBUG = false + +describe DocBook::Epub do + before(:all) do + @filedir = File.expand_path(File.join(File.dirname(__FILE__), 'files')) + @testdocsdir = File.expand_path(File.join(File.dirname(__FILE__), 'testdocs')) + @tmpdir = File.join(Dir::tmpdir(), "epubregressions"); Dir.mkdir(@tmpdir) rescue Errno::EEXIST + end + + it "should not include two s to the contents of s in the OPF file" do + part_file = File.join(@testdocsdir, "subtitle.001.xml") + epub_file = File.join(@tmpdir, File.basename(part_file, ".xml") + ".epub") + part_epub = DocBook::Epub.new(part_file, @tmpdir) + part_epub.render_to_file(epub_file, $DEBUG) + + FileUtils.copy(epub_file, "./.t.epub") if $DEBUG + + itemref_tmpdir = File.join(Dir::tmpdir(), "epubitemref"); Dir.mkdir(itemref_tmpdir) rescue Errno::EEXIST + system("unzip -q -o -d #{itemref_tmpdir} #{epub_file}") + opf_file = File.join(itemref_tmpdir, "OEBPS", "content.opf") + opf = REXML::Document.new(File.new(opf_file)) + + itemrefs = REXML::XPath.match(opf, "//itemref").map {|e| e.attributes['idref']} + itemrefs.should == itemrefs.uniq + end + + after(:all) do + FileUtils.rm_r(@tmpdir, :force => true) + end +end diff --git a/xsl/epub/bin/spec/epub_small_smoketest.rb b/xsl/epub/bin/spec/epub_small_smoketest.rb index 5ea0f1a62..28dd78748 100755 --- a/xsl/epub/bin/spec/epub_small_smoketest.rb +++ b/xsl/epub/bin/spec/epub_small_smoketest.rb @@ -14,7 +14,7 @@ require 'spec' require 'docbook' -$DEBUG = true +$DEBUG = false TESTDOCSDIR = File.expand_path(File.join(File.dirname(__FILE__), 'testdocs')) NUMBER_TO_TEST = 15 @@ -25,10 +25,7 @@ describe DocBook::Epub do @tmpdir = File.join(Dir::tmpdir(), "epubspecsmoke"); Dir.mkdir(@tmpdir) rescue Errno::EEXIST end - # TODO olink, index, cmdsynopsis, refentry, table - - Dir["#{TESTDOCSDIR}/programlisting*.006.xml"].sort_by { rand }[0..(NUMBER_TO_TEST-1)].each do |xml_file| - #Dir["#{TESTDOCSDIR}/*.[0-9][0-9][0-9].xml"].sort_by { rand }[0..(NUMBER_TO_TEST-1)].each do |xml_file| + Dir["#{TESTDOCSDIR}/*.[0-9][0-9][0-9].xml"].sort_by { rand }[0..(NUMBER_TO_TEST-1)].each do |xml_file| it "should be able to render a valid .epub for the test document #{xml_file}" do epub = DocBook::Epub.new(xml_file, @tmpdir) epub_file = File.join(@tmpdir, File.basename(xml_file, ".xml") + ".epub") diff --git a/xsl/epub/bin/spec/epub_smoketest_spec.rb b/xsl/epub/bin/spec/epub_smoketest_spec.rb index 7c39f7f58..6efad0d00 100755 --- a/xsl/epub/bin/spec/epub_smoketest_spec.rb +++ b/xsl/epub/bin/spec/epub_smoketest_spec.rb @@ -25,6 +25,26 @@ describe DocBook::Epub do @tmpdir = File.join(Dir::tmpdir(), "epubspecsmoke"); Dir.mkdir(@tmpdir) rescue Errno::EEXIST end + # TODO + # Known failures on all of: + # calloutlist.003.xml + # extensions.00[24].xml + # programlisting.00[26].xml + # olink.*.xml + # cmdsynopsis.002.xml + # refentry.007.xml + # programlistingco.002.xml + # textobject.*.xml + # + # The causes of the failures are typically missing extensions in xsltproc + # (specifically insertfile, for textdata, imagedata, graphic, or inlinegraphic + # text/XML @filerefs, invalid XHTML 1.1 (block elements inside inlines that + # I don't feel like # fixing because I think they're edge cases), callouts + # (which are hard in .epub), or test docs I really don't think are cromulent. + + # Current passage rate: + # 224 examples, 12 failures (94.6%) + Dir["#{TESTDOCSDIR}/[a-z]*.[0-9][0-9][0-9].xml"].each_with_index do |xml_file, ix| it "should be able to render a valid .epub for the test document #{xml_file} [#{ix}]" do epub = DocBook::Epub.new(xml_file, @tmpdir) diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index c7b5462c1..020e69109 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -24,12 +24,13 @@ - - + - + + + @@ -41,7 +42,6 @@ htmltoc - - - - - - + + + + + + + + @@ -778,7 +780,7 @@ - Warning: mediaobjectco almost certain will not render as expected in .epub + Warning: mediaobjectco almost certainly will not render as expected in .epub! @@ -1321,4 +1323,8 @@ + + + +