prawn-markup 0.3.2 → 0.3.5

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: 83dd2ffa7203c8b28be3282663d21c5b2476c42df3b76dc18eae813da119deca
4
- data.tar.gz: aa58d34136f86e9d810a7735c6976573b128f078ad42143037f3995e241b1a9a
3
+ metadata.gz: c3e26315f0588069e152aea5344bb9e79523b71aed0a574875036802ccb3a3d0
4
+ data.tar.gz: 1c9f31e0e3d19c4bc0c9811d1c0043512a11fa5ca9b15e864919c3ab4d633402
5
5
  SHA512:
6
- metadata.gz: d0d52868e2fad2b0af5d762cf8424c8db25452ebec7176a34c200557b4a6bb4b72e8c8d314910bbcb0fd2d732e2b80f76ff07365fb61ec46150f4aafdff18059
7
- data.tar.gz: d76133ccb760e0de761592be9f8a5c950ffad696213d0ae0ca01350f6d3ef6e5ed6df3c29bfb09e52e5b90b8d9a36398fd7be5846a9ce54a381230e7219abd44
6
+ metadata.gz: 4251fb1e5ea67b00c9e8281712f3bfe6a866c5ec2054c972de9be13d56939c3342e3cebc23a0cbe3164aa93b2fd6a59fa85de83487a8690413ebaad747b16ff1
7
+ data.tar.gz: b9900e07d2636efe47842bf2ca9b8a6445cdfe3cee1d9fb92149f9c7e6c80956081cf4bebce79be9245a7c7968892abbe6563af8df5b5ff762bfdb4fb680d4d4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Prawn::Markup
2
2
 
3
- [![Build Status](https://travis-ci.org/puzzle/prawn-markup.svg?branch=master)](https://travis-ci.org/puzzle/prawn-markup)
3
+ [![Build Status](https://github.com/puzzle/prawn-markup/actions/workflows/build.yml/badge.svg)](https://github.com/puzzle/prawn-markup/actions/workflows/build.yml)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/52a462f9d65e33352d4e/maintainability)](https://codeclimate.com/github/puzzle/prawn-markup/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/52a462f9d65e33352d4e/test_coverage)](https://codeclimate.com/github/puzzle/prawn-markup/test_coverage)
6
6
 
@@ -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
 
@@ -12,8 +12,11 @@ module Prawn
12
12
  end
13
13
 
14
14
  def start_img
15
+ src = current_attrs['src']
16
+ return if src.to_s.strip.empty?
17
+
15
18
  add_current_text
16
- add_image_or_placeholder(current_attrs['src'])
19
+ add_image_or_placeholder(src)
17
20
  end
18
21
 
19
22
  def start_iframe
@@ -70,7 +73,11 @@ module Prawn
70
73
 
71
74
  def load_remote_image(src)
72
75
  if src =~ %r{^https?:/}
73
- URI.parse(src).open
76
+ begin
77
+ URI.parse(src).open
78
+ rescue OpenURI::HTTPError, SocketError
79
+ nil
80
+ end
74
81
  end
75
82
  end
76
83
 
@@ -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'
10
10
  )
11
11
  end
12
12
 
@@ -78,6 +78,19 @@ 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
81
94
  end
82
95
  end
83
96
  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.2'
5
+ VERSION = '0.3.5'
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.2
4
+ version: 0.3.5
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: 2021-05-03 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -187,7 +187,7 @@ homepage: https://github.com/puzzle/prawn-markup
187
187
  licenses:
188
188
  - MIT
189
189
  metadata: {}
190
- post_install_message:
190
+ post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
193
193
  - lib
@@ -202,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubygems_version: 3.1.2
206
- signing_key:
205
+ rubygems_version: 3.1.4
206
+ signing_key:
207
207
  specification_version: 4
208
208
  summary: Parse simple HTML markup to include in Prawn PDFs
209
209
  test_files: []