Skip to content

Commit

Permalink
ignore missing files in verify_target_images
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Nov 17, 2024
1 parent fecb2e5 commit b4f6d91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def verify_target_images(basetmpdir)
@producer.contents.each do |content|
case content.media
when 'application/xhtml+xml'
File.open("#{basetmpdir}/#{content.file}") do |f|
unless File.exist?(File.join(basetmpdir, content.file))
next
end
File.open(File.join(basetmpdir, content.file)) do |f|
REXML::Document.new(File.new(f)).each_element('//img') do |e|
@config['epubmaker']['force_include_images'].push(e.attributes['src'])
if e.attributes['src'] =~ /svg\Z/i
Expand All @@ -211,6 +214,9 @@ def verify_target_images(basetmpdir)
end
end
when 'text/css'
unless File.exist?(File.join(basetmpdir, content.file))
next
end
File.open(File.join(basetmpdir, content.file)) do |f|
f.each_line do |l|
l.scan(/url\((.+?)\)/) do |_m|
Expand Down
15 changes: 15 additions & 0 deletions test/test_epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,19 @@ def test_verify_target_images
assert_equal true, true
end
end

def test_accept_missing_file_in_verify_target_images
epubmaker_instance do |epubmaker, tmpdir|
epubmaker.config['epubmaker']['verify_target_images'] = true
epubmaker.config['coverimage'] = 'cover.png'

epubmaker.producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'missing.html', title: 'MISSING', level: 1)
epubmaker.producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'missing.css')
epubmaker.verify_target_images(tmpdir)

expect = %w[images/cover.png]
assert_equal expect, epubmaker.config['epubmaker']['force_include_images']
assert_equal true, true
end
end
end

0 comments on commit b4f6d91

Please sign in to comment.