From 163ebbe0e26295d17b3b43b6eba58cc4f69aa12f Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 31 Dec 2016 09:21:36 +0900 Subject: [PATCH 1/2] unify the behavior of //comment and @ at each builders. ref #360 --- lib/review/htmlbuilder.rb | 7 ++----- lib/review/idgxmlbuilder.rb | 17 +++++++++++++++-- lib/review/latexbuilder.rb | 2 +- lib/review/markdownbuilder.rb | 16 ++++++++++++++++ lib/review/md2inaobuilder.rb | 9 --------- lib/review/topbuilder.rb | 12 +++++++----- 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 3b713645a..2b47bba14 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -762,10 +762,7 @@ def comment(lines, comment = nil) lines.unshift comment unless comment.blank? if @book.config["draft"] str = lines.join("
") - puts %Q(
#{str}
) - else - str = lines.join("\n") - puts %Q() + puts %Q(
#{escape_html(str)}
) end end @@ -1165,7 +1162,7 @@ def inline_comment(str) if @book.config["draft"] %Q(#{escape_html(str)}) else - %Q() + "" end end diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index e65510fdd..b259eaa55 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -630,8 +630,21 @@ def imgtable(lines, id, caption = nil, metric = nil) end end - def comment(str) - print %Q() + def comment(lines, comment = nil) + if @book.config["draft"] + lines ||= [] + lines.unshift comment unless comment.blank? + str = lines.join("\n") + print "#{escape_html(str)}" + end + end + + def inline_comment(str) + if @book.config["draft"] + %Q(#{escape_html(str)}) + else + '' + end end def footnote(id, str) diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 9bccc0bf1..b108a0692 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -644,7 +644,7 @@ def comment(lines, comment = nil) lines ||= [] lines.unshift comment unless comment.blank? if @book.config["draft"] - str = lines.join("") + str = lines.join('\par ') puts macro('pdfcomment', escape(str)) end end diff --git a/lib/review/markdownbuilder.rb b/lib/review/markdownbuilder.rb index 0be8399b7..5a81c9ed7 100644 --- a/lib/review/markdownbuilder.rb +++ b/lib/review/markdownbuilder.rb @@ -301,6 +301,22 @@ def compile_ruby(base, ruby) end end + def comment(lines, comment = nil) + if @book.config["draft"] + lines ||= [] + lines.unshift comment unless comment.blank? + str = lines.join("
") + puts %Q(
#{escape_html(str)}
) + end + end + + def inline_comment(str) + if @book.config["draft"] + %Q(#{escape_html(str)}) + else + '' + end + end end end # module ReVIEW diff --git a/lib/review/md2inaobuilder.rb b/lib/review/md2inaobuilder.rb index 4dc290abf..e7edb9e5a 100644 --- a/lib/review/md2inaobuilder.rb +++ b/lib/review/md2inaobuilder.rb @@ -44,15 +44,6 @@ def dl_end puts '' end - def comment(lines, comment = nil) - lines ||= [] - lines.unshift comment unless comment.blank? - str = lines.join("\n") - puts '' - puts str - puts '' - end - def compile_ruby(base, ruby) if base.length == 1 %Q[#{escape_html(base)}(#{escape_html(ruby)})] diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index 805281377..25bb816b1 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -381,10 +381,12 @@ def table_end end def comment(lines, comment = nil) - lines ||= [] - lines.unshift comment unless comment.blank? - str = lines.join("") - puts "◆→DTP連絡:#{str}←◆" + if @book.config["draft"] + lines ||= [] + lines.unshift comment unless comment.blank? + str = lines.join("") + puts "◆→#{str}←◆" + end end def footnote(id, str) @@ -501,7 +503,7 @@ def inline_uchar(str) def inline_comment(str) if @book.config["draft"] - %Q[◆→DTP連絡:#{str}←◆] + "◆→#{str}←◆" else "" end From 1246da30051579f154af460fb21783164d6adc71 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 31 Dec 2016 14:08:52 +0900 Subject: [PATCH 2/2] tests for comments --- test/test_htmlbuilder.rb | 21 +++++++++++++++++++++ test/test_idgxmlbuilder.rb | 21 +++++++++++++++++++++ test/test_latexbuilder.rb | 21 +++++++++++++++++++++ test/test_markdownbuilder.rb | 23 ++++++++++++++++++++++- test/test_md2inaobuilder.rb | 5 ----- test/test_topbuilder.rb | 13 ++++++++++++- 6 files changed, 97 insertions(+), 7 deletions(-) diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index de3e0c6ea..7df6b16d3 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -1464,4 +1464,25 @@ def test_major_blocks assert_equal expected, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|
コメント
\n|, actual + end + + def test_inline_comment + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test test2|, actual + end + + def test_inline_comment_for_draft + @config["draft"] = true + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test コメント test2|, actual + end end diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index 65298435d..48714c537 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -676,4 +676,25 @@ def test_block_raw4 assert_equal expected.chomp, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|コメント|, actual + end + + def test_inline_comment + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test test2|, actual + end + + def test_inline_comment_for_draft + @config["draft"] = true + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test コメント test2|, actual + end end diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index b296ee58b..7384d7de8 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -873,4 +873,25 @@ def test_block_raw4 assert_equal expected, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|\\pdfcomment{コメント}\n|, actual + end + + def test_inline_comment + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test test2|, actual + end + + def test_inline_comment_for_draft + @config["draft"] = true + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test \\pdfcomment{コメント} test2|, actual + end end diff --git a/test/test_markdownbuilder.rb b/test/test_markdownbuilder.rb index ba06a2ebc..9226f7065 100644 --- a/test/test_markdownbuilder.rb +++ b/test/test_markdownbuilder.rb @@ -46,6 +46,17 @@ def test_ul assert_equal expected, actual end + def test_inline_comment + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test test2|, actual + end + + def test_inline_comment_for_draft + @config["draft"] = true + actual = compile_inline("test @{コメント} test2") + assert_equal %Q|test コメント test2|, actual + end + def test_ul_nest1 src =<<-EOS * AAA @@ -62,7 +73,6 @@ def test_cmd assert_equal "```shell-session\nlineA\nlineB\n```\n", actual end - def test_dlist actual = compile_block(": foo\n foo.\n bar.\n") assert_equal %Q|
\n
foo
\n
foo.bar.
\n
\n|, actual @@ -79,6 +89,17 @@ def test_dlist_with_comment assert_equal %Q|
\n
title
\n
body
\n
title2
\n
body2
\n
\n|, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|
コメント
\n|, actual + end + def test_list actual = compile_block(<<-EOS) //list[name][caption]{ diff --git a/test/test_md2inaobuilder.rb b/test/test_md2inaobuilder.rb index 1ee2b3cf5..4f94a6a76 100644 --- a/test/test_md2inaobuilder.rb +++ b/test/test_md2inaobuilder.rb @@ -57,11 +57,6 @@ def test_list EOS end - def test_comment - actual = compile_block("//comment{\nHello, world!\n//}\n") - assert_equal "\nHello, world!\n\n", actual - end - def test_ruby_mono actual = compile_block("@{謳,うた}い文句") assert_equal " 謳(うた)い文句\n\n", actual diff --git a/test/test_topbuilder.rb b/test/test_topbuilder.rb index 20a1e56cd..1b37a42d8 100644 --- a/test/test_topbuilder.rb +++ b/test/test_topbuilder.rb @@ -142,7 +142,7 @@ def test_inline_comment def test_inline_comment_for_draft @config["draft"] = true actual = compile_inline("test @{コメント} test2") - assert_equal %Q|test ◆→DTP連絡:コメント←◆ test2|, actual + assert_equal %Q|test ◆→コメント←◆ test2|, actual end def test_inline_in_table @@ -170,6 +170,17 @@ def test_noindent assert_equal %Q|◆→DTP連絡:次の1行インデントなし←◆\nfoobar\nfoo2bar2\n|, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|◆→コメント←◆\n|, actual + end + def test_list def @chapter.list(id) Book::ListIndex::Item.new("test",1)