require "review" require 'fileutils' require "review/retrovert/yamlconfig" module ReVIEW module Retrovert class Converter attr_accessor :config, :basedir def initialize @basedir = nil @srccontentsdir = nil @outimagedir = nil @logger = ReVIEW.logger @configs = YamlConfig.new @embeded_contents = [] @catalog_contents = [] end def error(msg) @logger.error msg exit 1 end def warn(msg) @logger.warn msg end def info(msg) @logger.info msg end def copy_config(outdir) @configs.copy(outdir) end def copy_catalog(outdir) yamlfile = @config['catalogfile'] FileUtils.copy(File.join(@basedir, yamlfile), File.join(outdir, File.basename(yamlfile))) end def copy_contents(outdir) path = File.join(@basedir, @srccontentsdir) # outpath = File.join(outdir, srccontentsdir) # FileUtils.mkdir_p(outpath) # FileUtils.cp_r(Dir.glob(File.join(path, '*.re')), outpath) FileUtils.cp_r(Dir.glob(File.join(path, '*.re')), outdir) end def copy_images(outdir) imagedir = @config['imagedir'] srcpath = File.join(@basedir, imagedir) outimagedir = File.basename(imagedir) # Re:VIEW not support sub-directory outpath = File.join(outdir, outimagedir) FileUtils.mkdir_p(outpath) image_ext = @config['image_ext'] srcroot = Pathname.new(srcpath) image_ext.each { |ext| Dir.glob(File.join(srcpath, "**/*.#{ext}")).each { |srcimg| outimg = File.join(outpath, Pathname.new(srcimg).relative_path_from(srcroot)) FileUtils.makedirs(File.dirname(outimg)) FileUtils.cp(srcimg, outimg) } } @configs.rewrite_yml('imagedir', outimagedir) end def update_config(outdir) @configs.rewrite_yml('contentdir', '.') @configs.rewrite_yml('hook_beforetexcompile', 'null') @configs.rewrite_yml('texstyle', '["reviewmacro"]') # @configs.rewrite_yml('chapterlink', 'null') pagesize = @config['starter']['pagesize'].downcase @configs.rewrite_yml_array('texdocumentclass', "[\"review-jsbook\", \"media=print,paper=#{pagesize}\"]") @config['retrovert'].each{ |k,v| unless v..is_a?(Hash) @configs.commentout_root_yml(k) end } end def replace_compatible_block_command_outline(content, command, new_command, option_count) if option_count > 0 content.gsub!(/^\/\/#{command}(?