Skip to content

Commit

Permalink
skip empty table. Closes: #1325
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Jun 10, 2019
1 parent 3328886 commit 7e717f7
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

begin
if caption.present?
Expand All @@ -173,7 +174,6 @@ def table(lines, id = nil, caption = nil)
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?
table_begin rows.first.size
if sepidx
sepidx.times do
Expand Down
2 changes: 1 addition & 1 deletion lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

if id
puts %Q(<div id="#{normalize_id(id)}" class="table">)
Expand All @@ -669,7 +670,6 @@ def table(lines, id = nil, caption = nil)
error "no such table: #{id}"
end
table_begin rows.first.size
return if rows.empty?
if sepidx
sepidx.times do
tr(rows.shift.map { |s| th(s) })
Expand Down
5 changes: 3 additions & 2 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ def table(lines, id = nil, caption = nil)
tablewidth = @book.config['tableopt'] ? @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f : nil
col = 0

puts '<table>'
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
Expand All @@ -466,6 +465,9 @@ def table(lines, id = nil, caption = nil)
col2 = rows[rows.length - 1].split(/\t/).length
col = col2 if col2 > col
end
return if rows.empty?

puts '<table>'

cellwidth = []
if tablewidth
Expand All @@ -492,7 +494,6 @@ def table(lines, id = nil, caption = nil)
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?

if tablewidth.nil?
print '<tbody>'
Expand Down
2 changes: 1 addition & 1 deletion lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,13 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

begin
table_header(id, caption) if caption.present?
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?
table_begin(rows.first.size)
if sepidx
sepidx.times do
Expand Down
2 changes: 1 addition & 1 deletion lib/review/markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

begin
table_header id, caption unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
table_begin rows.first.size
return if rows.empty?
if sepidx
sepidx.times do
tr(rows.shift.map { |s| th(s) })
Expand Down
5 changes: 3 additions & 2 deletions lib/review/plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def texequation(lines, id = nil, caption = '')
end

def table(lines, id = nil, caption = nil)
blank
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
Expand All @@ -234,13 +233,15 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

blank

begin
table_header(id, caption) if caption.present?
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?
table_begin rows.first.size
if sepidx
sepidx.times do
Expand Down
8 changes: 4 additions & 4 deletions lib/review/topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ def texequation(lines, id = nil, caption = '')
end

def table(lines, id = nil, caption = nil)
blank
puts "◆→開始:#{@titles['table']}←◆"

rows = []
sepidx = nil
lines.each_with_index do |line, idx|
Expand All @@ -201,13 +198,16 @@ def table(lines, id = nil, caption = nil)
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
return if rows.empty?

blank
puts "◆→開始:#{@titles['table']}←◆"

begin
table_header id, caption if caption.present?
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?
table_begin rows.first.size
if sepidx
sepidx.times do
Expand Down
7 changes: 7 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,13 @@ def test_table
actual
end

def test_empty_table
actual = compile_block("//table{\n//}\n")
assert_equal '', actual
actual = compile_block("//table{\n------------\n//}\n")
assert_equal '', actual
end

def test_inline_table
def @chapter.table(_id)
Book::TableIndex::Item.new('sampletable', 1)
Expand Down
7 changes: 7 additions & 0 deletions test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def test_customize_mmtopt
assert_equal %Q(<table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="1"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="28.458">A</td></tbody></table>), actual
end

def test_empty_table
actual = compile_block("//table{\n//}\n")
assert_equal '', actual
actual = compile_block("//table{\n------------\n//}\n")
assert_equal '', actual
end

def test_emtable
actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}")
assert_equal %Q(<table><caption>foo</caption><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="1"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="28.345">A</td></tbody></table><table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="1"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="28.345">A</td></tbody></table>), actual
Expand Down
7 changes: 7 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,13 @@ def test_table
actual
end

def test_empty_table
actual = compile_block("//table{\n//}\n")
assert_equal '', actual
actual = compile_block("//table{\n------------\n//}\n")
assert_equal '', actual
end

def test_customize_cellwidth
actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
Expand Down
7 changes: 7 additions & 0 deletions test/test_plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ def test_table
actual
end

def test_empty_table
actual = compile_block("//table{\n//}\n")
assert_equal '', actual
actual = compile_block("//table{\n------------\n//}\n")
assert_equal '', actual
end

def test_inline_table
def @chapter.table(_id)
Book::TableIndex::Item.new('sampletable', 1)
Expand Down
7 changes: 7 additions & 0 deletions test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ def test_table
actual
end

def test_empty_table
actual = compile_block("//table{\n//}\n")
assert_equal '', actual
actual = compile_block("//table{\n------------\n//}\n")
assert_equal '', actual
end

def test_inline_table
def @chapter.table(_id)
Book::TableIndex::Item.new('sampletable', 1)
Expand Down

0 comments on commit 7e717f7

Please sign in to comment.