Skip to content

Commit

Permalink
Merge pull request #717 from kmuto/draftmode
Browse files Browse the repository at this point in the history
ドラフトコメントのサポート
  • Loading branch information
kmuto authored Jan 5, 2017
2 parents b633e21 + 1246da3 commit d60ee54
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 29 deletions.
7 changes: 2 additions & 5 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,7 @@ def comment(lines, comment = nil)
lines.unshift comment unless comment.blank?
if @book.config["draft"]
str = lines.join("<br />")
puts %Q(<div class="draft-comment">#{str}</div>)
else
str = lines.join("\n")
puts %Q(<!-- #{escape_comment(str)} -->)
puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
end
end

Expand Down Expand Up @@ -1162,7 +1159,7 @@ def inline_comment(str)
if @book.config["draft"]
%Q(<span class="draft-comment">#{escape_html(str)}</span>)
else
%Q(<!-- #{escape_comment(escape_html(str))} -->)
""
end
end

Expand Down
17 changes: 15 additions & 2 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,21 @@ def imgtable(lines, id, caption = nil, metric = nil)
end
end

def comment(str)
print %Q(<!-- [Comment] #{escape_html(str)} -->)
def comment(lines, comment = nil)
if @book.config["draft"]
lines ||= []
lines.unshift comment unless comment.blank?
str = lines.join("\n")
print "<msg>#{escape_html(str)}</msg>"
end
end

def inline_comment(str)
if @book.config["draft"]
%Q(<msg>#{escape_html(str)}</msg>)
else
''
end
end

def footnote(id, str)
Expand Down
2 changes: 1 addition & 1 deletion lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,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
Expand Down
16 changes: 16 additions & 0 deletions lib/review/markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<br />")
puts %Q(<div class="red">#{escape_html(str)}</div>)
end
end

def inline_comment(str)
if @book.config["draft"]
%Q(<span class="red">#{escape_html(str)}</span>)
else
''
end
end
end

end # module ReVIEW
9 changes: 0 additions & 9 deletions lib/review/md2inaobuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ def dl_end
puts '</dl>'
end

def comment(lines, comment = nil)
lines ||= []
lines.unshift comment unless comment.blank?
str = lines.join("\n")
puts '<span class="red">'
puts str
puts '</span>'
end

def compile_ruby(base, ruby)
if base.length == 1
%Q[<span class='monoruby'>#{escape_html(base)}(#{escape_html(ruby)})</span>]
Expand Down
12 changes: 7 additions & 5 deletions lib/review/topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -501,7 +503,7 @@ def inline_uchar(str)

def inline_comment(str)
if @book.config["draft"]
%Q[◆→DTP連絡:#{str}←◆]
"◆→#{str}←◆"
else
""
end
Expand Down
21 changes: 21 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|<div class="draft-comment">コメント</div>\n|, actual
end

def test_inline_comment
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test test2|, actual
end

def test_inline_comment_for_draft
@config["draft"] = true
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test <span class="draft-comment">コメント</span> test2|, actual
end
end
21 changes: 21 additions & 0 deletions test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,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|<msg>コメント</msg>|, actual
end

def test_inline_comment
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test test2|, actual
end

def test_inline_comment_for_draft
@config["draft"] = true
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test <msg>コメント</msg> test2|, actual
end
end
21 changes: 21 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -890,4 +890,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 @<comment>{コメント} test2")
assert_equal %Q|test test2|, actual
end

def test_inline_comment_for_draft
@config["draft"] = true
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test \\pdfcomment{コメント} test2|, actual
end
end
23 changes: 22 additions & 1 deletion test/test_markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def test_ul
assert_equal expected, actual
end

def test_inline_comment
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test test2|, actual
end

def test_inline_comment_for_draft
@config["draft"] = true
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test <span class="red">コメント</span> test2|, actual
end

def test_ul_nest1
src =<<-EOS
* AAA
Expand All @@ -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|<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
Expand All @@ -79,6 +89,17 @@ def test_dlist_with_comment
assert_equal %Q|<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\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|<div class="red">コメント</div>\n|, actual
end

def test_list
actual = compile_block(<<-EOS)
//list[name][caption]{
Expand Down
5 changes: 0 additions & 5 deletions test/test_md2inaobuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def test_list
EOS
end

def test_comment
actual = compile_block("//comment{\nHello, world!\n//}\n")
assert_equal "<span class=\"red\">\nHello, world!\n</span>\n", actual
end

def test_ruby_mono
actual = compile_block("@<ruby>{謳,うた}い文句")
assert_equal " <span class='monoruby'>謳(うた)</span>い文句\n\n", actual
Expand Down
13 changes: 12 additions & 1 deletion test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_inline_comment
def test_inline_comment_for_draft
@config["draft"] = true
actual = compile_inline("test @<comment>{コメント} test2")
assert_equal %Q|test ◆→DTP連絡:コメント←◆ test2|, actual
assert_equal %Q|test ◆→コメント←◆ test2|, actual
end

def test_inline_in_table
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d60ee54

Please sign in to comment.