Module: Asciidoctor::PDF::Rhrev::PrawnTableDrawPatch
- Defined in:
- lib/asciidoctor/rhrev/table_draw_patch.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#rhrev_blank_cell?(cell) ⇒ Boolean
The trailing row appended for rhrev-table-extra-blank-row is a pair of non-breaking-space cells.
Instance Method Details
#draw ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/asciidoctor/rhrev/table_draw_patch.rb', line 31 def draw unless @pdf.respond_to?(:instance_variable_get) && @pdf.instance_variable_get(:@_rhrev_skip_lonely_blank_row) return super end # Defensive: only take the reimplemented path when the prawn-table # internals we rely on are exactly the shape we reimplement against # (0.2.2). On any drift, fall back to stock behavior. internals = %i[initial_row_on_initial_page start_new_page? ink_and_draw_cells_and_start_new_page set_background_color ink_and_draw_cells header_rows with_position] unless internals.all? { |m| respond_to?(m, true) } && @pdf.respond_to?(:reference_bounds) return super end with_position do ref_bounds = @pdf.reference_bounds started_new_page_at_row = initial_row_on_initial_page offset = @pdf.y @header_row = header_rows if @header cells_this_page = [] last_drawn_cell = nil last_row_index = @cells.map(&:row).max blank_row_decided = false skip_blank_row = false @cells.each do |cell| if cell.row == last_row_index && rhrev_blank_cell?(cell) # Decide once, from the first (column 0) cell of the last row, and # apply the same answer to every cell of that row. unless blank_row_decided skip_blank_row = start_new_page?(cell, offset, ref_bounds) blank_row_decided = true end next if skip_blank_row end if start_new_page?(cell, offset, ref_bounds) cells_this_page, offset = ink_and_draw_cells_and_start_new_page(cells_this_page, cell) started_new_page_at_row = cell.row end cell = set_background_color(cell, started_new_page_at_row) cells_this_page << [cell, [cell.relative_x, cell.relative_y(offset)]] last_drawn_cell = cell end ink_and_draw_cells(cells_this_page) # @cells.last may now be a dropped blank cell; anchor the final cursor # to the last cell we actually inked. if last_drawn_cell @pdf.move_cursor_to(last_drawn_cell.relative_y(offset) - last_drawn_cell.height) end end end |
#rhrev_blank_cell?(cell) ⇒ Boolean
The trailing row appended for rhrev-table-extra-blank-row is a pair of non-breaking-space cells. Treat a last-row cell as blank when its content is empty once NBSP/whitespace is stripped; when the content can't be read, rely on the caller's flag + last-row guarantee and treat it as blank.
96 97 98 99 100 |
# File 'lib/asciidoctor/rhrev/table_draw_patch.rb', line 96 def rhrev_blank_cell? cell content = (cell.content.to_s rescue nil) return true if content.nil? content.gsub(/[ \s]| | /, '').empty? end |