Skip to content

Native tables have named columns - #94

Merged
czj merged 1 commit into
mainfrom
claude/confident-pasteur-jz0fj6
Nov 12, 2026
Merged

czj merged 1 commit into
mainfrom
claude/confident-pasteur-jz0fj6

Conversation

@czj

@czj czj commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

A native table took Prawn's array of arrays: the header was the first row, and a column was styled by its position, counted by hand and recounted whenever a column was added. Its options were Prawn's (column_widths, cell_style, row_colors), passed through unchecked.

Columns now have names, and rows are hashes or objects answering those names. This is the fourth slice of #71, part of #69. It replaces the table options added in #91, which have not been released.

  • Named columns: each column takes a title, width, align, weight, italic, size and color; a missing title is the name spelled out (first_name reads "First name"), and without columns: a table of hashes has those of its first row.
  • Rows as data: hashes, or objects answering the columns' names; a row given as an array raises an error that points to document.prawn.table.
  • Header from the titles: bold and repeated on every page by default; header: takes its style (including background) or false.
  • Checked options: stripes alternates row backgrounds, cell styles every cell, and an unknown option at any level raises ArgumentError listing the accepted ones.
  • Escape hatch kept: the block still receives the Prawn::Table before it is laid out, for what the options do not cover, such as a span or one cell's style.
Proof
  • test/native_boxes_test.rb: a 61-row table with named columns gives the same glyphs at the same positions, on the same pages, as the equivalent Prawn table, and leaves the same cursor; a right-aligned bold column is drawn where Prawn's own table draws it; titles are inferred from the first row, and rows can be objects; header styles, stripes, the header background and cell borders are read from the content stream through qpdf; an empty table without a header draws nothing and takes no room; every malformed input raises with its message checked.
  • test/native_bands_test.rb: a footer holding a native table still stays on its page.
  • Full suite on Ruby 3.3.6 with the corpus, rebased on main after Headers and footers that know their page number and the total #92 and List Mapitaine with the other gems #93: 1307 runs, 0 failures, 3 skips (veraPDF and Mustang not installed here). RuboCop and docs:highlight:check pass.
  • A two-page table with a dark repeated header, stripes, a right-aligned bold column and a total table beside it was rendered and looked at.
  • Tests cover the change (a bug fix comes with a test that fails without it)
  • Output unchanged, or every difference is intended and listed above

Generated by Claude Code

A native table took Prawn's array of arrays: the header was the first
row, and a column was styled by its position, counted by hand and
recounted when a column was added.

Columns now have names. Rows are hashes, or objects answering those
names; each column takes a title, a width, an alignment and text
attributes, and the header row is made of the titles. header takes the
header's style or false, stripes alternates row backgrounds, cell
styles every cell, and each option is checked. Without columns, a table
of hashes has those of its first row.

The block still receives the Prawn::Table before it is laid out, for
what the options do not cover, and Prawn's table of arrays stays at
document.prawn.table. The table box moves to its own file.

Assisted-by: Claude [Claude Code]
@czj
czj merged commit 04352d3 into main Nov 12, 2026
8 checks passed
@czj
czj deleted the claude/confident-pasteur-jz0fj6 branch November 12, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants