From 582ed9f897d576195d9617c7e67a96de7aef8e37 Mon Sep 17 00:00:00 2001
From: Diego Steiner <939106+diegosteiner@users.noreply.github.com>
Date: Sun, 22 Dec 2024 15:46:44 +0100
Subject: [PATCH 1/5] fix: only allow on supported options of prawn-table
See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
---
lib/prawn/markup/processor/tables.rb | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/prawn/markup/processor/tables.rb b/lib/prawn/markup/processor/tables.rb
index a85eb56..c899da1 100644
--- a/lib/prawn/markup/processor/tables.rb
+++ b/lib/prawn/markup/processor/tables.rb
@@ -86,6 +86,11 @@ def inside_container?
def add_cell_text_node(cell, options = {})
return unless buffered_text?
+ options[:font_style] ||= options.delete(:style) if options.key?(:style)
+ # only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
+ options.slice!(*%i[font font_style inline_format kerning leading min_font_size
+ overflow rotate rotate_around single_line size text_color valign])
+
cell.nodes << options.merge(content: dump_text.strip)
end
From 7dd635d6addc82a605f2f35a53f62541a26570f6 Mon Sep 17 00:00:00 2001
From: Diego Steiner <939106+diegosteiner@users.noreply.github.com>
Date: Sun, 22 Dec 2024 15:52:43 +0100
Subject: [PATCH 2/5] fix: add specs
---
spec/prawn/markup/processor/tables_spec.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/spec/prawn/markup/processor/tables_spec.rb b/spec/prawn/markup/processor/tables_spec.rb
index ac2b3b4..b519e36 100644
--- a/spec/prawn/markup/processor/tables_spec.rb
+++ b/spec/prawn/markup/processor/tables_spec.rb
@@ -77,6 +77,14 @@
first_row_top - 4 * line].map(&:round))
end
+ it 'creates headings inside tables' do
+ processor.parse('
')
+ expect(text.strings).to eq(['hello', 'world'])
+ first_sub_col_left = first_col_left + table_padding
+ expect(left_positions).to eq([first_col_left, first_col_left)
+ expect(top_positions).to eq([first_row_top, first_row_top - line].map(&:round))
+ end
+
it 'creates divs inside tables' do
processor.parse('bootall the rest | ' \
'other |
')
From 7d4ab3229fe9bea21684d625f496572b15edfcdc Mon Sep 17 00:00:00 2001
From: Diego Steiner <939106+diegosteiner@users.noreply.github.com>
Date: Wed, 8 Jan 2025 09:09:05 +0100
Subject: [PATCH 3/5] fix: requested changes from PR
---
lib/prawn/markup/processor/tables.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/prawn/markup/processor/tables.rb b/lib/prawn/markup/processor/tables.rb
index c899da1..fd6924e 100644
--- a/lib/prawn/markup/processor/tables.rb
+++ b/lib/prawn/markup/processor/tables.rb
@@ -86,10 +86,9 @@ def inside_container?
def add_cell_text_node(cell, options = {})
return unless buffered_text?
- options[:font_style] ||= options.delete(:style) if options.key?(:style)
# only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
- options.slice!(*%i[font font_style inline_format kerning leading min_font_size
- overflow rotate rotate_around single_line size text_color valign])
+ options = options.slice!(*%i[font font_style inline_format kerning leading min_font_size
+ overflow rotate rotate_around single_line size text_color valign])
cell.nodes << options.merge(content: dump_text.strip)
end
From b97b1dcde2ee0112e3748541b0426056eea462cd Mon Sep 17 00:00:00 2001
From: Diego Steiner <939106+diegosteiner@users.noreply.github.com>
Date: Wed, 8 Jan 2025 09:14:55 +0100
Subject: [PATCH 4/5] fix: requested changes from PR
---
lib/prawn/markup/processor/tables.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/prawn/markup/processor/tables.rb b/lib/prawn/markup/processor/tables.rb
index fd6924e..6dc7c33 100644
--- a/lib/prawn/markup/processor/tables.rb
+++ b/lib/prawn/markup/processor/tables.rb
@@ -87,8 +87,8 @@ def add_cell_text_node(cell, options = {})
return unless buffered_text?
# only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
- options = options.slice!(*%i[font font_style inline_format kerning leading min_font_size
- overflow rotate rotate_around single_line size text_color valign])
+ options = options.slice(*%i[font font_style inline_format kerning leading min_font_size
+ overflow rotate rotate_around single_line size text_color valign])
cell.nodes << options.merge(content: dump_text.strip)
end
From 7235655c1146b39b0a912c33417c5faa0e4463a2 Mon Sep 17 00:00:00 2001
From: Diego Steiner
Date: Wed, 8 Jan 2025 08:54:14 +0000
Subject: [PATCH 5/5] fix: changes from pr
---
lib/prawn/markup/processor/tables.rb | 6 +++---
spec/prawn/markup/processor/tables_spec.rb | 22 ++++++++++++++--------
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/lib/prawn/markup/processor/tables.rb b/lib/prawn/markup/processor/tables.rb
index 6dc7c33..be49cd0 100644
--- a/lib/prawn/markup/processor/tables.rb
+++ b/lib/prawn/markup/processor/tables.rb
@@ -87,9 +87,9 @@ def add_cell_text_node(cell, options = {})
return unless buffered_text?
# only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
- options = options.slice(*%i[font font_style inline_format kerning leading min_font_size
- overflow rotate rotate_around single_line size text_color valign])
-
+ options = options.slice(*%i[font font_style inline_format kerning leading min_font_size size
+ overflow rotate rotate_around single_line text_color valign])
+
cell.nodes << options.merge(content: dump_text.strip)
end
diff --git a/spec/prawn/markup/processor/tables_spec.rb b/spec/prawn/markup/processor/tables_spec.rb
index b519e36..0d48aa2 100644
--- a/spec/prawn/markup/processor/tables_spec.rb
+++ b/spec/prawn/markup/processor/tables_spec.rb
@@ -65,7 +65,6 @@
processor.parse('boot hello world and universe | ' \
'other
last |
')
expect(text.strings).to eq(['boot', 'hello', 'world', 'and universe', 'other', 'last'])
- first_sub_col_left = first_col_left + table_padding
expect(left_positions)
.to eq([first_col_left, first_col_left, first_col_left, first_col_left, 342, 342])
expect(top_positions)
@@ -77,19 +76,26 @@
first_row_top - 4 * line].map(&:round))
end
- it 'creates headings inside tables' do
- processor.parse('')
- expect(text.strings).to eq(['hello', 'world'])
- first_sub_col_left = first_col_left + table_padding
- expect(left_positions).to eq([first_col_left, first_col_left)
- expect(top_positions).to eq([first_row_top, first_row_top - line].map(&:round))
+ describe 'nested headings' do
+ let(:options) do
+ {
+ heading1: { size: 36, style: :bold },
+ heading2: { size: 24, style: :bold_italic }
+ }
+ end
+
+ it 'creates headings inside tables' do
+ processor.parse('')
+ expect(text.strings).to eq(['hello', 'world'])
+ expect(left_positions).to eq([first_col_left, first_col_left])
+ expect(top_positions).to eq([first_row_top - 17, first_row_top - 50].map(&:round))
+ end
end
it 'creates divs inside tables' do
processor.parse('bootall the rest | ' \
'other |
')
expect(text.strings).to eq(['boot', 'hello', 'world', 'and universe', 'all the rest', 'other'])
- first_sub_col_left = first_col_left + table_padding
expect(left_positions)
.to eq([first_col_left, first_col_left, first_col_left, first_col_left, first_col_left, 368])
expect(top_positions)