diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 4579e291e..9daf4e134 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi +# Copyright (c) 2010-2024 Kenshi Muto and Masayoshi Takahashi # # This program is free software. # You can distribute or modify this program under the terms of @@ -523,7 +523,7 @@ def copy_stylesheet(basetmpdir) end def copy_static_file(configname, destdir, destfilename: nil) - destfilename ||= @config[configname] + destfilename ||= File.basename(@config[configname]) unless File.exist?(@config[configname]) error! "#{configname}: #{@config[configname]} is not found." end diff --git a/lib/review/epubmaker/epubcommon.rb b/lib/review/epubmaker/epubcommon.rb index ec29649af..b2e6cdf6d 100644 --- a/lib/review/epubmaker/epubcommon.rb +++ b/lib/review/epubmaker/epubcommon.rb @@ -1,6 +1,6 @@ # = epubcommon.rb -- super class for EPUBv2 and EPUBv3 # -# Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi +# Copyright (c) 2010-2024 Kenshi Muto and Masayoshi Takahashi # # This program is free software. # You can distribute or modify this program under the terms of @@ -320,19 +320,19 @@ def flat_ncx(type, indent = nil) end def produce_write_common(basedir, tmpdir) - File.write("#{tmpdir}/mimetype", mimetype) + File.write(File.join(tmpdir, 'mimetype'), mimetype) - FileUtils.mkdir_p("#{tmpdir}/META-INF") - File.write("#{tmpdir}/META-INF/container.xml", container) + FileUtils.mkdir_p(File.join(tmpdir, 'META-INF')) + File.write(File.join(tmpdir, 'META-INF', 'container.xml'), container) - FileUtils.mkdir_p("#{tmpdir}/OEBPS") + FileUtils.mkdir_p(File.join(tmpdir, 'OEBPS')) File.write(File.join(tmpdir, opf_path), opf) if config['cover'] - if File.exist?("#{basedir}/#{config['cover']}") - FileUtils.cp("#{basedir}/#{config['cover']}", "#{tmpdir}/OEBPS") + if File.exist?(File.join(basedir, File.basename(config['cover']))) + FileUtils.cp(File.join(basedir, File.basename(config['cover'])), File.join(tmpdir, 'OEBPS')) else - File.write("#{tmpdir}/OEBPS/#{config['cover']}", cover) + File.write(File.join(tmpdir, 'OEBPS', File.basename(config['cover'])), cover) end end @@ -344,13 +344,13 @@ def produce_write_common(basedir, tmpdir) contents.each do |item| next if /#/.match?(item.file) # skip subgroup - fname = "#{basedir}/#{item.file}" + fname = File.join(basedir, item.file) unless File.exist?(fname) raise ApplicationError, "#{fname} is not found." end - FileUtils.mkdir_p(File.dirname("#{tmpdir}/OEBPS/#{item.file}")) - FileUtils.cp(fname, "#{tmpdir}/OEBPS/#{item.file}") + FileUtils.mkdir_p(File.dirname(File.join(tmpdir, 'OEBPS', item.file))) + FileUtils.cp(fname, File.join(tmpdir, 'OEBPS', item.file)) end end diff --git a/lib/review/pdfmaker.rb b/lib/review/pdfmaker.rb index a41c7c062..0c480fa51 100644 --- a/lib/review/pdfmaker.rb +++ b/lib/review/pdfmaker.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi +# Copyright (c) 2010-2024 Kenshi Muto and Masayoshi Takahashi # # This program is free software. # You can distribute or modify this program under the terms of @@ -339,6 +339,7 @@ def make_custom_page(file) File.read(file_sty) else warn "File #{file_sty} is not found." + nil end end @@ -505,6 +506,15 @@ def template_content template_dir = @basedir template_path = 'layouts/layout.tex.erb' end + + if @config['cover'] && !File.exist?(@config['cover']) + error! "File #{@config['cover']} is not found." + end + + if @config['titlepage'] && @config['titlefile'] && !File.exist?(@config['titlefile']) + error! "File #{@config['titlefile']} is not found." + end + ReVIEW::Template.generate(path: template_path, mode: '-', binding: binding, template_dir: template_dir) rescue StandardError => e if defined?(e.full_message) diff --git a/review.gemspec b/review.gemspec index 5e8fdaf1a..0dbe77e4d 100644 --- a/review.gemspec +++ b/review.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |gem| gem.add_dependency('rouge') gem.add_dependency('rubyzip') gem.add_dependency('tty-logger') - gem.add_development_dependency('mini_magick') + gem.add_development_dependency('mini_magick', '~> 5.0.0') gem.add_development_dependency('playwright-runner') gem.add_development_dependency('pygments.rb') gem.add_development_dependency('rake') diff --git a/test/test_epubmaker.rb b/test/test_epubmaker.rb index 0380fbb05..cdca5f825 100644 --- a/test/test_epubmaker.rb +++ b/test/test_epubmaker.rb @@ -875,6 +875,9 @@ def error(s) File.write(File.join(tmpdir, 'exist.css'), 'body {}') File.write(File.join(tmpdir, 'exist.html'), '') + Dir.mkdir(File.join(tmpdir, 'subdir')) + File.write(File.join(tmpdir, 'subdir', 'exist.html'), '') + Dir.chdir(tmpdir) do Dir.mkdir('test') yield(epubmaker, File.join(tmpdir, 'test')) @@ -897,6 +900,9 @@ def test_copy_static_file epubmaker.config['titlefile'] = 'exist.html' assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) } + epubmaker.config['titlefile'] = 'subdir/exist.html' + assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) } + epubmaker.config['titlefile'] = 'nothing.html' @log_io.string = '' assert_raise(SystemExit) { epubmaker.copy_frontmatter(tmpdir) } @@ -909,6 +915,9 @@ def test_copy_static_file epubmaker.config[name] = 'exist.html' assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) } + epubmaker.config[name] = 'subdir/exist.html' + assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) } + epubmaker.config[name] = 'nothing.html' @log_io.string = '' assert_raise(SystemExit) { epubmaker.copy_frontmatter(tmpdir) } @@ -921,6 +930,9 @@ def test_copy_static_file epubmaker.config[name] = 'exist.html' assert_nothing_raised { epubmaker.copy_backmatter(tmpdir) } + epubmaker.config[name] = 'subdir/exist.html' + assert_nothing_raised { epubmaker.copy_backmatter(tmpdir) } + epubmaker.config[name] = 'nothing.html' @log_io.string = '' assert_raise(SystemExit) { epubmaker.copy_backmatter(tmpdir) } diff --git a/test/test_img_math.rb b/test/test_img_math.rb index 8f1e49716..33f7d347c 100644 --- a/test/test_img_math.rb +++ b/test/test_img_math.rb @@ -87,7 +87,8 @@ def test_make_math_image private def compare_images(image1, image2) - compare = MiniMagick::Tool::Compare.new(whiny: false) + MiniMagick.errors = false + compare = MiniMagick::Tool::Compare.new compare << '-fuzz' compare << '10%' compare.metric('AE')