Skip to content

Commit

Permalink
fix caption of //list, //listnum
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Nov 23, 2015
1 parent 23339f6 commit b8f682f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
47 changes: 23 additions & 24 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -276,33 +271,37 @@ 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
end

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|
Expand All @@ -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
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8f682f

Please sign in to comment.