svgle 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -1
- data/lib/svgle.rb +47 -24
- metadata +21 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d994517953a3e97d2db065bce4ed869a6c079f7a
|
4
|
+
data.tar.gz: 3d09ccfdfe4c55b63d74f0b119f3bd8c6b1b20bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8279f4ab5a081f25e068eec462aa3515595f5d22db7212fb265a3f63fd9107d14f609bb07a01f410b4fe1e19e6a12955bf6d9d2d3867a2e22a2177c9468862f
|
7
|
+
data.tar.gz: af1c29186fa99368c38de63d006ca0f8dc8fb21f9842e2ea88327c8ef52d59b742ea7614d396cbc8246122abdb04876f5a7d611ac3ae326166d307c72e7b4fb2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
��ߔ8��;�e�j�"���'�~�������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@��|��z�V������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,
|
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
|
-
|
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
|
218
|
+
def find_add_css()
|
216
219
|
|
217
|
-
@doc.root.xpath('//style').each
|
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
|
-
|
222
|
+
# check for an external CSS file
|
223
|
+
if @instructions and @instructions.any? then
|
224
224
|
|
225
|
-
|
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
|
-
[
|
231
|
-
end
|
227
|
+
if x[0] =~ /xml-stylesheet/i and x[1] =~ /text\/css/i then
|
232
228
|
|
233
|
-
|
234
|
-
|
235
|
-
|
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.
|
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
|