From b8f682f1e591c3bea587cc5a3d70d492de504f6c Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 24 Nov 2015 00:57:59 +0900 Subject: [PATCH] fix caption of //list, //listnum --- lib/review/latexbuilder.rb | 47 +++++++++++++++++++------------------- test/test_latexbuilder.rb | 2 +- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 4e021f657..c06711105 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -238,9 +238,9 @@ def highlight_listings? def emlist(lines, caption = nil, lang = nil) blank if highlight_listings? - common_code_block_lst(lines, 'reviewemlistlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang) else - common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx| detab(line) + "\n" end end @@ -249,9 +249,9 @@ def emlist(lines, caption = nil, lang = nil) def emlistnum(lines, caption = nil, lang = nil) blank if highlight_listings? - common_code_block_lst(lines, 'reviewemlistnumlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang) else - common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx| detab((idx+1).to_s.rjust(2)+": " + line) + "\n" end end @@ -260,14 +260,9 @@ def emlistnum(lines, caption = nil, lang = nil) ## override Builder#list def list(lines, id, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistlst', 'caption', caption, lang) + common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang) else - begin - puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}") - rescue KeyError - error "no such list: #{id}" - end - common_code_block(lines, 'reviewlist', nil, lang) do |line, idx| + common_code_block(id, lines, 'reviewlist', nil, lang) do |line, idx| detab(line) + "\n" end end @@ -276,14 +271,9 @@ def list(lines, id, caption, lang = nil) ## override Builder#listnum def listnum(lines, id, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistnumlst', 'caption', caption, lang) + common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang) else - begin - puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}") - rescue KeyError - error "no such list: #{id}" - end - common_code_block(lines, 'reviewlist', caption, lang) do |line, idx| + common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx| detab((idx+1).to_s.rjust(2)+": " + line) + "\n" end end @@ -291,18 +281,27 @@ def listnum(lines, id, caption, lang = nil) def cmd(lines, caption = nil, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewcmdlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang) else blank - common_code_block(lines, 'reviewcmd', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx| detab(line) + "\n" end end end - def common_code_block(lines, command, caption, lang) + def common_code_block(id, lines, command, caption, lang) + buf = "" if caption - puts macro(command + 'caption', "#{compile_inline(caption)}") + if command =~ /emlist/ || command =~ /cmd/ + puts macro(command + 'caption', "#{compile_inline(caption)}") + else + begin + puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}") + rescue KeyError + error "no such list: #{id}" + end + end end body = "" lines.each_with_index do |line, idx| @@ -314,7 +313,7 @@ def common_code_block(lines, command, caption, lang) blank end - def common_code_block_lst(lines, command, title, caption, lang) + def common_code_block_lst(id, lines, command, title, caption, lang) caption_str = compile_inline((caption || "")) if title == "title" && caption_str == "" caption_str = "\\relax" ## dummy charactor to remove lstname @@ -335,7 +334,7 @@ def common_code_block_lst(lines, command, title, caption, lang) def source(lines, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewlistlst', 'title', caption, lang) else puts '\begin{reviewlist}' puts macro('reviewlistcaption', compile_inline(caption)) diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index c0158c7da..481f37afb 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -279,7 +279,7 @@ def test_emlist_with_tab4 def test_listnum actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") - assert_equal %Q|\\reviewlistcaption{リスト1.1: ruby}\n\\reviewlistcaption{ruby}\n\\begin{reviewlist}\n 1: class Foo\n 2: def foo\n 3: bar\n 4: \n 5: buz\n 6: end\n 7: end\n\\end{reviewlist}\n|, actual + assert_equal %Q|\\reviewlistcaption{リスト1.1: ruby}\n\\begin{reviewlist}\n 1: class Foo\n 2: def foo\n 3: bar\n 4: \n 5: buz\n 6: end\n 7: end\n\\end{reviewlist}\n|, actual end def test_listnum_lst