lib/review/textmaker.rb in review-5.0.0 vs lib/review/textmaker.rb in review-5.1.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2018-2020 Kenshi Muto
+# Copyright (c) 2018-2021 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".
@@ -14,10 +14,11 @@
require 'review/book'
require 'review/yamlloader'
require 'review/topbuilder'
require 'review/version'
require 'review/makerhelper'
+require 'review/img_math'
module ReVIEW
class TEXTMaker
include MakerHelper
@@ -25,10 +26,11 @@
def initialize
@basedir = nil
@logger = ReVIEW.logger
@plaintext = nil
+ @img_math = nil
end
def error(msg)
@logger.error msg
exit 1
@@ -68,33 +70,35 @@
def build_path
"#{@config['bookname']}-text"
end
def remove_old_files(path)
- cleanup_mathimg('_review_math_text')
+ @img_math.cleanup_mathimg
FileUtils.rm_rf(path)
end
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)
+ @img_math = ReVIEW::ImgMath.new(@config, path_name: '_review_math_text')
I18n.setup(@config['language'])
begin
generate_text_files(yamlfile)
+ @logger.success("built #{build_path}")
rescue ApplicationError => e
raise if @config['debug']
+
error(e.message)
end
- math_dir = "./#{@config['imagedir']}/_review_math_text"
- if @config['imgmath'] && File.exist?(File.join(math_dir, '__IMGMATH_BODY__.map'))
- make_math_images(math_dir)
+ if @config['math_format'] == 'imgmath'
+ @img_math.make_math_images
end
end
def generate_text_files(yamlfile)
@basedir = File.dirname(yamlfile)
@@ -109,12 +113,12 @@
def build_body(basetmpdir, _yamlfile)
base_path = Pathname.new(@basedir)
builder = nil
if @plaintext
- builder = ReVIEW::PLAINTEXTBuilder.new
+ builder = ReVIEW::PLAINTEXTBuilder.new(img_math: @img_math)
else
- builder = ReVIEW::TOPBuilder.new
+ builder = 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?