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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b195d6ff3dfeacfc8e8112f17323bfdc8981b955a994862d9609b07184dd229f
4
- data.tar.gz: 33113b2d2db4aedae4eb7c412f65d7d2400d89f4dc94f30d9f4a700ea6598164
3
+ metadata.gz: 83dd2ffa7203c8b28be3282663d21c5b2476c42df3b76dc18eae813da119deca
4
+ data.tar.gz: aa58d34136f86e9d810a7735c6976573b128f078ad42143037f3995e241b1a9a
5
5
  SHA512:
6
- metadata.gz: 912de36400986c54d00f4ca94fa5e37207236e79152490370278f2c11895da5e75041b1bd528e6c179c11b145723a7ee1a4fdee8da05f384f4054d711a589117
7
- data.tar.gz: 3f03640c1d82f6a46f2d5c74e9fcb8ff16287a0b83ad6a6e273f55ba03f2d4a716e0a549e7e6c9b64551062522e04ae2108678b048163fb21b5554a327c6b6fa
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
- * `[:text][:preprocessor]`: A proc/callable that is called each time before a chunk of text is rendered.
58
- * `[:text][:margin_bottom]`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
59
- * `[:heading1-6][:margin_top]`: Margin before a heading. Default is 0.
60
- * `[:heading1-6][:margin_bottom]`: Margin after a heading. Default is 0.
61
- * `[:table][:placeholder][: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]'.
62
- * `[:table][:placeholder][: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]'.
63
- * `[:list][:vertical_margin]`: Margin at the top and the bottom of a list. Default is 5.
64
- * `[:list][:bullet][:char]`: The text used as bullet in unordered lists. Default is '•'.
65
- * `[:list][:bullet][:margin]`: Margin before the bullet. Default is 10.
66
- * `[:list][:content][:margin]`: Margin between the bullet and the content. Default is 10.
67
- * `[:list][:placeholder][: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]'.
68
- * `[:image][: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.
69
- * `[:image][:placeholder]`: If an image is not supported, this text/callable is rendered instead. Defaults to '[unsupported image]'.
70
- * `[:iframe][:placeholder]`: If the HTML contains IFrames, this text/callable is rendered instead.
71
- A callable gets the URL of the IFrame as an argument. Defaults to ignore iframes.
72
-
73
- ## Supported HTML
74
-
75
- This gem parses the given HTML and layouts the following elements in a vertical order:
76
-
77
- * Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
78
- * Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`
79
- * Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
80
- * Tables: `table`, `tr`, `td`, `th`
81
- * Media: `img`, `iframe`
82
-
83
- 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`.
84
-
85
- 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`.
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'prawn'
2
4
  require 'prawn/measurement_extensions'
3
5
  require 'prawn/table'
@@ -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 = '•'.freeze
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
- make(true).draw
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 do |options|
51
- options[:font_style] ||= options.delete(:style)
52
- options[:text_color] ||= options.delete(:color)
53
- end
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
- make.draw
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 < 0
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
  module Elements
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module Elements
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module Elements
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module Interface
@@ -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: Hash[attrs])
52
- if self.class.known_elements.include?(name)
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('SAX parsing error: ' + string.strip) if logger
71
+ logger.info("SAX parsing error: #{string.strip}") if logger
69
72
  end
70
73
 
71
74
  def warning(string)
72
- logger.info('SAX parsing warning: ' + string.strip) if logger
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
- tokens = style.split(';').map { |p| p.split(':', 2).map(&:strip) }
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
- with_font(text_options) do
127
- pdf.font.line_gap +
128
- pdf.font.descender +
129
- text_leading
130
- end
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module Processor::Headings
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open-uri'
2
4
 
3
5
  module Prawn
@@ -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 inside_container?
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 inside_container?
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.last
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
- Builders::ListBuilder.new(pdf, list, pdf.bounds.width, options).draw
89
- put_bottom_margin(text_margin_bottom)
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
- add_cell_text_node(current_cell)
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
- Builders::TableBuilder.new(pdf, cells, pdf.bounds.width, options).draw
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module Processor::Text
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  module HashMerger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  # Normalizes HTML markup:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
5
  class SizeConverter
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Markup
3
- VERSION = '0.2.0'.freeze
5
+ VERSION = '0.3.2'
4
6
  end
5
7
  end
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{^(test|spec|features)/})
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.0
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: 2019-07-09 00:00:00.000000000 Z
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
- rubyforge_project:
214
- rubygems_version: 2.7.8
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
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /spec/coverage/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
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
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in prawn-markup.gemspec
4
- gemspec
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
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
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__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here