svgle 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 735387a31aa3a8f3f0c94d85245c1a5b4cf04a4c
4
- data.tar.gz: 14992ed09ea03bb29aa0bf4c92b8ac6aaa6c1845
3
+ metadata.gz: ebac10f7f16a51fdc11cb47d10722df139a6ad6e
4
+ data.tar.gz: c193058e7416fec69057dff1a4b6d1d8d0425bad
5
5
  SHA512:
6
- metadata.gz: 807a97089d5543c86d62a6509aa907c126b507b58d136bf76ae05bbf47632c577547768ba94ea1bf833e21bba5be0614d58af9ff582cc5fae00bf205541aaee1
7
- data.tar.gz: d40d7cc82298ba522f72902aa695f0e7636fc7f148c3b43843629f3c9a9ae6ac4dae2ab02c3c038e5ece1f79d953c9a2165845b664281bd913543161edb95883
6
+ metadata.gz: b502b25bc97c7143935a5a2af502136c4fd4972d585404d2889f980db1b8c2db11a36c47662f0ec897f035c09c896a1f60c6ad4235989b52c960d3e287498e51
7
+ data.tar.gz: 7436b3233067e7d5a94ed37fe58135661b26c40d1cd48b45f84cd247e05da5b557990b09dd805c3d36b6b7be76f7d33e23884ddbf0434cc6f51c6a37ce2b801a
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/svgle.rb CHANGED
@@ -176,6 +176,11 @@ class Svgle < Rexle
176
176
 
177
177
  end
178
178
 
179
+ class Style < Element
180
+
181
+ end
182
+
183
+
179
184
  class Svg < Element
180
185
  attr2_accessor *%i(width height)
181
186
  def boundary()
@@ -191,14 +196,53 @@ class Svgle < Rexle
191
196
  end
192
197
 
193
198
 
194
- def initialize(x=nil,callback: nil)
199
+ def initialize(x=nil, callback: nil)
195
200
  super x
201
+ add_css()
196
202
  @callback = callback
197
203
  end
198
204
 
205
+ def inspect()
206
+ "#<Svgle:%s>" % [self.object_id]
207
+ end
208
+
199
209
  def refresh()
200
210
  @callback.refresh if @callback
201
211
  end
212
+
213
+ private
214
+
215
+ def add_css()
216
+
217
+ @doc.root.xpath('//style').each do |e|
218
+
219
+ # parse the CSS
220
+
221
+ a = e.text.split(/}/)[0..-2].map do |entry|
222
+
223
+ raw_selector,raw_styles = entry.split(/{/,2)
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
229
+
230
+ [raw_selector.split(/,\s*/).map(&:strip), h]
231
+ end
232
+
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 }
240
+ end
241
+ end
242
+
243
+ end
244
+
245
+ end
202
246
 
203
247
  def scan_element(name, attributes=nil, *children)
204
248
 
@@ -212,6 +256,7 @@ class Svgle < Rexle
212
256
  g: Svgle::G,
213
257
  svg: Svgle::Svg,
214
258
  script: Svgle::Script,
259
+ style: Svgle::Style,
215
260
  doc: Rexle::Element,
216
261
  polygon: Svgle::Polygon,
217
262
  polyline: Svgle::Polyline,
data.tar.gz.sig CHANGED
Binary file
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.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -83,7 +83,6 @@ rubyforge_project:
83
83
  rubygems_version: 2.4.8
84
84
  signing_key:
85
85
  specification_version: 4
86
- summary: "*Experimental gem under development.* Svgle (SVG + Rexle) generates an SVG
87
- Document Object Model from the given SVG. Suitable for accessing, or modifying SVG
88
- elements as objects."
86
+ summary: Svgle (SVG + Rexle) generates an SVG Document Object Model from the given
87
+ SVG. Suitable for accessing, or modifying SVG elements as objects.
89
88
  test_files: []
metadata.gz.sig CHANGED
Binary file