From 15d8540eab18a301067dd5f7466b4439bbc44d9f Mon Sep 17 00:00:00 2001 From: Keith Fahlgren Date: Tue, 17 Feb 2009 04:41:34 +0000 Subject: [PATCH] Patch contributed by Liza Daly to make ePub cover handling more generic. Additionally DocBook 5.0's now has some limited support: - should reference a cover in the OPF guide for a DocBook 5.0 test document --- xsl/epub/bin/spec/epub_regressions_spec.rb | 6 +++ xsl/epub/bin/spec/epub_spec.rb | 13 ------ xsl/epub/bin/spec/files/v5cover.xml | 25 +++++++++++ xsl/epub/bin/spec/spec_helper.rb | 17 ++++++++ xsl/epub/docbook.xsl | 48 ++++++++++++++-------- 5 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 xsl/epub/bin/spec/files/v5cover.xml diff --git a/xsl/epub/bin/spec/epub_regressions_spec.rb b/xsl/epub/bin/spec/epub_regressions_spec.rb index 9f6d55572..1b152b3c4 100755 --- a/xsl/epub/bin/spec/epub_regressions_spec.rb +++ b/xsl/epub/bin/spec/epub_regressions_spec.rb @@ -17,6 +17,7 @@ require 'docbook' $DEBUG = false + describe DocBook::Epub do before(:all) do @filedir = File.expand_path(File.join(File.dirname(__FILE__), 'files')) @@ -103,6 +104,11 @@ describe DocBook::Epub do xhtml_dtd_in_opf_file.should_not be_true end + it "should reference a cover in the OPF guide for a DocBook 5.0 test document" do + opf_lns = opf_lines('v5cover.xml', @filedir) + opf_lns.to_s.should =~ /reference[^>]+type=['"]cover['"]/ + end + after(:all) do FileUtils.rm_r(@tmpdir, :force => true) end diff --git a/xsl/epub/bin/spec/epub_spec.rb b/xsl/epub/bin/spec/epub_spec.rb index 22143ddd6..e4ea0f635 100755 --- a/xsl/epub/bin/spec/epub_spec.rb +++ b/xsl/epub/bin/spec/epub_spec.rb @@ -16,19 +16,6 @@ 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 diff --git a/xsl/epub/bin/spec/files/v5cover.xml b/xsl/epub/bin/spec/files/v5cover.xml new file mode 100644 index 000000000..082f0475a --- /dev/null +++ b/xsl/epub/bin/spec/files/v5cover.xml @@ -0,0 +1,25 @@ + + + v5 test + + + Liza + Daly + + + + + + + + + Additional content on cover page. + + + + + DocBook v5 Regression Cover Test + + Some content + + diff --git a/xsl/epub/bin/spec/spec_helper.rb b/xsl/epub/bin/spec/spec_helper.rb index d3cfe75ba..51b755d38 100755 --- a/xsl/epub/bin/spec/spec_helper.rb +++ b/xsl/epub/bin/spec/spec_helper.rb @@ -3,6 +3,7 @@ $LOAD_PATH.unshift(lib) if File.exist?(lib) require 'docbook' +# Helper classes class BeValidEpub def initialize @@ -35,3 +36,19 @@ end def be_valid_epub BeValidEpub.new end + + +# Helper Functions +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 diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index 3502827ae..5c81361d4 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -36,7 +36,7 @@ - + ncxtoc htmltoc @@ -321,7 +321,7 @@ - + cover @@ -404,7 +404,7 @@ type="cover" pointing to it AND there is a logical cover specified in a tag, THEN, the HTML cover is discarded. --> - + cover @@ -656,10 +656,10 @@ + /*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> http://www.idpf.org/2007/opf - + @@ -694,12 +694,19 @@ - + - no + + + + yes + + no + + @@ -773,7 +780,7 @@ - + http://www.idpf.org/2007/opf @@ -972,8 +979,7 @@ http://www.idpf.org/2007/opf - - + @@ -1022,8 +1028,7 @@ http://www.idpf.org/2007/opf - - + @@ -1421,10 +1426,10 @@ - + - + @@ -1449,9 +1454,20 @@ - - + + + + + + + + + + + + -- 2.49.0