prawn-markup 0.2.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +57 -32
- data/lib/prawn/markup.rb +2 -0
- data/lib/prawn/markup/builders/list_builder.rb +8 -3
- data/lib/prawn/markup/builders/nestable_builder.rb +8 -4
- data/lib/prawn/markup/builders/table_builder.rb +7 -7
- data/lib/prawn/markup/elements/cell.rb +2 -0
- data/lib/prawn/markup/elements/item.rb +2 -0
- data/lib/prawn/markup/elements/list.rb +2 -0
- data/lib/prawn/markup/interface.rb +2 -0
- data/lib/prawn/markup/processor.rb +17 -11
- data/lib/prawn/markup/processor/blocks.rb +13 -5
- data/lib/prawn/markup/processor/headings.rb +2 -0
- data/lib/prawn/markup/processor/images.rb +2 -0
- data/lib/prawn/markup/processor/inputs.rb +61 -0
- data/lib/prawn/markup/processor/lists.rb +14 -5
- data/lib/prawn/markup/processor/tables.rb +24 -3
- data/lib/prawn/markup/processor/text.rb +2 -0
- data/lib/prawn/markup/support/hash_merger.rb +2 -0
- data/lib/prawn/markup/support/normalizer.rb +2 -0
- data/lib/prawn/markup/support/size_converter.rb +2 -0
- data/lib/prawn/markup/version.rb +3 -1
- data/prawn-markup.gemspec +1 -1
- metadata +7 -16
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -64
- data/.travis.yml +0 -25
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -87
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83dd2ffa7203c8b28be3282663d21c5b2476c42df3b76dc18eae813da119deca
|
4
|
+
data.tar.gz: aa58d34136f86e9d810a7735c6976573b128f078ad42143037f3995e241b1a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d52868e2fad2b0af5d762cf8424c8db25452ebec7176a34c200557b4a6bb4b72e8c8d314910bbcb0fd2d732e2b80f76ff07365fb61ec46150f4aafdff18059
|
7
|
+
data.tar.gz: d76133ccb760e0de761592be9f8a5c950ffad696213d0ae0ca01350f6d3ef6e5ed6df3c29bfb09e52e5b90b8d9a36398fd7be5846a9ce54a381230e7219abd44
|
data/README.md
CHANGED
@@ -33,6 +33,27 @@ doc = Prawn::Document.new
|
|
33
33
|
doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>')
|
34
34
|
```
|
35
35
|
|
36
|
+
## Supported HTML
|
37
|
+
|
38
|
+
This gem parses the given HTML and layouts the following elements in a vertical order:
|
39
|
+
|
40
|
+
* Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
|
41
|
+
* Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`
|
42
|
+
* Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
|
43
|
+
* Tables: `table`, `tr`, `td`, `th`
|
44
|
+
* Media: `img`, `iframe`
|
45
|
+
* Inputs: `type=checkbox`, `type=radio`
|
46
|
+
|
47
|
+
All other elements are ignored, their content is added to the parent element. With a few exceptions, no CSS is processed. One exception is the `width` property of `img`, `td` and `th`, which may contain values in `cm`, `mm`, `px`, `pt`, `%` or `auto`.
|
48
|
+
|
49
|
+
If no explicit loader is given (see above), images are loaded from `http(s)` addresses or may be contained in the `src` attribute as base64 encoded data URIs. Prawn only supports `PNG` and `JPG`.
|
50
|
+
|
51
|
+
## Example
|
52
|
+
|
53
|
+
Have a look at [showcase.html](spec/fixtures/showcase.html), which is rendered by the corresponding [spec](spec/prawn/markup/showcase_spec.rb). Uncomment the `lookatit` call there to directly open the generated PDF when running the spec with `spec spec/prawn/markup/showcase_spec.rb`.
|
54
|
+
|
55
|
+
## Formatting Options
|
56
|
+
|
36
57
|
To customize element formatting, do:
|
37
58
|
|
38
59
|
```ruby
|
@@ -46,44 +67,48 @@ doc.markup_options = {
|
|
46
67
|
doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>', text: { align: :center })
|
47
68
|
```
|
48
69
|
|
49
|
-
Options may be set for `text`, `table` (`cell` and `header`) and `list` (`content` and `bullet`).
|
70
|
+
Options may be set for `text`, `heading[1-6]`, `table` (subkeys `cell` and `header`) and `list` (subkeys `content` and `bullet`).
|
50
71
|
|
51
|
-
Text options include all keys from Prawns [#text](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method) method: `font`, `size`, `color`, `style`, `align`, `valign`, `leading`,`direction`, `character_spacing`, `indent_paragraphs`, `kerning`, `mode`.
|
72
|
+
Text and heading options include all keys from Prawns [#text](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method) method: `font`, `size`, `color`, `style`, `align`, `valign`, `leading`,`direction`, `character_spacing`, `indent_paragraphs`, `kerning`, `mode`.
|
52
73
|
|
53
74
|
Tables and lists are rendered with [prawn-table](https://github.com/prawnpdf/prawn-table) and have the following additional options: `padding`, `borders`, `border_width`, `border_color`, `background_color`, `border_lines`, `rotate`, `overflow`, `min_font_size`. Options from `text` may be overridden.
|
54
75
|
|
55
76
|
Beside these options handled by Prawn / prawn-table, the following values may be customized:
|
56
77
|
|
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
|
-
|
78
|
+
* `:text`
|
79
|
+
* `:preprocessor`: A proc/callable that is called each time before a chunk of text is rendered.
|
80
|
+
* `:margin_bottom`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
|
81
|
+
* `:heading1-6`
|
82
|
+
* `:margin_top`: Margin before a heading. Default is 0.
|
83
|
+
* `:margin_bottom`: Margin after a heading. Default is 0.
|
84
|
+
* `:table`
|
85
|
+
* `:placeholder`
|
86
|
+
* `:too_large`: If the table content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[table content too large]'.
|
87
|
+
* `:subtable_too_large`: If the content of a subtable cannot be fitted into the table, this text is rendered instead. Defaults to '[nested tables with automatic width are not supported]'.
|
88
|
+
* `:list`
|
89
|
+
* `:vertical_margin`: Margin at the top and the bottom of a list. Default is 5.
|
90
|
+
* `:bullet`
|
91
|
+
* `:char`: The text used as bullet in unordered lists. Default is '•'.
|
92
|
+
* `:margin`: Margin before the bullet. Default is 10.
|
93
|
+
* `:content`
|
94
|
+
* `:margin`: Margin between the bullet and the content. Default is 10.
|
95
|
+
* `:placeholder`
|
96
|
+
* `:too_large`: If the list content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[list content too large]'.
|
97
|
+
* `:image`
|
98
|
+
* `:loader`: A callable that accepts the `src` attribute as an argument an returns a value understood by Prawn's `image` method. Loads `http(s)` URLs and base64 encoded data URIs by default.
|
99
|
+
* `:placeholder`: If an image is not supported, this text/callable is rendered instead. Defaults to '[unsupported image]'.
|
100
|
+
* `:iframe`
|
101
|
+
* `:placeholder`: If the HTML contains IFrames, this text/callable is rendered instead.
|
102
|
+
A callable gets the URL of the IFrame as an argument. Defaults to ignore iframes.
|
103
|
+
* `:input`
|
104
|
+
* `:symbol_font`: A special font to print checkboxes and radios. Prawn's standard fonts do not support special unicode characters. Do not forget to update the document's `font_families`.
|
105
|
+
* `:symbol_font_size`: The size of the special font to print checkboxes and radios.
|
106
|
+
* `:checkbox`
|
107
|
+
* `:checked`: The char to print for a checked checkbox. Default is '☑'.
|
108
|
+
* `:unchecked`: The char to print for an unchecked checkbox. Default is '☐'.
|
109
|
+
* `:radio`
|
110
|
+
* `:checked`: The char to print for a checked radio. Default is '◉'.
|
111
|
+
* `:unchecked`: The char to print for an unchecked radio. Default is '○'.
|
87
112
|
|
88
113
|
## Development
|
89
114
|
|
data/lib/prawn/markup.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Builders
|
4
6
|
class ListBuilder < NestableBuilder
|
5
|
-
BULLET_CHAR = '•'
|
7
|
+
BULLET_CHAR = '•'
|
6
8
|
BULLET_MARGIN = 10
|
7
9
|
CONTENT_MARGIN = 10
|
8
10
|
VERTICAL_MARGIN = 5
|
@@ -22,7 +24,10 @@ module Prawn
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def draw
|
25
|
-
|
27
|
+
# fix https://github.com/prawnpdf/prawn-table/issues/120
|
28
|
+
pdf.font_size(column_cell_style(:content)[:size] || pdf.font_size) do
|
29
|
+
make(true).draw
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
private
|
@@ -65,7 +70,7 @@ module Prawn
|
|
65
70
|
data = item.nodes.map { |n| [normalize_list_item_node(n)] }
|
66
71
|
style = column_cell_style(:content)
|
67
72
|
.merge(borders: [], padding: [0, 0, padding_bottom, 0])
|
68
|
-
pdf.make_table(data, cell_style: style) do
|
73
|
+
pdf.make_table(data, cell_style: style, column_widths: [content_width]) do
|
69
74
|
rows(-1).padding = [0, 0, 0, 0]
|
70
75
|
end
|
71
76
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Builders
|
@@ -47,10 +49,12 @@ module Prawn
|
|
47
49
|
def extract_text_cell_style(hash)
|
48
50
|
TEXT_STYLE_OPTIONS
|
49
51
|
.each_with_object({}) { |key, h| h[key] = hash[key] }
|
50
|
-
.tap
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
.tap { |options| convert_style_options(options) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_style_options(hash)
|
56
|
+
hash[:font_style] ||= hash.delete(:style)
|
57
|
+
hash[:text_color] ||= hash.delete(:color)
|
54
58
|
end
|
55
59
|
|
56
60
|
def type_key(object)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Builders
|
@@ -20,7 +22,10 @@ module Prawn
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def draw
|
23
|
-
|
25
|
+
# fix https://github.com/prawnpdf/prawn-table/issues/120
|
26
|
+
pdf.font_size(table_options[:cell][:size] || pdf.font_size) do
|
27
|
+
make.draw
|
28
|
+
end
|
24
29
|
rescue Prawn::Errors::CannotFit => e
|
25
30
|
if failover_on_error
|
26
31
|
draw
|
@@ -169,7 +174,7 @@ module Prawn
|
|
169
174
|
|
170
175
|
def distribute_remaing_width(count)
|
171
176
|
equal_width = (total_width - column_width_sum) / count.to_f
|
172
|
-
return if equal_width
|
177
|
+
return if equal_width.negative?
|
173
178
|
|
174
179
|
column_widths.map! { |width| width || equal_width }
|
175
180
|
end
|
@@ -231,11 +236,6 @@ module Prawn
|
|
231
236
|
convert_style_options(opts[:header])
|
232
237
|
end
|
233
238
|
|
234
|
-
def convert_style_options(hash)
|
235
|
-
hash[:font_style] ||= hash.delete(:style)
|
236
|
-
hash[:text_color] ||= hash.delete(:color)
|
237
|
-
end
|
238
|
-
|
239
239
|
def default_table_options
|
240
240
|
{
|
241
241
|
cell: {
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
# Processes known HTML tags. Unknown tags are ignored.
|
@@ -24,6 +26,7 @@ module Prawn
|
|
24
26
|
require 'prawn/markup/processor/blocks'
|
25
27
|
require 'prawn/markup/processor/headings'
|
26
28
|
require 'prawn/markup/processor/images'
|
29
|
+
require 'prawn/markup/processor/inputs'
|
27
30
|
require 'prawn/markup/processor/tables'
|
28
31
|
require 'prawn/markup/processor/lists'
|
29
32
|
|
@@ -31,10 +34,12 @@ module Prawn
|
|
31
34
|
prepend Prawn::Markup::Processor::Blocks
|
32
35
|
prepend Prawn::Markup::Processor::Headings
|
33
36
|
prepend Prawn::Markup::Processor::Images
|
37
|
+
prepend Prawn::Markup::Processor::Inputs
|
34
38
|
prepend Prawn::Markup::Processor::Tables
|
35
39
|
prepend Prawn::Markup::Processor::Lists
|
36
40
|
|
37
41
|
def initialize(pdf, options = {})
|
42
|
+
super()
|
38
43
|
@pdf = pdf
|
39
44
|
@options = options
|
40
45
|
end
|
@@ -48,10 +53,8 @@ module Prawn
|
|
48
53
|
end
|
49
54
|
|
50
55
|
def start_element(name, attrs = [])
|
51
|
-
stack.push(name: name, attrs:
|
52
|
-
if
|
53
|
-
send("start_#{name}") if respond_to?("start_#{name}", true)
|
54
|
-
end
|
56
|
+
stack.push(name: name, attrs: attrs.to_h)
|
57
|
+
send("start_#{name}") if known_element?(name) && respond_to?("start_#{name}", true)
|
55
58
|
end
|
56
59
|
|
57
60
|
def end_element(name)
|
@@ -65,11 +68,11 @@ module Prawn
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def error(string)
|
68
|
-
logger.info(
|
71
|
+
logger.info("SAX parsing error: #{string.strip}") if logger
|
69
72
|
end
|
70
73
|
|
71
74
|
def warning(string)
|
72
|
-
logger.info(
|
75
|
+
logger.info("SAX parsing warning: #{string.strip}") if logger
|
73
76
|
end
|
74
77
|
|
75
78
|
private
|
@@ -78,7 +81,11 @@ module Prawn
|
|
78
81
|
|
79
82
|
def reset
|
80
83
|
@stack = []
|
81
|
-
@text_buffer = ''
|
84
|
+
@text_buffer = +''
|
85
|
+
end
|
86
|
+
|
87
|
+
def known_element?(name)
|
88
|
+
self.class.known_elements.include?(name)
|
82
89
|
end
|
83
90
|
|
84
91
|
def append_text(string)
|
@@ -118,15 +125,14 @@ module Prawn
|
|
118
125
|
def style_properties
|
119
126
|
style = current_attrs['style']
|
120
127
|
if style
|
121
|
-
|
122
|
-
Hash[tokens]
|
128
|
+
style.split(';').map { |p| p.split(':', 2).map(&:strip) }.to_h
|
123
129
|
else
|
124
130
|
{}
|
125
131
|
end
|
126
132
|
end
|
127
133
|
|
128
134
|
def placeholder_value(keys, *args)
|
129
|
-
placeholder = dig_options(keys)
|
135
|
+
placeholder = dig_options(*keys)
|
130
136
|
return if placeholder.nil?
|
131
137
|
|
132
138
|
if placeholder.respond_to?(:call)
|
@@ -136,7 +142,7 @@ module Prawn
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
def dig_options(keys)
|
145
|
+
def dig_options(*keys)
|
140
146
|
keys.inject(options) { |opts, key| opts ? opts[key] : nil }
|
141
147
|
end
|
142
148
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Processor::Blocks
|
@@ -123,11 +125,17 @@ module Prawn
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def default_text_margin_bottom
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
text_line_gap +
|
129
|
+
text_descender +
|
130
|
+
text_leading
|
131
|
+
end
|
132
|
+
|
133
|
+
def text_line_gap
|
134
|
+
@text_line_gap ||= with_font(text_options) { pdf.font.line_gap }
|
135
|
+
end
|
136
|
+
|
137
|
+
def text_descender
|
138
|
+
@text_descender ||= with_font(text_options) { pdf.font.descender }
|
131
139
|
end
|
132
140
|
|
133
141
|
def text_leading
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Prawn
|
4
|
+
module Markup
|
5
|
+
module Processor::Inputs
|
6
|
+
|
7
|
+
DEFAULT_CHECKABLE_CHARS = {
|
8
|
+
checkbox: {
|
9
|
+
checked: '☑',
|
10
|
+
unchecked: '☐'
|
11
|
+
},
|
12
|
+
radio: {
|
13
|
+
checked: '◉',
|
14
|
+
unchecked: '○'
|
15
|
+
}
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def self.prepended(base)
|
19
|
+
base.known_elements.push('input')
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_input
|
23
|
+
type = current_attrs['type'].to_sym
|
24
|
+
if DEFAULT_CHECKABLE_CHARS.keys.include?(type)
|
25
|
+
append_checked_symbol(type)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def append_checked_symbol(type)
|
32
|
+
char = checkable_symbol(type)
|
33
|
+
append_text(build_font_tag(char))
|
34
|
+
end
|
35
|
+
|
36
|
+
def checkable_symbol(type)
|
37
|
+
state = current_attrs.key?('checked') ? :checked : :unchecked
|
38
|
+
dig_options(:input, type, state) || DEFAULT_CHECKABLE_CHARS[type][state]
|
39
|
+
end
|
40
|
+
|
41
|
+
def symbol_font_options
|
42
|
+
@symbol_font_options ||= {
|
43
|
+
name: dig_options(:input, :symbol_font),
|
44
|
+
size: dig_options(:input, :symbol_font_size)
|
45
|
+
}.compact
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_font_tag(content)
|
49
|
+
return content if symbol_font_options.empty?
|
50
|
+
|
51
|
+
out = +'<font'
|
52
|
+
symbol_font_options.each do |key, value|
|
53
|
+
out << " #{key}=\"#{value}\""
|
54
|
+
end
|
55
|
+
out << '>'
|
56
|
+
out << content
|
57
|
+
out << '</font>'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Processor::Lists
|
@@ -32,13 +34,13 @@ module Prawn
|
|
32
34
|
alias end_ul end_list
|
33
35
|
|
34
36
|
def start_li
|
35
|
-
return unless
|
37
|
+
return unless current_list
|
36
38
|
|
37
39
|
current_list.items << Elements::Item.new
|
38
40
|
end
|
39
41
|
|
40
42
|
def end_li
|
41
|
-
return unless
|
43
|
+
return unless current_list
|
42
44
|
|
43
45
|
add_cell_text_node(current_list_item)
|
44
46
|
end
|
@@ -65,7 +67,9 @@ module Prawn
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def current_list_item
|
68
|
-
current_list.items
|
70
|
+
items = current_list.items
|
71
|
+
items << Elements::Item.new if items.empty?
|
72
|
+
items.last
|
69
73
|
end
|
70
74
|
|
71
75
|
def inside_container?
|
@@ -85,12 +89,17 @@ module Prawn
|
|
85
89
|
end
|
86
90
|
|
87
91
|
def add_list(list)
|
88
|
-
|
89
|
-
|
92
|
+
pdf.move_up(additional_cell_padding_top)
|
93
|
+
draw_list(list)
|
94
|
+
put_bottom_margin(text_margin_bottom + additional_cell_padding_top)
|
90
95
|
rescue Prawn::Errors::CannotFit => e
|
91
96
|
append_text(list_too_large_placeholder(e))
|
92
97
|
end
|
93
98
|
|
99
|
+
def draw_list(list)
|
100
|
+
Builders::ListBuilder.new(pdf, list, pdf.bounds.width, options).draw
|
101
|
+
end
|
102
|
+
|
94
103
|
def list_too_large_placeholder(error)
|
95
104
|
placeholder_value(%i[list placeholder too_large], error) || '[list content too large]'
|
96
105
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Prawn
|
2
4
|
module Markup
|
3
5
|
module Processor::Tables
|
@@ -26,19 +28,29 @@ module Prawn
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def start_tr
|
31
|
+
return unless current_table
|
32
|
+
|
29
33
|
current_table << []
|
30
34
|
end
|
31
35
|
|
32
36
|
def start_td
|
37
|
+
return unless current_table
|
38
|
+
|
33
39
|
current_table.last << Elements::Cell.new(width: style_properties['width'])
|
34
40
|
end
|
35
41
|
|
36
42
|
def start_th
|
43
|
+
return unless current_table
|
44
|
+
|
37
45
|
current_table.last << Elements::Cell.new(width: style_properties['width'], header: true)
|
38
46
|
end
|
39
47
|
|
40
48
|
def end_td
|
41
|
-
|
49
|
+
if current_table
|
50
|
+
add_cell_text_node(current_cell)
|
51
|
+
else
|
52
|
+
add_current_text
|
53
|
+
end
|
42
54
|
end
|
43
55
|
alias end_th end_td
|
44
56
|
|
@@ -84,15 +96,24 @@ module Prawn
|
|
84
96
|
end
|
85
97
|
|
86
98
|
def add_table(cells)
|
87
|
-
|
88
|
-
put_bottom_margin(text_margin_bottom)
|
99
|
+
draw_table(cells)
|
100
|
+
put_bottom_margin(text_margin_bottom + additional_cell_padding_top + text_leading)
|
89
101
|
rescue Prawn::Errors::CannotFit => e
|
90
102
|
append_text(table_too_large_placeholder(e))
|
91
103
|
end
|
92
104
|
|
105
|
+
def draw_table(cells)
|
106
|
+
Builders::TableBuilder.new(pdf, cells, pdf.bounds.width, options).draw
|
107
|
+
end
|
108
|
+
|
93
109
|
def table_too_large_placeholder(error)
|
94
110
|
placeholder_value(%i[table placeholder too_large], error) || '[table content too large]'
|
95
111
|
end
|
112
|
+
|
113
|
+
def additional_cell_padding_top
|
114
|
+
# as used in Prawn::Table::Cell::Text#draw_content move_down
|
115
|
+
(text_line_gap + text_descender) / 2
|
116
|
+
end
|
96
117
|
end
|
97
118
|
end
|
98
119
|
end
|
data/lib/prawn/markup/version.rb
CHANGED
data/prawn-markup.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
-
f.match(%r{^(
|
20
|
+
f.match(%r{^(((spec|bin)/)|\.|Gemfile|Rakefile)})
|
21
21
|
end
|
22
22
|
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Zumkehr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -159,18 +159,9 @@ executables: []
|
|
159
159
|
extensions: []
|
160
160
|
extra_rdoc_files: []
|
161
161
|
files:
|
162
|
-
- ".gitignore"
|
163
|
-
- ".rspec"
|
164
|
-
- ".rubocop.yml"
|
165
|
-
- ".travis.yml"
|
166
162
|
- CODE_OF_CONDUCT.md
|
167
|
-
- Gemfile
|
168
|
-
- Gemfile.lock
|
169
163
|
- LICENSE.txt
|
170
164
|
- README.md
|
171
|
-
- Rakefile
|
172
|
-
- bin/console
|
173
|
-
- bin/setup
|
174
165
|
- lib/prawn/markup.rb
|
175
166
|
- lib/prawn/markup/builders/list_builder.rb
|
176
167
|
- lib/prawn/markup/builders/nestable_builder.rb
|
@@ -183,6 +174,7 @@ files:
|
|
183
174
|
- lib/prawn/markup/processor/blocks.rb
|
184
175
|
- lib/prawn/markup/processor/headings.rb
|
185
176
|
- lib/prawn/markup/processor/images.rb
|
177
|
+
- lib/prawn/markup/processor/inputs.rb
|
186
178
|
- lib/prawn/markup/processor/lists.rb
|
187
179
|
- lib/prawn/markup/processor/tables.rb
|
188
180
|
- lib/prawn/markup/processor/text.rb
|
@@ -195,7 +187,7 @@ homepage: https://github.com/puzzle/prawn-markup
|
|
195
187
|
licenses:
|
196
188
|
- MIT
|
197
189
|
metadata: {}
|
198
|
-
post_install_message:
|
190
|
+
post_install_message:
|
199
191
|
rdoc_options: []
|
200
192
|
require_paths:
|
201
193
|
- lib
|
@@ -210,9 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
202
|
- !ruby/object:Gem::Version
|
211
203
|
version: '0'
|
212
204
|
requirements: []
|
213
|
-
|
214
|
-
|
215
|
-
signing_key:
|
205
|
+
rubygems_version: 3.1.2
|
206
|
+
signing_key:
|
216
207
|
specification_version: 4
|
217
208
|
summary: Parse simple HTML markup to include in Prawn PDFs
|
218
209
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
DisplayCopNames: true
|
3
|
-
Exclude:
|
4
|
-
- '*.gemspec'
|
5
|
-
- spec/**/*
|
6
|
-
- vendor/**/*
|
7
|
-
|
8
|
-
Metrics/AbcSize:
|
9
|
-
Severity: error
|
10
|
-
|
11
|
-
Metrics/ClassLength:
|
12
|
-
Max: 250
|
13
|
-
Severity: error
|
14
|
-
|
15
|
-
Metrics/CyclomaticComplexity:
|
16
|
-
Severity: error
|
17
|
-
|
18
|
-
Metrics/LineLength:
|
19
|
-
Max: 100
|
20
|
-
Severity: error
|
21
|
-
|
22
|
-
Metrics/MethodLength:
|
23
|
-
Max: 10
|
24
|
-
Severity: error
|
25
|
-
|
26
|
-
Metrics/ModuleLength:
|
27
|
-
Max: 150
|
28
|
-
Severity: error
|
29
|
-
|
30
|
-
Metrics/ParameterLists:
|
31
|
-
Max: 4
|
32
|
-
Severity: warning
|
33
|
-
|
34
|
-
# Keep for now, easier with superclass definitions
|
35
|
-
ClassAndModuleChildren:
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
# The ones we use must exist for the entire class hierarchy.
|
39
|
-
ClassVars:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
# Well, well, well
|
43
|
-
Documentation:
|
44
|
-
Enabled: false
|
45
|
-
|
46
|
-
# Keep single line bodys for if and unless
|
47
|
-
IfUnlessModifier:
|
48
|
-
Enabled: false
|
49
|
-
|
50
|
-
# We thinks that's fine for specs
|
51
|
-
Layout/EmptyLinesAroundBlockBody:
|
52
|
-
Enabled: false
|
53
|
-
|
54
|
-
# We thinks that's fine
|
55
|
-
Layout/EmptyLinesAroundClassBody:
|
56
|
-
Enabled: false
|
57
|
-
|
58
|
-
# We thinks that's fine
|
59
|
-
Layout/EmptyLinesAroundModuleBody:
|
60
|
-
Enabled: false
|
61
|
-
|
62
|
-
# We think that's the developers choice
|
63
|
-
Style/GuardClause:
|
64
|
-
Enabled: false
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
|
3
|
-
language: ruby
|
4
|
-
|
5
|
-
rvm:
|
6
|
-
- 2.5.1
|
7
|
-
|
8
|
-
env:
|
9
|
-
global:
|
10
|
-
- CC_TEST_REPORTER_ID=d70fe39ffb8f2f7c5f837f0133d10a3a1c6784d0dd189153111577b60f74c603
|
11
|
-
|
12
|
-
before_install: gem install bundler
|
13
|
-
|
14
|
-
before_script:
|
15
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
16
|
-
- chmod +x ./cc-test-reporter
|
17
|
-
- ./cc-test-reporter before-build
|
18
|
-
|
19
|
-
script:
|
20
|
-
- bundle exec rake
|
21
|
-
- bundle exec rubocop
|
22
|
-
|
23
|
-
after_script:
|
24
|
-
- ./cc-test-reporter format-coverage -t simplecov -o spec/coverage/codeclimate.json spec/coverage/.resultset.json
|
25
|
-
- if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter upload-coverage -i spec/coverage/codeclimate.json; fi
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
prawn-markup (0.2.0)
|
5
|
-
nokogiri
|
6
|
-
prawn
|
7
|
-
prawn-table
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
Ascii85 (1.0.3)
|
13
|
-
afm (0.2.2)
|
14
|
-
ast (2.4.0)
|
15
|
-
byebug (10.0.2)
|
16
|
-
diff-lcs (1.3)
|
17
|
-
docile (1.3.2)
|
18
|
-
hashery (2.1.2)
|
19
|
-
jaro_winkler (1.5.3)
|
20
|
-
json (2.2.0)
|
21
|
-
mini_portile2 (2.4.0)
|
22
|
-
nokogiri (1.9.1)
|
23
|
-
mini_portile2 (~> 2.4.0)
|
24
|
-
parallel (1.17.0)
|
25
|
-
parser (2.6.3.0)
|
26
|
-
ast (~> 2.4.0)
|
27
|
-
pdf-core (0.7.0)
|
28
|
-
pdf-inspector (1.3.0)
|
29
|
-
pdf-reader (>= 1.0, < 3.0.a)
|
30
|
-
pdf-reader (2.2.0)
|
31
|
-
Ascii85 (~> 1.0.0)
|
32
|
-
afm (~> 0.2.1)
|
33
|
-
hashery (~> 2.0)
|
34
|
-
ruby-rc4
|
35
|
-
ttfunk
|
36
|
-
prawn (2.2.2)
|
37
|
-
pdf-core (~> 0.7.0)
|
38
|
-
ttfunk (~> 1.5)
|
39
|
-
prawn-table (0.2.2)
|
40
|
-
prawn (>= 1.3.0, < 3.0.0)
|
41
|
-
rainbow (3.0.0)
|
42
|
-
rake (12.3.2)
|
43
|
-
rspec (3.8.0)
|
44
|
-
rspec-core (~> 3.8.0)
|
45
|
-
rspec-expectations (~> 3.8.0)
|
46
|
-
rspec-mocks (~> 3.8.0)
|
47
|
-
rspec-core (3.8.2)
|
48
|
-
rspec-support (~> 3.8.0)
|
49
|
-
rspec-expectations (3.8.4)
|
50
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.8.0)
|
52
|
-
rspec-mocks (3.8.1)
|
53
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.8.0)
|
55
|
-
rspec-support (3.8.2)
|
56
|
-
rubocop (0.68.1)
|
57
|
-
jaro_winkler (~> 1.5.1)
|
58
|
-
parallel (~> 1.10)
|
59
|
-
parser (>= 2.5, != 2.5.1.1)
|
60
|
-
rainbow (>= 2.2.2, < 4.0)
|
61
|
-
ruby-progressbar (~> 1.7)
|
62
|
-
unicode-display_width (>= 1.4.0, < 1.6)
|
63
|
-
ruby-progressbar (1.10.1)
|
64
|
-
ruby-rc4 (0.1.5)
|
65
|
-
simplecov (0.17.0)
|
66
|
-
docile (~> 1.1)
|
67
|
-
json (>= 1.8, < 3)
|
68
|
-
simplecov-html (~> 0.10.0)
|
69
|
-
simplecov-html (0.10.2)
|
70
|
-
ttfunk (1.5.1)
|
71
|
-
unicode-display_width (1.5.0)
|
72
|
-
|
73
|
-
PLATFORMS
|
74
|
-
ruby
|
75
|
-
|
76
|
-
DEPENDENCIES
|
77
|
-
bundler
|
78
|
-
byebug
|
79
|
-
pdf-inspector
|
80
|
-
prawn-markup!
|
81
|
-
rake
|
82
|
-
rspec
|
83
|
-
rubocop
|
84
|
-
simplecov
|
85
|
-
|
86
|
-
BUNDLED WITH
|
87
|
-
1.17.3
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'prawn/markup'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|