prawn-markup 0.3.0 → 0.3.4

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: 3e42ddd575822d3805d7edb1525124617db37098e35ad139a2fed48824d08790
4
- data.tar.gz: feb4ae593f40ebb09875ff2e4e9158ee4de7856980cf90e602103855d9bb47ad
3
+ metadata.gz: a5217761bc64b6cf5ae6697d326934a9b87d3e54a3a65428f9c7025d3a03f043
4
+ data.tar.gz: c3274d3dfd6ab699f4d9fe17db8148305c9b4c4c7da8cd3b2a8b834735380583
5
5
  SHA512:
6
- metadata.gz: c13137a43fb81062dd27fcc0492d9d910f7244bf8841cda87c690bc36ad8a17434e783a864874e56cdeea90e7a4eff49b242c9f62d72a318a869110d2a393848
7
- data.tar.gz: f43d2499d55744f2e973a11ea9add7c254b283eee5639d29aa043f2b600d40a00fc52b4087c7bf7012d9eba502d9ab36a4da6b5f10484bdc9eb91e703dd1a23f
6
+ metadata.gz: 728da10a3ce7d80aca95a3b9d54d9122c9c791567ab150188c6f459bb0de15863524322d091ed01900e844661aa0e5337542fd191f03eb97d080e27b905cc394
7
+ data.tar.gz: c701c14bcc7fd0baa8cb17179f5096caef7a8f8ce829f8d548d9667d5ce78f2ec2248a1848eca32e01cb0e52e94befb0a845a9d6da0f14c851fb195420e9c90f
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
 
@@ -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
@@ -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
 
@@ -34,13 +34,13 @@ module Prawn
34
34
  alias end_ul end_list
35
35
 
36
36
  def start_li
37
- return unless inside_container?
37
+ return unless current_list
38
38
 
39
39
  current_list.items << Elements::Item.new
40
40
  end
41
41
 
42
42
  def end_li
43
- return unless inside_container?
43
+ return unless current_list
44
44
 
45
45
  add_cell_text_node(current_list_item)
46
46
  end
@@ -67,7 +67,9 @@ module Prawn
67
67
  end
68
68
 
69
69
  def current_list_item
70
- current_list.items.last
70
+ items = current_list.items
71
+ items << Elements::Item.new if items.empty?
72
+ items.last
71
73
  end
72
74
 
73
75
  def inside_container?
@@ -39,6 +39,7 @@ module Prawn
39
39
  prepend Prawn::Markup::Processor::Lists
40
40
 
41
41
  def initialize(pdf, options = {})
42
+ super()
42
43
  @pdf = pdf
43
44
  @options = options
44
45
  end
@@ -52,10 +53,8 @@ module Prawn
52
53
  end
53
54
 
54
55
  def start_element(name, attrs = [])
55
- stack.push(name: name, attrs: Hash[attrs])
56
- if self.class.known_elements.include?(name)
57
- send("start_#{name}") if respond_to?("start_#{name}", true)
58
- end
56
+ stack.push(name: name, attrs: attrs.to_h)
57
+ send("start_#{name}") if known_element?(name) && respond_to?("start_#{name}", true)
59
58
  end
60
59
 
61
60
  def end_element(name)
@@ -69,11 +68,11 @@ module Prawn
69
68
  end
70
69
 
71
70
  def error(string)
72
- logger.info('SAX parsing error: ' + string.strip) if logger
71
+ logger.info("SAX parsing error: #{string.strip}") if logger
73
72
  end
74
73
 
75
74
  def warning(string)
76
- logger.info('SAX parsing warning: ' + string.strip) if logger
75
+ logger.info("SAX parsing warning: #{string.strip}") if logger
77
76
  end
78
77
 
79
78
  private
@@ -85,6 +84,10 @@ module Prawn
85
84
  @text_buffer = +''
86
85
  end
87
86
 
87
+ def known_element?(name)
88
+ self.class.known_elements.include?(name)
89
+ end
90
+
88
91
  def append_text(string)
89
92
  text_buffer.concat(string)
90
93
  end
@@ -122,8 +125,7 @@ module Prawn
122
125
  def style_properties
123
126
  style = current_attrs['style']
124
127
  if style
125
- tokens = style.split(';').map { |p| p.split(':', 2).map(&:strip) }
126
- Hash[tokens]
128
+ style.split(';').map { |p| p.split(':', 2).map(&:strip) }.to_h
127
129
  else
128
130
  {}
129
131
  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.0'
5
+ VERSION = '0.3.4'
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.0
4
+ version: 0.3.4
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: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2022-01-10 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.0.6
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: []