From b4f6d917cf9653351adcd47af4b4d07c887b4a82 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sun, 17 Nov 2024 21:49:43 +0900 Subject: [PATCH 1/2] ignore missing files in verify_target_images --- lib/review/epubmaker.rb | 8 +++++++- test/test_epubmaker.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 8a281d24..adf1c544 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -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 @@ -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| diff --git a/test/test_epubmaker.rb b/test/test_epubmaker.rb index ef3ad77a..a31454ef 100644 --- a/test/test_epubmaker.rb +++ b/test/test_epubmaker.rb @@ -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 From e49763fbfa2ea08598fb14a4dcf2331cba8c2ead Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sun, 17 Nov 2024 21:52:09 +0900 Subject: [PATCH 2/2] follow rubocop --- lib/review/epubmaker.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index adf1c544..08bb39b5 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -205,6 +205,7 @@ def verify_target_images(basetmpdir) 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']) @@ -217,6 +218,7 @@ def verify_target_images(basetmpdir) 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|