From: Keith Fahlgren Date: Thu, 10 Jul 2008 16:58:11 +0000 (+0000) Subject: Adding better support for covers in epub files destined for .mobi and the Kindle X-Git-Tag: release/1.79.1~6^2~1289 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=950d25e2e7023907464e3da9e5147d9360dafb87;p=docbook-dsssl Adding better support for covers in epub files destined for .mobi and the Kindle --- diff --git a/xsl/epub/bin/spec/epub_realbook_spec.rb b/xsl/epub/bin/spec/epub_realbook_spec.rb index 4cedd3666..aca579739 100755 --- a/xsl/epub/bin/spec/epub_realbook_spec.rb +++ b/xsl/epub/bin/spec/epub_realbook_spec.rb @@ -18,40 +18,39 @@ $DEBUG = false TESTDOCSDIR = File.expand_path(File.join(File.dirname(__FILE__), 'files')) -TMPDIR = File.join(Dir::tmpdir(), "epubspecreal"); Dir.mkdir(TMPDIR) rescue Errno::EEXIST - describe DocBook::Epub do - Dir["#{TESTDOCSDIR}/orm*.[0-9][0-9][0-9].xml"].sort_by { rand }.each do |xml_file| - epub = DocBook::Epub.new(xml_file, TMPDIR) - epub_file = File.join(TMPDIR, File.basename(xml_file, ".xml") + ".epub") - epub.render_to_file(epub_file, $DEBUG) - - FileUtils.copy(epub_file, "." + File.basename(xml_file, ".xml") + ".epub") if $DEBUG - - it "should be able to render a valid .epub for the 'Real Book' test document #{xml_file}" do - epub_file.should be_valid_epub - end - - it "should include cover images in each rendered epub of a 'Real Book' test document like #{xml_file}" do - cvr_tmpdir = File.join(Dir::tmpdir(), "epubcovers"); Dir.mkdir(cvr_tmpdir) rescue Errno::EEXIST - system("unzip -q -o -d #{cvr_tmpdir} #{epub_file}") - cover_grep_lines = `grep --no-filename -c cvr_ #{cvr_tmpdir}/OEBPS/*.html` - num_covers = cover_grep_lines.split("\n").inject(0) {|sum,n| sum + n.to_i} - num_covers.should > 0 - FileUtils.rm_r(cvr_tmpdir, :force => true) - end - - it "should use the as dc:identifier for the 'Real Book' test document #{xml_file}" do - tmpdir = File.join(Dir::tmpdir(), "epubdcid"); Dir.mkdir(tmpdir) rescue Errno::EEXIST - - success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epub_file}") - raise "Could not unzip #{epub_file}" unless success - opf_file = Dir.glob(File.join(tmpdir, "**", "*.opf")).first - File.open(opf_file).readlines.to_s.should =~ /identifier[^>]+>urn:isbn:[0-9]/ - end + before(:all) do + @tmpdir = File.join(Dir::tmpdir(), "epubspecreal"); Dir.mkdir(@tmpdir) rescue Errno::EEXIST + @xml_file = Dir["#{TESTDOCSDIR}/orm*.[0-9][0-9][0-9].xml"].sort_by { rand }.first + @epub = DocBook::Epub.new(@xml_file, @tmpdir) + @epub_file = File.join(@tmpdir, File.basename(@xml_file, ".xml") + ".epub") + @epub.render_to_file(@epub_file, $DEBUG) + + FileUtils.copy(@epub_file, "." + File.basename(@xml_file, ".xml") + ".epub") if $DEBUG + + @tmpdir2 = File.join(Dir::tmpdir(), "epubreal"); Dir.mkdir(@tmpdir2) rescue Errno::EEXIST + success = system("unzip -q -o -d #{@tmpdir2} #{@epub_file}") + raise "Could not unzip #{epub_file}" unless success + + @html_files = Dir.glob(File.join(@tmpdir2, "**", "*.html")) + @opf_file = Dir.glob(File.join(@tmpdir2, "**", "*.opf")).first + end + + it "should be able to render a valid .epub for the 'Real Book' test document #{@xml_file}" do + @epub_file.should be_valid_epub + end + + it "should include the large cover image in each rendered epub of a 'Real Book' test document like #{@xml_file}" do + @cover_links = @html_files.find_all {|html_file| File.open(html_file).readlines.to_s =~ /cvr_lrg.jpg/} + @cover_links.length.should == 1 + end + + it "should use the as dc:identifier for the 'Real Book' test document #{@xml_file}" do + File.open(@opf_file).readlines.to_s.should =~ /identifier[^>]+>urn:isbn:[0-9]/ end after(:all) do - FileUtils.rm_r(TMPDIR, :force => true) + FileUtils.rm_r(@tmpdir, :force => true) + FileUtils.rm_r(@tmpdir2, :force => true) end end diff --git a/xsl/epub/bin/spec/files/orm.book.001.xml b/xsl/epub/bin/spec/files/orm.book.001.xml index 99dd0e59b..a8c7b703b 100644 --- a/xsl/epub/bin/spec/files/orm.book.001.xml +++ b/xsl/epub/bin/spec/files/orm.book.001.xml @@ -110,6 +110,9 @@ Mxxx xx xxx xxxxxxxxxxxx xxxx xx xxxxxxxxxxxxx xxx xxxxxxx xx xxxxxxxxxxx + + + diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index feb41f261..4e9b5ff4d 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -891,7 +891,7 @@ - + @@ -941,7 +941,7 @@ - + @@ -1368,7 +1368,7 @@ - +