Module: Prawn::Accessibility::TablePatch::CellClassPatch Private

Defined in:
lib/prawn/accessibility/table.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Prepended onto the Table::Cell singleton so Cell.draw_cells emits row/cell structure tags in tagged mode.

Instance Method Summary collapse

Instance Method Details

#draw_cells(cells) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/prawn/accessibility/table.rb', line 68

def draw_cells(cells)
  return super if cells.empty?

  first_entry = cells.first
  first_cell = first_entry.is_a?(Array) ? first_entry[0] : first_entry
  pdf = first_cell.instance_variable_get(:@pdf)
  tagged = pdf.respond_to?(:tagged?) && pdf.tagged?

  return super unless tagged

  # Phase 1: backgrounds (decorative — artifact in tagged mode)
  pdf.artifact(type: :Layout) do
    cells.each do |cell, pt|
      cell.set_width_constraints
      cell.draw_background(pt)
    end
  end

  # Phase 2: borders and content, wrapped in TR/TH/TD structure
  draw_cells_tagged(cells, pdf)
end

#draw_cells_tagged(cells, pdf) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Draw cells with accessibility structure tags (TR, TH, TD).



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/prawn/accessibility/table.rb', line 93

def draw_cells_tagged(cells, pdf)
  # Group cells by row for TR wrapping
  rows = cells.group_by { |cell, _pt| cell.row }

  rows.sort_by { |row_num, _| row_num }.each do |_row_num, row_cells|
    pdf.structure_container(:TR) do
      row_cells.each do |cell, pt|
        # Skip span dummy cells — the master cell handles drawing
        next if cell.is_a?(Prawn::Table::Cell::SpanDummy)

        # Borders are decorative
        pdf.artifact(type: :Layout) { cell.draw_borders(pt) }

        # Content gets TH or TD tag
        tag = cell.header? ? :TH : :TD
        attrs = {}
        attrs[:Scope] = :Column if tag == :TH

        pdf.structure(tag, attrs) do
          cell.draw_content_only(pt)
        end
      end
    end
  end
end