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 <isbn> 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 <isbn> 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
<xsl:attribute name="id">
<xsl:choose>
<!-- TODO: Remove hardcoded 'front' -->
- <xsl:when test="ancestor::mediaobject[@role='cover'] and @role='front'">
+ <xsl:when test="ancestor::mediaobject[@role='cover'] and ../@role='front-large'">
<xsl:value-of select="$epub.cover.image.id"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="id">
<xsl:choose>
<!-- TODO: Remove hardcoded 'front' -->
- <xsl:when test="ancestor::mediaobject[@role='cover'] and @role='front'">
+ <xsl:when test="ancestor::mediaobject[@role='cover'] and ../@role='front-large'">
<xsl:value-of select="$epub.cover.image.id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$epub.cover.image.id"/>
</xsl:attribute>
<!-- TODO: Remove hardcoded 'front' -->
- <xsl:apply-templates select="imageobject[@role='front']"/>
+ <xsl:apply-templates select="imageobject[@role='front-large']"/>
</xsl:element>
</xsl:element>
</xsl:element>