Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore missing files in verify_target_images #1930

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ 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 +215,10 @@ 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
Loading