prawn-svg 0.29.0 → 0.29.1

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: 11124a9218699a441e76a217c95fe1753777e96298f8d5ac4839cac9dc766705
4
- data.tar.gz: bc62cefeb7ffbceae1ddfe3f541a23ab7d7a16307b6666bc3c537fe839cd20c8
3
+ metadata.gz: 2dbf86f272347e8867b1e7262a49163c316d0160fc35802ceb1f7b0f8ed90e25
4
+ data.tar.gz: 4244134c0616eaf4aa9ca8ef19bbde2137e589d4f3929dd30b55c4c3d5136c36
5
5
  SHA512:
6
- metadata.gz: cd293d3c50672c0995c106295d9b83c1106261d02302c6f46a95e3d6f6e1f656685537ba69885aa171f615fb4bf1022f2499cfcf54f1b14588bf5776ca622077
7
- data.tar.gz: d4f103286a0090992d8608ff63e671a2879016f3f0f1713588634aba2b2fad6ac67f72b98dfec0d4d7ef737adc83078e36829ebad69e1655f1f2d9c4397dfbd5
6
+ metadata.gz: 3d1874a6766112c3084355c21b517b7a1d413f0e9e88c806cb236d69edc9fb7e1c3e253f13746c18e5e9b57d1221341d5c309494429dbae4a377ef91b99c8a52
7
+ data.tar.gz: bbd80743596ad9c2c25871c5c6542d2ddfb0c3026ac5d0efb61a894b501aabc6657e048f3d52b0b0e42e634e68b0d30f7e5096ce9bfdc81d4a7ffc7ac08d65e9
@@ -4,3 +4,5 @@ rvm:
4
4
  - 2.2.7
5
5
  - 2.3.3
6
6
  - 2.4.0
7
+ - 2.5.3
8
+ - 2.6.1
data/README.md CHANGED
@@ -107,6 +107,10 @@ In CSS selectors you can use element names, IDs, classes, attributes (existence,
107
107
  and all combinators (` `, `>`, `+`, `~`).
108
108
  The pseudo-classes `:first-child`, `:last-child` and `:nth-child(n)` (where n is a number) also work.
109
109
 
110
+ Warning: Ruby versions less than 2.6.0 have a bug in the REXML XPath implementation which means under some
111
+ conditions the `+` combinator will not pick up all matching elements. See `stylesheets_spec.rb` for an
112
+ explanation if you're stuck on an old version of Ruby.
113
+
110
114
  Pseudo-elements and the other pseudo-classes are not supported. Specificity ordering is
111
115
  implemented, but `!important` is not.
112
116
 
@@ -65,20 +65,48 @@ module Prawn::SVG::CSS
65
65
  def css_selector_to_xpath(selector)
66
66
  selector.map do |element|
67
67
  pseudo_classes = Set.new(element[:pseudo_class])
68
+ require_function_name = false
68
69
 
69
70
  result = case element[:combinator]
70
71
  when :child
71
- '/'
72
+ "/"
72
73
  when :adjacent
73
74
  pseudo_classes << 'first-child'
74
- '/following-sibling::'
75
+ "/following-sibling::"
75
76
  when :siblings
76
- '/following-sibling::'
77
+ "/following-sibling::"
77
78
  else
78
- '//'
79
+ "//"
79
80
  end
80
81
 
81
- result << element[:name] if element[:name]
82
+ positions = []
83
+ pseudo_classes.each do |pc|
84
+ case pc
85
+ when "first-child" then positions << '1'
86
+ when "last-child" then positions << 'last()'
87
+ when /^nth-child\((\d+)\)$/ then positions << $1
88
+ end
89
+ end
90
+
91
+ if !positions.empty?
92
+ result << "*" unless require_function_name
93
+ require_function_name = true
94
+
95
+ logic = if positions.length == 1
96
+ positions.first
97
+ else
98
+ positions.map { |position| "position()=#{position}" }.join(" and ")
99
+ end
100
+
101
+ result << "[#{logic}]"
102
+ end
103
+
104
+ if require_function_name
105
+ result << "[name()=#{xpath_quote element[:name]}]" if element[:name]
106
+ else
107
+ result << (element[:name] || '*')
108
+ end
109
+
82
110
  result << ((element[:class] || []).map { |name| "[contains(concat(' ',@class,' '), ' #{name} ')]" }.join)
83
111
  result << ((element[:id] || []).map { |name| "[@id='#{name}']" }.join)
84
112
 
@@ -101,14 +129,6 @@ module Prawn::SVG::CSS
101
129
  end
102
130
  end
103
131
 
104
- pseudo_classes.each do |pc|
105
- case pc
106
- when "first-child" then result << "[1]"
107
- when "last-child" then result << "[last()]"
108
- when /^nth-child\((\d+)\)$/ then result << "[#{$1}]"
109
- end
110
- end
111
-
112
132
  result
113
133
  end.join
114
134
  end
@@ -85,7 +85,7 @@ module Prawn::SVG::Loaders
85
85
  end
86
86
 
87
87
  def assert_valid_file_uri!(uri)
88
- if uri.host
88
+ unless uri.host.nil? || uri.host.empty?
89
89
  raise Prawn::SVG::UrlLoader::Error, "prawn-svg does not suport file: URLs with a host. Your URL probably doesn't start with three slashes, and it should."
90
90
  end
91
91
  end
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.29.0'
3
+ VERSION = '0.29.1'
4
4
  end
5
5
  end
@@ -6,7 +6,6 @@ Gem::Specification.new do |gem|
6
6
  gem.version = Prawn::SVG::VERSION
7
7
  gem.summary = "SVG renderer for Prawn PDF library"
8
8
  gem.description = "This gem allows you to render SVG directly into a PDF using the 'prawn' gem. Since PDF is vector-based, you'll get nice scaled graphics if you use SVG instead of an image."
9
- gem.has_rdoc = false
10
9
  gem.author = "Roger Nesbitt"
11
10
  gem.email = "roger@seriousorange.com"
12
11
  gem.homepage = "http://github.com/mogest/prawn-svg"
@@ -11,6 +11,7 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
11
11
  rect { fill: #ff0000; }
12
12
  rect ~ rect { fill: #330000; }
13
13
  rect + rect { fill: #440000; }
14
+ rect:first-child:last-child { fill: #441234; }
14
15
 
15
16
  circle:first-child { fill: #550000; }
16
17
  circle:nth-child(2) { fill: #660000; }
@@ -37,9 +38,13 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
37
38
  <rect width="6" height="6" />
38
39
  </g>
39
40
 
40
- <circle width="7" />
41
- <circle width="8" />
42
- <circle width="9" />
41
+ <circle width="100" />
42
+
43
+ <g id="circles">
44
+ <circle width="7" />
45
+ <circle width="8" />
46
+ <circle width="9" />
47
+ </g>
43
48
  </g>
44
49
 
45
50
  <square width="10" chocolate="hi there" />
@@ -56,13 +61,35 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
56
61
  result = Prawn::SVG::CSS::Stylesheets.new(CssParser::Parser.new, REXML::Document.new(svg)).load
57
62
  width_and_styles = result.map { |k, v| [k.attributes["width"].to_i, v] }.sort_by(&:first)
58
63
 
59
- expect(width_and_styles).to eq [
64
+ expected = [
60
65
  [1, [["fill", "#ff0000", false]]],
61
66
  [2, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#220000", false]]],
62
67
  [3, [["fill", "#ff0000", false], ["fill", "#00ff00", false]]],
63
68
  [4, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]],
64
- [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#00ff00", false]]],
65
- [6, [["fill", "#ff0000", false], ["fill", "#0000ff", false]]],
69
+ ]
70
+
71
+ #
72
+ # Under ruby < 2.6, a bug in REXML causes the /following-sibling selector to
73
+ # only pick the first matching sibling. This means the + CSS combinator behaves
74
+ # incorrectly in the following example:
75
+ #
76
+ # <a>
77
+ # <b a="1" />
78
+ # <b a="2" />
79
+ # <b a="3" />
80
+ # </a>
81
+ #
82
+ # The css selector `a b + b` will only pick the second <b>, whereas it should
83
+ # pick both the second and third <b> elements.
84
+ #
85
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
86
+ expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#00ff00", false]]]
87
+ else
88
+ expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]]
89
+ end
90
+
91
+ expected.concat [
92
+ [6, [["fill", "#ff0000", false], ["fill", "#441234", false], ["fill", "#0000ff", false]]],
66
93
  [7, [["fill", "#550000", false]]],
67
94
  [8, [["fill", "#660000", false]]],
68
95
  [9, [["fill", "#770000", false]]],
@@ -74,6 +101,8 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
74
101
  [15, [["fill", "#dd0000", false]]],
75
102
  [16, [["fill", "#ee0000", false]]],
76
103
  ]
104
+
105
+ expect(width_and_styles).to eq(expected)
77
106
  end
78
107
  end
79
108
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.29.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-05 00:00:00.000000000 Z
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -250,8 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  - !ruby/object:Gem::Version
251
251
  version: '0'
252
252
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.7.6
253
+ rubygems_version: 3.0.1
255
254
  signing_key:
256
255
  specification_version: 4
257
256
  summary: SVG renderer for Prawn PDF library