Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix caption of //list, //listnum #468

Merged
merged 1 commit into from
Nov 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def highlight_listings?
def emlist(lines, caption = nil, lang = nil)
buf = "\n"
if highlight_listings?
buf << common_code_block_lst(lines, 'reviewemlistlst', 'title', caption, lang)
buf << common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
else
buf << common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx|
buf << common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
detab(line) + "\n"
end
end
Expand All @@ -242,9 +242,9 @@ def emlist(lines, caption = nil, lang = nil)
def emlistnum(lines, caption = nil, lang = nil)
buf = "\n"
if highlight_listings?
buf << common_code_block_lst(lines, 'reviewemlistnumlst', 'title', caption, lang)
buf << common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang)
else
buf << common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx|
buf << common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
end
end
Expand All @@ -255,15 +255,9 @@ def emlistnum(lines, caption = nil, lang = nil)
def list(lines, id, caption = nil, lang = nil)
buf = ""
if highlight_listings?
buf << common_code_block_lst(lines, 'reviewlistlst', 'caption', caption, lang)
buf << common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
else
begin
buf << "\n"
buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
rescue KeyError
error "no such list: #{id}"
end
buf << common_code_block(lines, 'reviewlist', nil, lang) do |line, idx|
buf << common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
detab(line) + "\n"
end
end
Expand All @@ -275,15 +269,9 @@ def list(lines, id, caption = nil, lang = nil)
def listnum(lines, id, caption = nil, lang = nil)
buf = ""
if highlight_listings?
buf << common_code_block_lst(lines, 'reviewlistnumlst', 'caption', caption, lang)
buf << common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang)
else
begin
buf << "\n"
buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
rescue KeyError
error "no such list: #{id}"
end
buf << common_code_block(lines, 'reviewlist', caption, lang) do |line, idx|
buf << common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
end
end
Expand All @@ -293,20 +281,29 @@ def listnum(lines, id, caption = nil, lang = nil)
def cmd(lines, caption = nil, lang = nil)
buf = ""
if highlight_listings?
buf << common_code_block_lst(lines, 'reviewcmdlst', 'title', caption, lang)
buf << common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
else
buf << "\n"
buf << common_code_block(lines, 'reviewcmd', caption, lang) do |line, idx|
buf << common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx|
detab(line) + "\n"
end
end
buf
end

def common_code_block(lines, command, caption, lang)
def common_code_block(id, lines, command, caption, lang)
buf = ""
if caption
buf << macro(command + 'caption', "#{caption}") + "\n"
if command =~ /emlist/ || command =~ /cmd/
buf << macro(command + 'caption', "#{caption}") + "\n"
else
begin
buf << "\n"
buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
rescue KeyError
error "no such list: #{id}"
end
end
end
body = ""
lines.each_with_index do |line, idx|
Expand All @@ -318,7 +315,7 @@ def common_code_block(lines, command, caption, lang)
buf
end

def common_code_block_lst(lines, command, title, caption, lang)
def common_code_block_lst(id, lines, command, title, caption, lang)
buf = ""
caption_str = (caption || "")
if title == "title" && caption_str == ""
Expand All @@ -340,7 +337,7 @@ def common_code_block_lst(lines, command, title, caption, lang)

def source(lines, caption = nil, 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
buf = "\n"
buf << '\begin{reviewlist}' << "\n"
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|\n\\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|\n\\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