bin/review-compile in review-4.2.0 vs bin/review-compile in review-5.0.0

- old
+ new

@@ -77,36 +77,34 @@ case @mode when :files error('no input') if ARGV.empty? @basedir = File.dirname(ARGV[0]) - book = ReVIEW::Book::Base.load(@basedir) - book.config = @config # needs only at the first time + book = ReVIEW::Book::Base.new(@basedir, config: @config) ARGV.each do |item| error("file not found: #{item}") unless File.exist?(File.join(book.config['contentdir'], item)) chap_name = File.basename(item, '.*') chap = book.chapter(chap_name) - compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only)) + compiler = ReVIEW::Compiler.new(load_builder_class(@target, @check_only)) result = compiler.compile(chap) if @output_filename - write(@output_filename, result) + File.write(@output_filename, result) else puts result unless @check_only end end when :dir - book = @basedir ? ReVIEW::Book.load(@basedir) : ReVIEW::Book::Base.load - book.config = @config - compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only)) + book = @basedir ? ReVIEW::Book::Base.new(@basedir, config: @config) : ReVIEW::Book::Base.new(config: @config) + compiler = ReVIEW::Compiler.new(load_builder_class(@target, @check_only)) book.chapters.each do |chap| str = compiler.compile(chap) - write("#{chap.name}#{compiler.strategy.extname}", str) unless @check_only + File.write("#{chap.name}#{compiler.builder.extname}", str) unless @check_only end # PART book.parts_in_file.each do |part| str = compiler.compile(part) - write("#{part.name}#{compiler.strategy.extname}", str) unless @check_only + File.write("#{part.name}#{compiler.builder.extname}", str) unless @check_only end else raise "must not happen: #{@mode}" end rescue ReVIEW::ApplicationError => e @@ -176,15 +174,11 @@ def warn(msg) @logger.warn msg end -def load_strategy_class(target, strict) +def load_builder_class(target, strict) require "review/#{target}builder" ReVIEW.const_get("#{target.upcase}Builder").new(strict) -end - -def write(path, str) - File.open(path, 'w') { |f| f.puts str } end main