Class: ReVIEW::Retrovert::Converter
- Inherits:
-
Object
- Object
- ReVIEW::Retrovert::Converter
- Defined in:
- lib/review/retrovert/converter.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
Returns the value of attribute basedir.
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #add_catalog_contents(contentfiles) ⇒ Object
- #add_linkurl_footnote(content, filename) ⇒ Object
- #clean_initial_project(outdir) ⇒ Object
- #convert_csv_option(content) ⇒ Object
- #convert_starter_option(content) ⇒ Object
- #copy_catalog(outdir) ⇒ Object
- #copy_config(outdir) ⇒ Object
- #copy_contents(outdir) ⇒ Object
- #copy_embedded_contents(outdir, content) ⇒ Object
- #copy_images(outdir, store_image_dir) ⇒ Object
- #copy_wards(outdir, words_file) ⇒ Object
- #create_initial_project(outdir, options) ⇒ Object
- #delete_block_command(content, command) ⇒ Object
- #delete_block_command_outer(content, command) ⇒ Object
- #delete_inline_command(content, command) ⇒ Object
-
#desclist_to_nested_contents_list(content, cmd) ⇒ Object
desclist to //#cmd[]{ //emlist[]{}… }.
- #do_replace_inline_command(content, command, &blk) ⇒ Object
- #erb_sty(outdir, filename) ⇒ Object
- #error(msg) ⇒ Object
- #exclude_exta_option(content, cmd, max_option_num) ⇒ Object
- #exclude_exta_options(content, commands, max_option_num) ⇒ Object
- #execute(yamlfile, outdir, options) ⇒ Object
-
#expand_nested_inline_command(content) ⇒ Object
@<XXX>AAA@<YYY>{BBB} to @<XXX>AAA@<YYY>BBB.
- #fix_deprecated_list(content) ⇒ Object
- #get_out_imagedir(outdir) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize ⇒ Converter
constructor
A new instance of Converter.
- #load_config(yamlfile) ⇒ Object
- #make_id_label(name) ⇒ Object
- #preproc_content_files(outdir, pp, contentdir, contentfiles) ⇒ Object
- #preproc_contents(outdir, options) ⇒ Object
- #remove_option_param(content, commands, n, param) ⇒ Object
- #remove_starter_options(content) ⇒ Object
- #remove_starter_refid(content) ⇒ Object
- #replace_auto_ids(content, command, require_option_count) ⇒ Object
- #replace_block_command_nested_boxed_article(content, box) ⇒ Object
- #replace_block_command_nested_boxed_article_i(content, box, depth) ⇒ Object
- #replace_block_command_nested_boxed_articles(content) ⇒ Object
- #replace_block_command_outline(content, command, new_command, use_option) ⇒ Object
-
#replace_block_commentout(content) ⇒ Object
#@+++ ~ #@— to #@#+++ #@#~ #@#—.
- #replace_block_commentout_without_sampleout(content) ⇒ Object
- #replace_compatible_block_command_outline(content, command, new_command, option_count, begin_option_pos = 0) ⇒ Object
- #replace_compatible_block_command_to_outside(content, command, new_command, option_count, add_options = "", new_body = "") ⇒ Object
- #replace_file_option(content, matched, fence_open, option) ⇒ Object
- #replace_inline_command(content, command, new_command) ⇒ Object
- #replace_sampleoutput(content) ⇒ Object
- #replace_starter_command(content) ⇒ Object
- #replace_starter_inline_command(content) ⇒ Object
- #replace_tsize(content) ⇒ Object
- #restore_out_image(outpath, tmpdir) ⇒ Object
- #starter_caption_to_text(content, command, n) ⇒ Object
- #starter_list_to_nested_contents_list(content) ⇒ Object
- #store_out_image(outdir) ⇒ Object
-
#talklist_to_nested_contents_list(content, cmd) ⇒ Object
talklist to //#cmd[]{ //emlist[]{}… }.
- #update_config(outdir) ⇒ Object
- #update_content(outdir, contentfile) ⇒ Object
- #update_content_files(outdir, contentdir, contentfiles) ⇒ Object
- #update_contents(outdir, options) ⇒ Object
- #update_ext(outdir, options) ⇒ Object
- #update_sty(outdir, options) ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize ⇒ Converter
Returns a new instance of Converter.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/review/retrovert/converter.rb', line 15 def initialize @basedir = nil @srccontentsdir = nil @outimagedir = nil @logger = ReVIEW.logger @configs = YamlConfig.new @embeded_contents = [] @catalog_contents = [] @talk_shortcuts = {} @ird = false @talklist_replace_cmd = "note" @desclist_replace_cmd = "info" @talk_icon_scale = 0.1 @r_option_inner = ReViewDef::r_option_inner end |
Instance Attribute Details
#basedir ⇒ Object
Returns the value of attribute basedir.
13 14 15 |
# File 'lib/review/retrovert/converter.rb', line 13 def basedir @basedir end |
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/review/retrovert/converter.rb', line 13 def config @config end |
Class Method Details
.execute(yamlfile, outdir, options) ⇒ Object
1011 1012 1013 |
# File 'lib/review/retrovert/converter.rb', line 1011 def self.execute(yamlfile, outdir, ) self.new.execute(yamlfile, outdir, ) end |
Instance Method Details
#add_catalog_contents(contentfiles) ⇒ Object
939 940 941 942 |
# File 'lib/review/retrovert/converter.rb', line 939 def add_catalog_contents(contentfiles) files = contentfiles.is_a?(String) ? contentfiles.split(/\R/) : contentfiles @catalog_contents.concat(files) end |
#add_linkurl_footnote(content, filename) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/review/retrovert/converter.rb', line 582 def add_linkurl_footnote(content, filename) urls = {} content.dup.scan(/(^.*)(@<href>{)(.*?)(,)(.*?)(})(.*)$/) { |m| unless m[0].match(/^#@#/) matched = m.join prev = m[0] url = m[2] text = m[4] post = m[6] id = "#{make_id_label(filename)}_link_auto_footnote#{urls.length}" urls[id] = url content.sub!(/#{Regexp.escape(matched)}$/, "#{prev}@<href>{#{url},#{text}} @<fn>{#{id}} #{post}") end } urls.each { |k,v| content.sub!(/(@<href>{#{v},.*?} @<fn>{#{k}}.*?\R\R)/m, "\\1//footnote[#{k}][#{v}]\n") } urls.each { |k,v| unless content.match(/\/\/footnote\[#{k}\]\[#{v}\]/) content << "//footnote[#{k}][#{v}]\n" end } end |
#clean_initial_project(outdir) ⇒ Object
932 933 934 935 936 937 |
# File 'lib/review/retrovert/converter.rb', line 932 def clean_initial_project(outdir) FileUtils.rm(File.join(outdir, 'config.yml')) FileUtils.rm(File.join(outdir, 'catalog.yml')) FileUtils.rm_rf(File.join(outdir, 'images')) FileUtils.rm(Dir.glob(File.join(outdir, '*.re'))) end |
#convert_csv_option(content) ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/review/retrovert/converter.rb', line 504 def convert_csv_option(content) r_table = /^(?<matched>\/\/table\[#{@r_option_inner}\]\[#{@r_option_inner}\]\[(?<options>#{@r_option_inner})\](?<open>.))$/ content.dup.scan(r_table) { |m| matched = m[0] = m[1] .split(',').each { |option| if option.match(/\s*csv\s*=\s*on\s*/) open = m[2] close = ReViewDef::fence_close(open) if close tm = content.match(/#{Regexp.escape(matched)}(.*?)^\/\/#{close}/m) outer = tm[0] inner = tm[1] im = inner.match(/(.*?)([=\-]{12,}\R)(.*)/m) if im header = im[1] sep = im[2] body = im[3] new_header = "" new_body = "" CSV.parse(header) do |h| new_header += Utils::GenerateTsv(h) end CSV.parse(body) do |c| new_body += Utils::GenerateTsv(c) end content.gsub!(outer, "#{matched}#{new_header}#{sep}#{new_body}//#{close}") else im = inner.match(/^\#@mapfile\((.*?)\)\R^\#@end/m) if im inner_file = im[1] csv_text = "\n" csv_text += File.open(File.join(@basedir, inner_file)).read() else csv_text = inner end new_body = "" CSV.parse(csv_text) do |c| new_body += Utils::GenerateTsv(c) end content.gsub!(outer, "#{matched}#{new_body}//#{close}") end end end } } end |
#convert_starter_option(content) ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/review/retrovert/converter.rb', line 488 def convert_starter_option(content) # file r = /^(?<matched>\/\/(list|listnum|table)\[#{@r_option_inner}\]\[#{@r_option_inner}\]\[(?<options>#{@r_option_inner})\](?<open>.))$/ content.dup.scan(r) { |m| matched = m[0] = m[1] fence_open = m[2] .split(',').each { |option| replace_file_option(content, matched, fence_open, option) } } remove_option_param(content, ["list", "listnum", "table"], 3, "file") # csv convert_csv_option(content) end |
#copy_catalog(outdir) ⇒ Object
49 50 51 52 |
# File 'lib/review/retrovert/converter.rb', line 49 def copy_catalog(outdir) yamlfile = @config['catalogfile'] FileUtils.copy(File.join(@basedir, yamlfile), File.join(outdir, File.basename(yamlfile))) end |
#copy_config(outdir) ⇒ Object
45 46 47 |
# File 'lib/review/retrovert/converter.rb', line 45 def copy_config(outdir) @configs.copy(outdir) end |
#copy_contents(outdir) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/review/retrovert/converter.rb', line 54 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 |
#copy_embedded_contents(outdir, content) ⇒ Object
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/review/retrovert/converter.rb', line 561 def (outdir, content) content.scan(/\#@mapfile\((.*?)\)/).each do |filepath_| filepath = filepath_[0] if filepath.blank? next end srcpath = File.join(@basedir, filepath) if File.exist?(srcpath) outpath = File.join(File.absolute_path(outdir), filepath) FileUtils.mkdir_p(File.dirname(outpath)) FileUtils.cp(srcpath, outpath) @embeded_contents.push(filepath) update_content(outpath, outpath) end end end |
#copy_images(outdir, store_image_dir) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/review/retrovert/converter.rb', line 87 def copy_images(outdir, store_image_dir) imagedir = @config['imagedir'] outimagedir = File.basename(imagedir) # Re:VIEW not support sub-directory outpath = get_out_imagedir(outdir) FileUtils.mkdir_p(outpath) if store_image_dir restore_out_image(outpath, store_image_dir) else srcpath = File.join(@basedir, imagedir) 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) } } end @configs.rewrite_yml('imagedir', outimagedir) end |
#copy_wards(outdir, words_file) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/review/retrovert/converter.rb', line 109 def copy_wards(outdir, words_file) new_file = words_file FileUtils.mkdir_p(File.join(outdir, File.dirname(words_file))) if File.extname(words_file) == ".csv" FileUtils.copy(File.join(@basedir, words_file), File.join(outdir, new_file)) else new_file += ".csv" Utils.Tsv2Csv(File.join(@basedir, words_file), File.join(outdir, new_file)) end new_file end |
#create_initial_project(outdir, options) ⇒ Object
957 958 959 960 961 |
# File 'lib/review/retrovert/converter.rb', line 957 def create_initial_project(outdir, ) FileUtils.rm_rf(outdir) if ['force'] ReVIEW::Init.execute(outdir) clean_initial_project(outdir) end |
#delete_block_command(content, command) ⇒ Object
235 236 237 238 |
# File 'lib/review/retrovert/converter.rb', line 235 def delete_block_command(content, command) content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{.*?\/\/}\R/m, '') content.gsub!(/^\/\/#{command}(\[.*?\])*\s*\R/, '') end |
#delete_block_command_outer(content, command) ⇒ Object
231 232 233 |
# File 'lib/review/retrovert/converter.rb', line 231 def delete_block_command_outer(content, command) content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}\R/m, '\k<inner>') end |
#delete_inline_command(content, command) ⇒ Object
652 653 654 655 |
# File 'lib/review/retrovert/converter.rb', line 652 def delete_inline_command(content, command) # 既に入れ子は展開されている前提 content.gsub!(/@<#{command}>(?:(\$)|(?:({)|(\|)))(.*?)(?(1)(\$)|(?(2)(})|(\|)))/, '\4') end |
#desclist_to_nested_contents_list(content, cmd) ⇒ Object
desclist to //#cmd[]{ //emlist[]{}… }
461 462 463 464 465 |
# File 'lib/review/retrovert/converter.rb', line 461 def desclist_to_nested_contents_list(content, cmd) content.gsub!(/^\/\/desclist(.*?){/, "//#{cmd}\\1{") content.gsub!(/^\/\/desc(?<options>\[#{@r_option_inner}\])\[(?<body>#{@r_option_inner})\]$/, "//desc\\k<options>{\n\\k<body>\n//}") content.gsub!(/^\/\/desc((\[#{@r_option_inner}\])*){/, '//emlist\1{') end |
#do_replace_inline_command(content, command, &blk) ⇒ Object
657 658 659 660 |
# File 'lib/review/retrovert/converter.rb', line 657 def do_replace_inline_command(content, command, &blk) # 既に入れ子は展開されている前提 content.gsub!(/@<#{command}>(?:(\$)|(?:({)|(\|)))(.*?)(?(1)(\$)|(?(2)(})|(\|)))/) { blk.call([$1, $2, $3].join, $4, [$5, $6, $7].join) } end |
#erb_sty(outdir, filename) ⇒ Object
909 910 911 912 913 914 |
# File 'lib/review/retrovert/converter.rb', line 909 def erb_sty(outdir, filename) src = File.join(__dir__, "sty/#{filename}.erb") dest = File.join(outdir, "sty/#{filename}") erb = ERB.new(File.read(src)) File.write(dest, erb.result) end |
#error(msg) ⇒ Object
32 33 34 35 |
# File 'lib/review/retrovert/converter.rb', line 32 def error(msg) @logger.error msg exit 1 end |
#exclude_exta_option(content, cmd, max_option_num) ⇒ Object
203 204 205 |
# File 'lib/review/retrovert/converter.rb', line 203 def exclude_exta_option(content, cmd, max_option_num) replace_compatible_block_command_outline(content, cmd, cmd, max_option_num) end |
#exclude_exta_options(content, commands, max_option_num) ⇒ Object
207 208 209 210 211 |
# File 'lib/review/retrovert/converter.rb', line 207 def (content, commands, max_option_num) commands.each do |cmd| exclude_exta_option(content, cmd, max_option_num) end end |
#execute(yamlfile, outdir, options) ⇒ Object
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/review/retrovert/converter.rb', line 963 def execute(yamlfile, outdir, ) @table_br_replace = ['table-br-replace'] @table_empty_replace = ['table-empty-replace'] @ird = ['ird'] load_config(yamlfile) store_image_dir = store_out_image(outdir) if ['no-image'] create_initial_project(outdir, ) @talk_shortcuts = @config['starter']['talk_shortcuts'] copy_config(outdir) copy_catalog(outdir) copy_images(outdir, store_image_dir) update_config(outdir) update_contents(outdir, ) update_sty(outdir, ) update_ext(outdir, ) unless ['no-delegate-config'] unless File.exist?(File.join(outdir, 'config.yml')) root_config = File.open(File.join(outdir, 'config.yml'), 'w') root_config.puts("review_version: #{ReVIEW::VERSION}") root_config.puts("inherit: [\"#{File.basename(yamlfile)}\"]") end unless File.exist?(File.join(outdir, 'catalog.yml')) catalogfile = @config['catalogfile'] FileUtils.copy(File.join(@basedir, catalogfile), File.join(outdir, 'catalog.yml')) end end unless ['no-update'] pwd = Dir.pwd Dir.chdir(outdir) updater = ReVIEW::Update.new updater.force = true # updater.backup = false begin updater.execute() rescue end Dir.chdir(pwd) end if ['preproc'] info 'preproc' preproc_contents(outdir, ) end end |
#expand_nested_inline_command(content) ⇒ Object
@<XXX>AAA@<YYY>{BBB} to @<XXX>AAA@<YYY>BBB
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'lib/review/retrovert/converter.rb', line 669 def (content) found = false content.dup.each_line do |line| if line.match(/^#@#/) next end line.scan(/(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m| matched = m.join body = m[4] outcmd_cmd = m[0] outcmd_open = m[1..3].join outcmd_begin = outcmd_cmd + outcmd_open outcmd_close = m[5..7].join im = body.match(/(.*)(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(3)(\$)|(?(4)(})|(\|)))(.*)/) if im.nil? # for {} im2 = body.match(/(.*)(@<.*?>)#{Regexp.escape(outcmd_open)}(.*)/) unless im2.nil? rep = "" if im2[3].length > 0 incmd_begin = im2[1..2].join + "$|{".gsub(outcmd_open, '')[0] incmd_end = "$|}".gsub(outcmd_close, '')[0] rep = "#{outcmd_begin}#{incmd_begin}#{im2[3]}#{incmd_end}" else rep = outcmd_begin + im2[1] end content.gsub!(matched) { |mm| rep } found = true else # for |$ if body.match(/.*@<.*?>$/) incmd_fence = "$|".gsub(outcmd_open, '') rep = "#{outcmd_begin}#{body}#{incmd_fence}" content.gsub!(/#{Regexp.escape(matched)}(.*?)#{Regexp.escape(outcmd_open)}/, "#{rep}\\1#{incmd_fence}") found = true end end else rep = "" rep += "#{outcmd_begin}#{im[1]}#{outcmd_close}" if im[1].length > 0 rep += "#{im[2..9].join}" rep += "#{outcmd_begin}#{im[-1]}#{outcmd_close}" if im[-1].length > 0 content.gsub!(matched) { |mm| rep } found = true end } end if found (content) end end |
#fix_deprecated_list(content) ⇒ Object
385 386 387 388 389 |
# File 'lib/review/retrovert/converter.rb', line 385 def fix_deprecated_list(content) if ReViewCompat::is_need_space_term_list() content.gsub!(/^: (.*)/, ' : \1') end end |
#get_out_imagedir(outdir) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/review/retrovert/converter.rb', line 62 def get_out_imagedir(outdir) imagedir = @config['imagedir'] outimagedir = File.basename(imagedir) # Re:VIEW not support sub-directory outpath = File.join(outdir, outimagedir) return outpath end |
#info(msg) ⇒ Object
41 42 43 |
# File 'lib/review/retrovert/converter.rb', line 41 def info(msg) @logger.info msg end |
#load_config(yamlfile) ⇒ Object
944 945 946 947 948 949 950 951 952 953 954 955 |
# File 'lib/review/retrovert/converter.rb', line 944 def load_config(yamlfile) @configs.open(yamlfile) @config = @configs.config @basedir = @configs.basedir @srccontentsdir = @config['contentdir'] catalog = ReViewCompat::Catalog(@configs.catalogfile()) add_catalog_contents(catalog.predef()) add_catalog_contents(catalog.chaps()) add_catalog_contents(catalog.appendix()) add_catalog_contents(catalog.postdef()) end |
#make_id_label(name) ⇒ Object
578 579 580 |
# File 'lib/review/retrovert/converter.rb', line 578 def make_id_label(name) name.gsub(/[^A-Za-z0-9]/, '_') end |
#preproc_content_files(outdir, pp, contentdir, contentfiles) ⇒ Object
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 |
# File 'lib/review/retrovert/converter.rb', line 875 def preproc_content_files(outdir, pp, contentdir, contentfiles) files = contentfiles.is_a?(String) ? contentfiles.split(/\R/) : contentfiles files.each do |content| contentpath = File.join(contentdir, content) if File.exist?(contentpath) info "preproc #{contentpath}" pwd = Dir.pwd Dir.chdir(outdir) content = pp.process(contentpath) Dir.chdir(pwd) content.gsub!(/^#[@]map.*$/, '') content.gsub!(/^#[@]end$/, '') File.write(contentpath, content) end end end |
#preproc_contents(outdir, options) ⇒ Object
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
# File 'lib/review/retrovert/converter.rb', line 892 def preproc_contents(outdir, ) yamlfile = @config['catalogfile'] abspath = File.absolute_path(outdir) contentdir = abspath param = {} param['tabwidth'] = ['tabwidth'].to_i pp = ReViewCompat::Preprocessor(param) if ['strict'] catalog = ReViewCompat::Catalog(File.join(abspath, yamlfile)) preproc_content_files(outdir, pp, contentdir, @catalog_contents) else contentsfiles = Pathname.glob(File.join(File.join(@basedir, @srccontentsdir), '*.re')).map(&:basename) preproc_content_files(outdir, pp, contentdir, contentsfiles) end end |
#remove_option_param(content, commands, n, param) ⇒ Object
407 408 409 410 411 412 413 414 415 |
# File 'lib/review/retrovert/converter.rb', line 407 def remove_option_param(content, commands, n, param) content.gsub!(/(^\/\/(#{commands.join('|')})(\[.*?\]){#{n-1}}\[.*?)((,|)\s*#{param}=[^,\]]*)(.*?\])/) { prev = $1 cmd = $2 opt = $4 post = $6 "#{prev}#{post}" } end |
#remove_starter_options(content) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/review/retrovert/converter.rb', line 417 def (content) # image width content.gsub!(/(^\/\/image\[.*?\]\[.*?\]\[.*?)(,|)(\s*)width=\s*([0-9.]+)%(?<after>.*?\])/) { |m| m.gsub!(/width=\s*([0-9.]+)%/) { value = $1 "scale=#{value.to_i * 0.01}" } } remove_option_param(content, ["image"], 3, "width") # image border remove_option_param(content, ["image"], 3, "border") # image pos remove_option_param(content, ["image"], 3, "pos") # list lineno remove_option_param(content, ["list", "listnum"], 3, "lineno") end |
#remove_starter_refid(content) ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/review/retrovert/converter.rb', line 391 def remove_starter_refid(content) # note - noteref content.dup.scan(/(@<noteref>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m| matched = m[0..-1].join ref = m[4] n = content.match(/^\/\/note\[#{ref}\](\[.*?\])/) unless n.nil? rep = n[1] content.gsub!(matched) { |mm| rep } content.gsub!(/^\/\/note\[#{ref}\](\[.*?\])/, '//note\1') else # content.gsub!(matched, "noteref<#{ref}>") end } end |
#replace_auto_ids(content, command, require_option_count) ⇒ Object
376 377 378 379 380 381 382 383 |
# File 'lib/review/retrovert/converter.rb', line 376 def replace_auto_ids(content, command, require_option_count) index = -1 content.gsub!(/^\/\/#{command}\[(|\?)\]/) { |s| index += 1; "//#{command}[starter_auto_id_#{command}_#{index}]" } if require_option_count > 0 while !content.gsub!(/(^\/\/#{command}(\[[^\[\]]*?\]){0,#{require_option_count-1}})($|{)/, '\1[]\3').nil? end end end |
#replace_block_command_nested_boxed_article(content, box) ⇒ Object
321 322 323 |
# File 'lib/review/retrovert/converter.rb', line 321 def replace_block_command_nested_boxed_article(content, box) replace_block_command_nested_boxed_article_i(content, box, 0) end |
#replace_block_command_nested_boxed_article_i(content, box, depth) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/review/retrovert/converter.rb', line 240 def replace_block_command_nested_boxed_article_i(content, box, depth) found = false content.dup.scan(/(^\/\/#{box})(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)).*?[\r\n]+)/m) { |m| matched = m[0..-1].join inner = m[5] # info depth im = inner.match(/^\/\/(?<command>\w+)(?<options>(\[#{@r_option_inner}\])*)(?<open>[$|{])/) unless im.nil? inner_cmd = im['command'] inner_open = im['open'] inner_opts = im['options'] id_opt = "" # is_commentout = false is_commentout = true if ReViewDef::is_has_id_block_command(inner_cmd) first_opt_m = inner_opts.match(/^\[(.*?)\]/) if first_opt_m first_opt_v = first_opt_m[1] unless first_opt_v.empty? if inner.match(/@<#{ReViewDef::id_ref_inline_commands().join('|')}>[$|{]#{first_opt_v}/) is_commentout = false id_opt = "\\[#{first_opt_v}\\]" end end end end cmd_begin = m[0..4].join cmd_end = m[6..-1].join # check other fence inner block (block command has fence??) if inner_open == m[2..4].join # if same fence then cmd_end == inner_end if is_commentout inner.gsub!(/(^\/\/(\w+(\[#{@r_option_inner}\]|))*#{inner_open})/) { line = $1 = ReViewDef::(line) s = "" s += "「#{}」\n\n" unless .blank? s += "#@##{line}" s } rep = "#{cmd_begin}#{inner}#@##{cmd_end}" content.gsub!(matched) { |mm| rep } else imb = inner.match(/(\R((^\/\/\w+(\[#{@r_option_inner}\])*)\s*)*^\/\/#{inner_cmd}#{id_opt}(\[#{@r_option_inner}\])*#{inner_open}.*)\R/m) to_out_block = imb[1] inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '') rep = "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}" content.gsub!(matched) { |mm| rep } end else close = ReViewDef::fence_close(inner_open) if is_commentout inner.gsub!(/(^\/\/(\w+(\[#{@r_option_inner}\]|))*#{inner_open})(.*?)(^\/\/#{close})/m) { first = $1 body = $2 last = $3 = ReViewDef::(first) s = "" s += "「#{}」\n\n" unless .blank? s += "#@##{first}#{body}@##{last}" s } rep = "#{cmd_begin}#{inner}#{cmd_end}" content.gsub!(matched) { |mm| rep } else imb = inner.match(/\R((^\/\/\w+(\[#{@r_option_inner}\])*)\s*)*^\/\/(#{inner_cmd})#{id_opt}(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)))/m) to_out_block = imb[0] inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '') rep = "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}" content.gsub!(matched) { |mm| rep } end end found = true end } if found replace_block_command_nested_boxed_article_i(content, box, depth+1) end end |
#replace_block_command_nested_boxed_articles(content) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/review/retrovert/converter.rb', line 325 def replace_block_command_nested_boxed_articles(content) unless ReViewCompat::has_nested_minicolumn() replace_block_command_nested_boxed_article(content, 'note') replace_block_command_nested_boxed_article(content, 'memo') replace_block_command_nested_boxed_article(content, 'tip') replace_block_command_nested_boxed_article(content, 'info') replace_block_command_nested_boxed_article(content, 'warning') replace_block_command_nested_boxed_article(content, 'important') replace_block_command_nested_boxed_article(content, 'caution') replace_block_command_nested_boxed_article(content, 'notice') end end |
#replace_block_command_outline(content, command, new_command, use_option) ⇒ Object
223 224 225 226 227 228 229 |
# File 'lib/review/retrovert/converter.rb', line 223 def replace_block_command_outline(content, command, new_command, use_option) if use_option content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}") else content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}") end end |
#replace_block_commentout(content) ⇒ Object
#@+++ ~ #@— to #@#+++ #@#~ #@#—
339 340 341 342 343 344 345 346 347 348 |
# File 'lib/review/retrovert/converter.rb', line 339 def replace_block_commentout(content) d = content.dup d.scan(/(^#@)(\++\R)(.*?)(^#@)(-+)/m) { |m| matched = m[0..-1].join inner = m[2] inner.gsub!(/^/, '#@#') rep = "#@##{m[1]}#{inner}#@##{m[4]}" content.gsub!(matched) { |mm| rep } } end |
#replace_block_commentout_without_sampleout(content) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/review/retrovert/converter.rb', line 350 def replace_block_commentout_without_sampleout(content) d = content.dup d.gsub!(/(^\/\/sampleoutputbegin\[)(.*?)(\])(.*?)(^\/\/sampleoutputend)/m, '') d.scan(/(^#@)(\++\R)(.*?)(^#@)(-+)/m) { |m| matched = m[0..-1].join inner = m[2] inner.gsub!(/^/, '#@#\1') rep = "#@##{m[1]}#{inner}#@##{m[4]}" content.gsub!(matched) { |mm| rep } } end |
#replace_compatible_block_command_outline(content, command, new_command, option_count, begin_option_pos = 0) ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/review/retrovert/converter.rb', line 194 def replace_compatible_block_command_outline(content, command, new_command, option_count, begin_option_pos=0) content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\]){0,#{begin_option_pos}}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}") content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\]){0,#{begin_option_pos}}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*$/, "//#{new_command}\\k<option>") # if begin_option_pos > 0 # content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\]){0,#{begin_option_pos}}{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}") # content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\]){0,#{begin_option_pos}}$/, "//#{new_command}") # end end |
#replace_compatible_block_command_to_outside(content, command, new_command, option_count, add_options = "", new_body = "") ⇒ Object
217 218 219 220 221 |
# File 'lib/review/retrovert/converter.rb', line 217 def replace_compatible_block_command_to_outside(content, command, new_command, option_count, ="", new_body="") body = new_body body += '\n' unless body.empty? content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>#{}{\n#{new_body}//}\\k<inner>") end |
#replace_file_option(content, matched, fence_open, option) ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/review/retrovert/converter.rb', line 475 def replace_file_option(content, matched, fence_open, option) file_param_m = option.match(/\s*file\s*=\s*([^,\]]*)/) if file_param_m fence_close = ReViewDef::fence_close(fence_open) filepath = file_param_m[1] if fence_close content.gsub!(/#{Regexp.escape(matched)}(.*?)^\/\/#{fence_close}/m) { "#{matched}\n\#@mapfile(#{filepath})\n\#@end\n//#{fence_close}" } end end end |
#replace_inline_command(content, command, new_command) ⇒ Object
662 663 664 665 666 |
# File 'lib/review/retrovert/converter.rb', line 662 def replace_inline_command(content, command, new_command) do_replace_inline_command(content, command) { |open, inner, close| "@<#{new_command}>#{open}#{inner}#{close}" } end |
#replace_sampleoutput(content) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/review/retrovert/converter.rb', line 362 def replace_sampleoutput(content) # replace_block_commentout_without_sampleout(content) content.dup.scan(/(^\/\/sampleoutputbegin\[)(.*?)(\].*?\R)(.*?)(^\/\/sampleoutputend)/m) { |m| matched = m[0..-1].join sampleoutputbegin = m[0..2].join sampleoutputend = m[4] option = m[1] inner = m[3] # inner.gsub!(/^\/\//, '//@<nop>{}') rep = "#{option}\n#@##{sampleoutputbegin}#{inner}#@##{sampleoutputend}" content.gsub!(matched) { |mm| rep } } end |
#replace_starter_command(content) ⇒ Object
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/review/retrovert/converter.rb', line 608 def replace_starter_command(content) replace_compatible_block_command_outline(content, 'program', 'list', 2) replace_compatible_block_command_outline(content, 'terminal', 'cmd', 1, 1) replace_compatible_block_command_outline(content, 'output', 'list', 3) replace_compatible_block_command_to_outside(content, 'sideimage', 'image', 1, '[]') replace_block_command_outline(content, 'abstract', 'lead', true) delete_block_command(content, 'makechaptitlepage') delete_block_command(content, 'vspace') delete_block_command(content, 'needvspace') delete_block_command(content, 'clearpage') delete_block_command(content, 'flushright') delete_block_command(content, 'paragraphend') delete_block_command_outer(content, 'centering') # convert starter option convert_starter_option(content) # delete starter option # exclude_exta_option(content, 'cmd', 0) (content, 'cmd', 1) (content, [ 'imgtable', 'table', # list/listnum の第3引数は言語指定だが、Starter の第3引数と全く異なるため 2 引数にしている # Starter 側が言語指定対応したら修正 'list', 'listnum', ], 2) # exclude_exta_option(content, 'tsize', 1) replace_tsize(content) # delete IRD unsupported commands if @ird delete_block_command(content, 'noindent') end # chapterauthor content.gsub!(/^\/\/chapterauthor\[(.*?)\]/, "//lead{\n\\1\n//}") # talklist/desclist starter_list_to_nested_contents_list(content) # empty caption imaget to indepimage content.gsub!(/^\/\/image(\[#{@r_option_inner}\]\[\].*)$/, '//indepimage\1') end |
#replace_starter_inline_command(content) ⇒ Object
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
# File 'lib/review/retrovert/converter.rb', line 721 def replace_starter_inline_command(content) (content) replace_inline_command(content, 'secref', 'hd') replace_inline_command(content, 'file', 'kw') replace_inline_command(content, 'hlink', 'href') replace_inline_command(content, 'B', 'strong') replace_inline_command(content, 'W', 'wb') replace_inline_command(content, 'term', 'idx') replace_inline_command(content, 'termnoidx', 'hidx') unless ReViewCompat::has_bou() replace_inline_command(content, 'bou', 'b') end delete_inline_command(content, 'userinput') delete_inline_command(content, 'weak') delete_inline_command(content, 'cursor') delete_inline_command(content, 'foldhere') # font size delete_inline_command(content, 'small') delete_inline_command(content, 'xsmall') delete_inline_command(content, 'xxsmall') delete_inline_command(content, 'large') delete_inline_command(content, 'xlarge') delete_inline_command(content, 'xxlarge') do_replace_inline_command(content, 'par') { |open, inner, close| "@<br>#{open}#{close}" } do_replace_inline_command(content, 'qq' ) { |open, inner, close| "\"#{inner}\"" } end |
#replace_tsize(content) ⇒ Object
553 554 555 556 557 558 559 |
# File 'lib/review/retrovert/converter.rb', line 553 def replace_tsize(content) content.gsub!(/^\/\/tsize\[(.*?)\]\[(.*?)\]/) { builder = $1 builder = "" if $1 == '*' "//tsize[|#{builder}|#{$2}]" } end |
#restore_out_image(outpath, tmpdir) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/review/retrovert/converter.rb', line 79 def restore_out_image(outpath, tmpdir) if File.exist?(tmpdir) FileUtils.mkdir_p(outpath) FileUtils.mv(Dir.glob(File.join(tmpdir, "**/*")), outpath) FileUtils.rm_rf(tmpdir) end end |
#starter_caption_to_text(content, command, n) ⇒ Object
213 214 215 |
# File 'lib/review/retrovert/converter.rb', line 213 def (content, command, n) content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{n-1}})\[(?<caption>#{@r_option_inner})\](?<post>.*)$/, "\\k<caption>\n//#{command}\\k<option>\\k<post>") end |
#starter_list_to_nested_contents_list(content) ⇒ Object
467 468 469 470 471 472 473 |
# File 'lib/review/retrovert/converter.rb', line 467 def starter_list_to_nested_contents_list(content) # talklist talklist_to_nested_contents_list(content, @talklist_replace_cmd) # desclist desclist_to_nested_contents_list(content, @desclist_replace_cmd) replace_block_command_nested_boxed_article(content, 'emlist') end |
#store_out_image(outdir) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/review/retrovert/converter.rb', line 69 def store_out_image(outdir) outpath = get_out_imagedir(outdir) if File.exist?(outpath) dir = Dir.mktmpdir('review-retrovert') FileUtils.mv(Dir.glob(File.join(outpath, "**/*")), dir) return dir end return nil end |
#talklist_to_nested_contents_list(content, cmd) ⇒ Object
talklist to //#cmd[]{ //emlist[]{}… }
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/review/retrovert/converter.rb', line 435 def talklist_to_nested_contents_list(content, cmd) content.gsub!(/^\/\/talklist(.*?){/, "//#{cmd}\\1{") content.gsub!(/^\/\/talk(?<options>\[#{@r_option_inner}\]\[#{@r_option_inner}\])\[(?<body>#{@r_option_inner})\]$/, "//talk\\k<options>{\n\\k<body>\n//}") content.gsub!(/^\/\/t(?<options>\[#{@r_option_inner}\])\[(?<body>#{@r_option_inner})\]$/, "//talk\\k<options>{\n\\k<body>\n//}") content.gsub!(/^\/\/(t|talk)((\[#{@r_option_inner}\])*){/) { |s| m = s.scan(/(\[(#{@r_option_inner})\])/) # 1st option is image id avatar = m[0][1] first_option = m[0][0] = m[1..-1].map{ |x| x[0] }.join if avatar.length > 0 kv = @talk_shortcuts[avatar] if kv&.key?('image') "//indepimage[#{kv['image']}][][scale=#{@talk_icon_scale}]{\n//}\n//emlist[]#{}{" elsif kv&.key?('name') "//emlist[#{kv['name']}]{" else "//indepimage#{first_option}[][scale=#{@talk_icon_scale}]{\n//}\n//emlist[]#{}{" end else "//emlist#{}{" end } end |
#update_config(outdir) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/review/retrovert/converter.rb', line 121 def update_config(outdir) @configs.rewrite_yml('contentdir', '.') @configs.rewrite_yml('hook_beforetexcompile', 'null') @configs.rewrite_yml('texstyle', '["reviewmacro"]') # words words_files = @config['words_file'] if words_files if words_files.is_a?(Array) new_words_files = [] words_files.each do |words_file| new_words_files.push copy_wards(outdir, words_file) end @configs.rewrite_yml('words_file', "[#{new_words_files.join(',')}]") else new_words_file = copy_wards(outdir, words_files) @configs.rewrite_yml('words_file', new_words_file) end end # makeindex_dic makeindex_dic = @config['pdfmaker']['makeindex_dic'] if makeindex_dic FileUtils.copy(File.join(@basedir, makeindex_dic), File.join(outdir, makeindex_dic)) end # texdocumentclass pagesize = @config['starter']['pagesize'].downcase book_configs = [ "media=print", "paper=#{pagesize}" ] texdocumentclass = @config['texdocumentclass'] book_style = texdocumentclass[0] if book_style == "jsbook" book_style = "review-jsbook" elsif book_style == "utbook" book_style = "review-utbook" FileUtils.cp(File.join(__dir__, 'sty/review-utbook.cls'), File.join(outdir, 'sty/review-utbook.cls')) end origin_book_configs = texdocumentclass[1].split(',') book_configs.concat origin_book_configs.select { |c| !ReViewDef::review_jsbook_invalid_configs().include?(c) } if @ird # # リュウミン Pr6N R-KL 12.5Q 22H (9pt = 12.7Q 15.5pt = 21.8Q(H)) # texdocumentclass: ["review-jsbook", "media=ebook,openany,paper=b5,fontsize=9pt,baselineskip=15.5pt,head_space=15mm,gutter=22mm,footskip=16mm,line_length=45zw,number_of_lines=38"] book_config = [ "media=ebook", "openany", "paper=b5", "fontsize=9pt", "baselineskip=15.5pt", "head_space=15mm", "gutter=22mm", "footskip=16mm", "line_length=45zw", "number_of_lines=38" ] end @configs.rewrite_yml_array('texdocumentclass', "[\"#{book_style}\", \"#{book_configs.join(',')}\"]") if @config.key?('retrovert') @config['retrovert'].each{ |k,v| unless v..is_a?(Hash) @configs.commentout_root_yml(k) end } end if @ird @configs.rewrite_yml('chapterlink', 'null') end end |
#update_content(outdir, contentfile) ⇒ Object
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
# File 'lib/review/retrovert/converter.rb', line 750 def update_content(outdir, contentfile) info contentfile filename = File.basename(contentfile, '.*') content = File.read(contentfile) content.gsub!(/@<href>{(.*?)#.*?,(.*?)}/, '@<href>{\1,\2}') content.gsub!(/@<href>{(.*?)#.*?}/, '@<href>{\1}') linkurl_footnote = @config['starter']['linkurl_footnote'] # noop を最後に消すためにダミーに変える content.gsub!('@<nop>$$', '@<dummynop>$must_be_replace_nop$') content.gsub!('@<nop>||', '@<dummynop>|must_be_replace_nop|') content.gsub!('@<nop>{}', '@<dummynop>{must_be_replace_nop}') # Re:VIEW Starter commands replace_starter_command(content) # fixed lack of options content.gsub!(/^\/\/list{/, '//list[][]{') # empty br line to blankline content.gsub!(/^\s*@<br>{}\s*$/, '//blankline') unless ReViewCompat::() # empty caption is not allow content.gsub!(/^\/\/image\[(.*)\]\[\]{/, '//image[\1][ ]{') end # special command replace_sampleoutput(content) if linkurl_footnote add_linkurl_footnote(content, filename) end # nested command replace_block_command_nested_boxed_articles(content) # empty ids replace_auto_ids(content, 'table', 2) replace_auto_ids(content, 'list', 2) replace_auto_ids(content, 'listnum', 2) # remove starter extension remove_starter_refid(content) (content) # replace block comment replace_block_commentout(content) # special charactor content.gsub!('@<LaTeX>{}', 'LaTeX') content.gsub!('@<TeX>{}', 'TeX') content.gsub!('@<hearts>{}', '!HEART!') replace_starter_inline_command(content) # fix deprecated fix_deprecated_list(content) if @ird # br to blankline content.gsub!(/(^\/\/footnote\[.*?\]\[.*?)((.*?@<br>({}|\$\$|\|\|)){1,})(.*\])$/) { |m| m.gsub(/@<br>({}|\$\$|\|\|)/, '@<fnbr>\1') } content.gsub!(/(\/\/table.*?{.*?\/\/})/m) { |m| # table 内の @ コマンドは不安定らしい m.gsub!('@<br>{}', "#{Regexp.escape(@table_br_replace)}") # 空セルが2行になることがあるらしい m.gsub!(/(\s)\.(\s)/, "\\1#{Regexp.escape(@table_empty_replace)}\\2") m } content.gsub!(/(.*)@<br>({}|\$\$|\|\|)$/, "\\1\n\n") content.gsub!(/(.*)@<br>({}|\$\$|\|\|)(.*)$/, "\\1\n\n\\2") content.gsub!('@<fnbr>{}', '@<br>{}') content.gsub!('@<fnbr>$$', '@<br>$$') content.gsub!('@<fnbr>||', '@<br>||') end # nop replace must be last step # content.gsub!('@<dumynop>$must_be_replace_nop$', '@<b>$$') # content.gsub!('@<dumynop>|must_be_replace_nop|', '@<b>||') content.gsub!('@<dummynop>$must_be_replace_nop$', '@<b>{}') content.gsub!('@<dummynop>|must_be_replace_nop|', '@<b>{}') content.gsub!('@<dummynop>{must_be_replace_nop}', '@<b>{}') File.write(contentfile, content) (outdir, content) end |
#update_content_files(outdir, contentdir, contentfiles) ⇒ Object
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'lib/review/retrovert/converter.rb', line 840 def update_content_files(outdir, contentdir, contentfiles) files = contentfiles.is_a?(String) ? contentfiles.split(/\R/) : contentfiles files.each do |content| contentpath = File.join(contentdir, content) srccontentpath = File.join(@srccontentsdir, content) if @embeded_contents.include?(srccontentpath) info "skip copy maped file #{contentpath}" next end unless File.exist?(contentpath) srcpath = File.join(@basedir, srccontentpath) # info srcpath if File.exist?(srcpath) FileUtils.cp(srcpath, contentdir) end end update_content(outdir, contentpath) end end |
#update_contents(outdir, options) ⇒ Object
860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
# File 'lib/review/retrovert/converter.rb', line 860 def update_contents(outdir, ) yamlfile = @config['catalogfile'] abspath = File.absolute_path(outdir) contentdir = abspath info 'replace starter block command' info 'replace starter inline command' catalog = ReViewCompat::Catalog(File.join(abspath, yamlfile)) update_content_files(outdir, contentdir, @catalog_contents) unless ['strict'] all_contentsfiles = Pathname.glob(File.join(File.join(@basedir, @srccontentsdir), '*.re')).map(&:basename) contentsfiles = all_contentsfiles.select{ |path| ! @catalog_contents.include?(path.to_s) } update_content_files(outdir, contentdir, contentsfiles) end end |
#update_ext(outdir, options) ⇒ Object
926 927 928 929 930 |
# File 'lib/review/retrovert/converter.rb', line 926 def update_ext(outdir, ) if @ird FileUtils.cp(File.join(__dir__, 'ext/review-ext.rb'), File.join(outdir, 'review-ext.rb')) end end |
#update_sty(outdir, options) ⇒ Object
916 917 918 919 920 921 922 923 924 |
# File 'lib/review/retrovert/converter.rb', line 916 def update_sty(outdir, ) review_custom_sty = File.open(File.join(outdir, 'sty/review-custom.sty'), 'a') erb_sty(outdir, 'review-retrovert-custom.sty') review_custom_sty.puts('\RequirePackage{review-retrovert-custom}') if @ird erb_sty(outdir, 'ird.sty') review_custom_sty.puts('\RequirePackage{ird}') end end |
#warn(msg) ⇒ Object
37 38 39 |
# File 'lib/review/retrovert/converter.rb', line 37 def warn(msg) @logger.warn msg end |