Skip to content

Commit

Permalink
resolves asciidoctor#403 advance table to next page if rowspan in fir…
Browse files Browse the repository at this point in the history
…st row does not fit in space remaining on current page
  • Loading branch information
mojavelinux committed May 22, 2022
1 parent 4c03f53 commit 2a218fc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
This document provides a high-level view of the changes to the {project-name} by release.
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.

== Unreleased

Bug Fixes::

* advance table to next page if rowspan in first row does not fit in space remaining on current page (#403)

== 2.0.1 (2022-05-21) - @mojavelinux

Bug Fixes::
Expand Down
11 changes: 11 additions & 0 deletions lib/asciidoctor/pdf/ext/prawn-table.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# frozen_string_literal: true

require 'prawn/table'

Prawn::Table.prepend (Module.new do
def initial_row_on_initial_page
return 0 if fits_on_page? @pdf.bounds.height
height_required = (row (0..number_of_header_rows)).height_with_span
return -1 if fits_on_page? height_required, true
@pdf.bounds.move_past_bottom
0
end
end)

require_relative 'prawn-table/cell'
require_relative 'prawn-table/cell/asciidoc'
require_relative 'prawn-table/cell/text'
21 changes: 21 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,27 @@
(expect big_cell_text[:y]).to be < top_cell_text[:y]
(expect big_cell_text[:y]).to be > bottom_cell_text[:y]
end

it 'should advance table to next page if rowspan in first row does not fit on current page' do
input = <<~EOS
#{(['filler'] * 5).join %(\n\n)}
[cols=2*]
|===
.30+|Group A |Member 1
#{29.times.map {|idx| '|Member ' + idx.next.to_s }.join ?\n}
.30+|Group B |Member 1
#{29.times.map {|idx| '|Member ' + idx.next.to_s }.join ?\n}
|===
EOS

pdf = to_pdf input, analyze: true, debug: true
(expect pdf.pages).to have_size 3
(expect (pdf.find_text 'filler').map {|it| it[:page_number] }.uniq).to eql [1]
(expect (pdf.find_unique_text 'Group A')[:page_number]).to eql 2
(expect (pdf.find_unique_text 'Group B')[:page_number]).to eql 3
end
end

context 'Arrange block' do
Expand Down

0 comments on commit 2a218fc

Please sign in to comment.