prawn-markup 0.3.3 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 064fb432004ce75eb3de1f626e08b1b5eba66de34fee0c1279eeb658d761a055
4
- data.tar.gz: 0ea8ce592534b0b4f10480981374c66ff1ba09c9deb799f3e9f53214a9a3b831
3
+ metadata.gz: df28b18b9cd1867a3ddf1b3d0a38be2bc6a222ba3162b7c030cec7e4819dabae
4
+ data.tar.gz: 707f1c55495e420935df46b7d8430c03155a67fefe5b5feeb2e8fa5a5acc5539
5
5
  SHA512:
6
- metadata.gz: 534a234950b2df218bb111563730b18b9e1e2cb22c3393da53ae3d70412283139e9bec5e57e7aeb2ae0638132a6ab023b602c7cb9c9dcedf97e27e92371a8565
7
- data.tar.gz: 8d7e1f43b928f9861b9b885eaf39692f8678b6e955845daf8859da60a95cdd76da72f1f2062dff8ef461dd0a9bd614509fb3903ba0ecada86546af7b1771460b
6
+ metadata.gz: 80702b603383f5613368db4ee66a6a1b3d3eb287f1d9ee90a941361638023dc90876df0f7faf91eb65d42cfca271670eecdbcdf28d525434ed4874bb550ad800
7
+ data.tar.gz: 803c32a2293ff0b6c73cda474a301af6a3ecdaadd0a85f84639aad4ecd2783386185a2c309f6d95286bcec1156833f87b92a7ca36d51320c1c86af82f39031af
data/README.md CHANGED
@@ -38,13 +38,13 @@ doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>')
38
38
  This gem parses the given HTML and layouts the following elements in a vertical order:
39
39
 
40
40
  * Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
41
- * Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`
41
+ * Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`, `color`
42
42
  * Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
43
43
  * Tables: `table`, `tr`, `td`, `th`
44
44
  * Media: `img`, `iframe`
45
45
  * Inputs: `type=checkbox`, `type=radio`
46
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`.
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`. Another exception is the `rgb` or `cmyk` properties of the Prawn-specific `color` tag.
48
48
 
49
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
50
 
@@ -69,7 +69,7 @@ module Prawn
69
69
  def list_item_table(item)
70
70
  data = item.nodes.map { |n| [normalize_list_item_node(n)] }
71
71
  style = column_cell_style(:content)
72
- .merge(borders: [], padding: [0, 0, padding_bottom, 0])
72
+ .merge(borders: [], padding: [0, 0, padding_bottom, 0], inline_format: true)
73
73
  pdf.make_table(data, cell_style: style, column_widths: [content_width]) do
74
74
  rows(-1).padding = [0, 0, 0, 0]
75
75
  end
@@ -98,7 +98,7 @@ module Prawn
98
98
  end
99
99
 
100
100
  def content_width
101
- column_widths.last && column_widths.last - content_margin
101
+ column_widths.last && (column_widths.last - content_margin)
102
102
  end
103
103
 
104
104
  def compute_column_widths
@@ -131,7 +131,7 @@ module Prawn
131
131
 
132
132
  def normalize_cell_hash(node, width, style_options)
133
133
  if width.nil? && total_width
134
- width = total_width - column_width_sum - (columns_without_width - 1) * MIN_COL_WIDTH
134
+ width = total_width - column_width_sum - ((columns_without_width - 1) * MIN_COL_WIDTH)
135
135
  end
136
136
  super(node, width, style_options)
137
137
  end
@@ -190,13 +190,13 @@ module Prawn
190
190
 
191
191
  def increase_widths(sum)
192
192
  diff = total_width - sum
193
- column_widths.map! { |w| w + w / sum * diff }
193
+ column_widths.map! { |w| w + (w / sum * diff) }
194
194
  end
195
195
 
196
196
  def decrease_widths(sum)
197
197
  sum += columns_without_width * MIN_COL_WIDTH
198
198
  diff = sum - total_width
199
- column_widths.map! { |w| w ? [w - w / sum * diff, 0].max : nil }
199
+ column_widths.map! { |w| w ? [w - (w / sum * diff), 0].max : nil }
200
200
  end
201
201
 
202
202
  def failover_on_error
@@ -210,7 +210,7 @@ module Prawn
210
210
 
211
211
  def horizontal_padding
212
212
  @horizontal_padding ||= begin
213
- padding = table_options[:cell][:padding] || [DEFAULT_CELL_PADDING] * 4
213
+ padding = table_options[:cell][:padding] || ([DEFAULT_CELL_PADDING] * 4)
214
214
  padding.is_a?(Array) ? padding[1] + padding[3] : padding
215
215
  end
216
216
  end
@@ -57,7 +57,7 @@ module Prawn
57
57
  def default_options_with_size(level)
58
58
  default = text_options.dup
59
59
  default[:size] ||= pdf.font_size
60
- default[:size] *= 2.5 - level * 0.25
60
+ default[:size] *= 2.5 - (level * 0.25)
61
61
  HashMerger.deep(default, options[:"heading#{level}"] || {})
62
62
  end
63
63
 
@@ -75,7 +75,7 @@ module Prawn
75
75
  if src =~ %r{^https?:/}
76
76
  begin
77
77
  URI.parse(src).open
78
- rescue OpenURI::HTTPError, SocketError
78
+ rescue StandardError # OpenURI::HTTPError, SocketError or anything else
79
79
  nil
80
80
  end
81
81
  end
@@ -90,9 +90,12 @@ module Prawn
90
90
  end
91
91
 
92
92
  def add_cell_image(cell)
93
+ src = current_attrs['src']
94
+ return if src.to_s.strip.empty?
95
+
93
96
  add_cell_text_node(cell)
94
- img = image_properties(current_attrs['src'])
95
- cell.nodes << img || invalid_image_placeholder
97
+ img = image_properties(src)
98
+ (cell.nodes << img) || invalid_image_placeholder
96
99
  end
97
100
 
98
101
  def add_table(cells)
@@ -6,7 +6,7 @@ module Prawn
6
6
  def self.prepended(base)
7
7
  base.known_elements.push(
8
8
  'a', 'b', 'strong', 'i', 'em', 'u', 'strikethrough', 'strike', 's', 'del',
9
- 'sub', 'sup'
9
+ 'sub', 'sup', 'color', 'font'
10
10
  )
11
11
  end
12
12
 
@@ -78,6 +78,31 @@ module Prawn
78
78
  append_text('</sup>')
79
79
  end
80
80
 
81
+ def start_color
82
+ rgb, c, m, y, k = current_attrs.values_at('rgb', 'c', 'm', 'y', 'k')
83
+
84
+ if [c, m, y, k].all?
85
+ append_text("<color c=\"#{c}\" m=\"#{m}\" y=\"#{y}\" k=\"#{k}\">")
86
+ else
87
+ append_text("<color rgb=\"#{rgb}\">")
88
+ end
89
+ end
90
+
91
+ def end_color
92
+ append_text('</color>')
93
+ end
94
+
95
+ def start_font
96
+ font_attrs = current_attrs
97
+ .slice('size', 'name', 'character_spacing')
98
+ .reduce('') { |acc, (key, val)| "#{acc} #{key}=\"#{val}\"" }
99
+
100
+ append_text("<font #{font_attrs}>")
101
+ end
102
+
103
+ def end_font
104
+ append_text('</font>')
105
+ end
81
106
  end
82
107
  end
83
108
  end
@@ -19,7 +19,7 @@ module Prawn
19
19
  def convert(string)
20
20
  value = string.to_f
21
21
  if string.end_with?('%')
22
- value * max / 100.0
22
+ max ? value * max / 100.0 : nil
23
23
  elsif string.end_with?('cm')
24
24
  value.cm
25
25
  elsif string.end_with?('mm')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module Markup
5
- VERSION = '0.3.3'
5
+ VERSION = '0.3.6'
6
6
  end
7
7
  end
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.3.3
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pascal Zumkehr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri