svgle 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -1
  4. data/lib/svgle.rb +47 -24
  5. metadata +21 -1
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebac10f7f16a51fdc11cb47d10722df139a6ad6e
4
- data.tar.gz: c193058e7416fec69057dff1a4b6d1d8d0425bad
3
+ metadata.gz: d994517953a3e97d2db065bce4ed869a6c079f7a
4
+ data.tar.gz: 3d09ccfdfe4c55b63d74f0b119f3bd8c6b1b20bd
5
5
  SHA512:
6
- metadata.gz: b502b25bc97c7143935a5a2af502136c4fd4972d585404d2889f980db1b8c2db11a36c47662f0ec897f035c09c896a1f60c6ad4235989b52c960d3e287498e51
7
- data.tar.gz: 7436b3233067e7d5a94ed37fe58135661b26c40d1cd48b45f84cd247e05da5b557990b09dd805c3d36b6b7be76f7d33e23884ddbf0434cc6f51c6a37ce2b801a
6
+ metadata.gz: a8279f4ab5a081f25e068eec462aa3515595f5d22db7212fb265a3f63fd9107d14f609bb07a01f410b4fe1e19e6a12955bf6d9d2d3867a2e22a2177c9468862f
7
+ data.tar.gz: af1c29186fa99368c38de63d006ca0f8dc8fb21f9842e2ea88327c8ef52d59b742ea7614d396cbc8246122abdb04876f5a7d611ac3ae326166d307c72e7b4fb2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- #�<;%��,��<�7�N��g }N���,q��� s��u�ަgn��"�����y{����P9afl���ά�0�+�c'�NP!��zG��jʽ�vj���`�.8���%6��@njd�}��4$Y��q��t��JJ�gX
1
+ ��ߔ8��;�ej"���'�~�������o3[�1f��og�Z98�Nl�cɸ$�$NM�=�Y��ndcL�>�@hD辰��2�0/�"R�𾖽)���y�w�nj�k�� 7�?ZM!�YG�����f/t�̙�kh�w�����@�������U�`)-�і0�<� ��v�P@��|��zV�� ����A}H��X��6%�%+}xw��|��.B?�����5�r�q��
data/lib/svgle.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # file: svgle.rb
4
4
 
5
5
  require 'rexle'
6
+ require 'rxfhelper'
6
7
 
7
8
  # helpful SVG element references:
8
9
  #
@@ -62,10 +63,11 @@ class Svgle < Rexle
62
63
 
63
64
  class Element < Rexle::Element
64
65
 
65
- def initialize(name=nil, value: nil, attributes: Attributes.new(parent: self), rexle: nil)
66
+ def initialize(name=nil, value: nil, \
67
+ attributes: Attributes.new(parent: self), rexle: nil)
68
+
66
69
  super(name, value: value, attributes: attributes, rexle: rexle)
67
70
 
68
- @boundary_box = [[0,0,0,0]]
69
71
  end
70
72
 
71
73
  def self.attr2_accessor(*a)
@@ -177,6 +179,7 @@ class Svgle < Rexle
177
179
  end
178
180
 
179
181
  class Style < Element
182
+
180
183
 
181
184
  end
182
185
 
@@ -197,8 +200,8 @@ class Svgle < Rexle
197
200
 
198
201
 
199
202
  def initialize(x=nil, callback: nil)
200
- super x
201
- add_css()
203
+ super x
204
+ find_add_css()
202
205
  @callback = callback
203
206
  end
204
207
 
@@ -212,34 +215,54 @@ class Svgle < Rexle
212
215
 
213
216
  private
214
217
 
215
- def add_css()
218
+ def find_add_css()
216
219
 
217
- @doc.root.xpath('//style').each do |e|
218
-
219
- # parse the CSS
220
-
221
- a = e.text.split(/}/)[0..-2].map do |entry|
220
+ @doc.root.xpath('//style').each {|e| add_css e.text }
222
221
 
223
- raw_selector,raw_styles = entry.split(/{/,2)
222
+ # check for an external CSS file
223
+ if @instructions and @instructions.any? then
224
224
 
225
- h = raw_styles.split(/;/).inject({}) do |r, x|
226
- k, v = x.split(/:/,2).map(&:strip)
227
- r.merge(k.to_sym => v)
228
- end
225
+ hrefs = @instructions.inject([]) do |r,x|
229
226
 
230
- [raw_selector.split(/,\s*/).map(&:strip), h]
231
- end
227
+ if x[0] =~ /xml-stylesheet/i and x[1] =~ /text\/css/i then
232
228
 
233
-
234
- # add the CSS style attributes to the element
235
- # e.g. a = [[['line'],{stroke: 'green'}]]
236
-
237
- a.each do |selectors, style|
238
- selectors.each do |selector|
239
- style.each {|k,v| self.at_css(selector).style[k] = v }
229
+ r << x[1][/href\s*=\s*["']([^'"]+)/,1]
230
+ else
231
+ r
240
232
  end
241
233
  end
242
234
 
235
+ add_css hrefs.map{|x| RXFHelper.read(x).first}.join
236
+
237
+ end
238
+
239
+
240
+ end
241
+
242
+ def add_css(s)
243
+
244
+ # parse the CSS
245
+
246
+ a = s.split(/}/)[0..-2].map do |entry|
247
+
248
+ raw_selector,raw_styles = entry.split(/{/,2)
249
+
250
+ h = raw_styles.split(/;/).inject({}) do |r, x|
251
+ k, v = x.split(/:/,2).map(&:strip)
252
+ r.merge(k.to_sym => v)
253
+ end
254
+
255
+ [raw_selector.split(/,\s*/).map(&:strip), h]
256
+ end
257
+
258
+
259
+ # add each CSS style attribute to the element
260
+ # e.g. a = [[['line'],{stroke: 'green'}]]
261
+
262
+ a.each do |selectors, style|
263
+ selectors.each do |selector|
264
+ style.each {|k,v| self.at_css(selector).style[k] = v }
265
+ end
243
266
  end
244
267
 
245
268
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -53,6 +53,26 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.3.9
56
+ - !ruby/object:Gem::Dependency
57
+ name: rxfhelper
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.2.3
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.2'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.3
56
76
  description:
57
77
  email: james@r0bertson.co.uk
58
78
  executables: []
metadata.gz.sig CHANGED
Binary file