lib/review/textmaker.rb in review-5.3.0 vs lib/review/textmaker.rb in review-5.4.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2018-2021 Kenshi Muto +# Copyright (c) 2018-2022 Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # For details of the GNU LGPL, see the file "COPYING". @@ -72,13 +72,18 @@ def execute(*args) cmd_config, yamlfile = parse_opts(args) error! "#{yamlfile} not found." unless File.exist?(yamlfile) - @config = ReVIEW::Configure.create(maker: 'textmaker', - yamlfile: yamlfile, - config: cmd_config) + begin + @config = ReVIEW::Configure.create(maker: 'textmaker', + yamlfile: yamlfile, + config: cmd_config) + rescue ReVIEW::ConfigError => e + error! e.message + end + @img_math = ReVIEW::ImgMath.new(@config, path_name: '_review_math_text') I18n.setup(@config['language']) begin generate_text_files(yamlfile) @@ -109,16 +114,15 @@ end end def build_body(basetmpdir, _yamlfile) base_path = Pathname.new(@basedir) - builder = nil - if @plaintext - builder = ReVIEW::PLAINTEXTBuilder.new(img_math: @img_math) - else - builder = ReVIEW::TOPBuilder.new(img_math: @img_math) - end + builder = if @plaintext + ReVIEW::PLAINTEXTBuilder.new(img_math: @img_math) + else + ReVIEW::TOPBuilder.new(img_math: @img_math) + end @converter = ReVIEW::Converter.new(@book, builder) @book.parts.each do |part| if part.name.present? if part.file? build_chap(part, base_path, basetmpdir, true) @@ -140,27 +144,25 @@ f.puts end end def build_chap(chap, base_path, basetmpdir, ispart) - filename = '' - - if ispart.present? - filename = chap.path - else - filename = Pathname.new(chap.path).relative_path_from(base_path).to_s - end + filename = if ispart.present? + chap.path + else + Pathname.new(chap.path).relative_path_from(base_path).to_s + end id = File.basename(filename).sub(/\.re\Z/, '') if @buildonly && !@buildonly.include?(id) warn "skip #{id}.re" return end textfile = "#{id}.txt" begin @converter.convert(filename, File.join(basetmpdir, textfile)) - rescue => e + rescue StandardError => e @compile_errors = true error "compile error in #{filename} (#{e.class})" error e.message end end