svgle 0.3.1 → 0.4.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/svgle.rb +7 -187
- metadata +8 -28
- 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: 20edf14e1fb2d867c4cc15a5eef5a2fd53d1b9d7
|
4
|
+
data.tar.gz: 9d3ed5fcec3fa4f14b77e7dfde8f78212efde32b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d01e7ac7d6037c76ce75b8c885944348efee357be0f065f634e2abc27930a63a5c1f33eb1550de77b6d74ecaa2476bfab74abf5aef164b6865d273f1e817d3f
|
7
|
+
data.tar.gz: 53a60916562462ad76b01acb4473c313cc573a4fc54726a5afb93e528961afe953a8d5071ebd2707a0210f962ed27a17785bd31ba0c3a27fc1d3674cbc0b7a05
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/svgle.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
# file: svgle.rb
|
4
4
|
|
5
|
-
require '
|
6
|
-
|
5
|
+
require 'domle'
|
6
|
+
|
7
7
|
|
8
8
|
# helpful SVG element references:
|
9
9
|
#
|
@@ -25,100 +25,10 @@ text {fill: red}
|
|
25
25
|
|
26
26
|
CSS
|
27
27
|
|
28
|
-
class Style < Hash
|
29
|
-
|
30
|
-
def initialize(parent, h)
|
31
|
-
@parent = parent
|
32
|
-
|
33
|
-
super().merge! h
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def []=(k,v)
|
38
|
-
|
39
|
-
super(k,v)
|
40
|
-
@parent[:style] = self.map{|x| x.join(':') }.join(';')
|
41
|
-
@parent.callback.refresh
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Attributes
|
47
|
-
|
48
|
-
attr_reader :callback
|
49
|
-
|
50
|
-
def initialize(parent: nil)
|
51
|
-
@callback = parent
|
52
|
-
end
|
53
|
-
|
54
|
-
def style(parent=nil)
|
55
|
-
|
56
|
-
@callback ||= parent
|
57
|
-
|
58
|
-
if @style.nil? then
|
59
|
-
|
60
|
-
h = self[:style].split(';').inject({}) do |r, x|
|
61
|
-
k, v = x.split(':',2)
|
62
|
-
r.merge(k.to_sym => v)
|
63
|
-
end
|
64
|
-
|
65
|
-
@style = Style.new(self, h)
|
66
|
-
|
67
|
-
end
|
68
|
-
@style
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
28
|
|
73
29
|
|
74
|
-
class Svgle <
|
30
|
+
class Svgle < Domle
|
75
31
|
|
76
|
-
class Element < Rexle::Element
|
77
|
-
|
78
|
-
def initialize(name=nil, value: nil, \
|
79
|
-
attributes: Attributes.new(parent: self), rexle: nil)
|
80
|
-
|
81
|
-
attributes.merge!(style: '') unless attributes.has_key? :style
|
82
|
-
super(name, value: value, attributes: attributes, rexle: rexle)
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.attr2_accessor(*a)
|
87
|
-
|
88
|
-
a.concat %i(id transform)
|
89
|
-
a.concat %i(onmousemove onmousedown) # DOM events
|
90
|
-
|
91
|
-
a.each do |attribute|
|
92
|
-
|
93
|
-
class_eval do
|
94
|
-
|
95
|
-
define_method attribute.to_s.gsub('-','_').to_sym do
|
96
|
-
attributes[attribute]
|
97
|
-
end
|
98
|
-
|
99
|
-
define_method (attribute.to_s + '=').to_sym do |val|
|
100
|
-
attributes[attribute] = val
|
101
|
-
@rexle.refresh
|
102
|
-
val
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def style()
|
110
|
-
attributes.style(@rexle)
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
def hotspot?(x,y)
|
115
|
-
|
116
|
-
(boundary.first.is_a?(Array) ? boundary : [boundary]).all? do |box|
|
117
|
-
x1, y1, x2, y2 = box
|
118
|
-
(x1..x2).include? x and (y1..y2).include? y
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
32
|
|
123
33
|
class A < Element
|
124
34
|
# undecided how to implement this
|
@@ -185,18 +95,8 @@ class Svgle < Rexle
|
|
185
95
|
[x1, y1, x1+w, y1+h]
|
186
96
|
end
|
187
97
|
|
188
|
-
end
|
189
|
-
|
190
|
-
class Script < Element
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
class Style < Element
|
195
|
-
|
196
|
-
|
197
98
|
end
|
198
99
|
|
199
|
-
|
200
100
|
class Svg < Element
|
201
101
|
attr2_accessor *%i(width height background-color)
|
202
102
|
def boundary()
|
@@ -210,21 +110,11 @@ class Svgle < Rexle
|
|
210
110
|
[0,0,0,0]
|
211
111
|
end
|
212
112
|
end
|
213
|
-
|
214
|
-
|
215
|
-
def initialize(x=nil, callback: nil)
|
216
|
-
super x
|
217
|
-
find_add_css()
|
218
|
-
@callback = callback
|
219
|
-
end
|
220
113
|
|
221
114
|
def inspect()
|
222
115
|
"#<Svgle:%s>" % [self.object_id]
|
223
116
|
end
|
224
117
|
|
225
|
-
def refresh()
|
226
|
-
@callback.refresh if @callback
|
227
|
-
end
|
228
118
|
|
229
119
|
private
|
230
120
|
|
@@ -253,50 +143,10 @@ class Svgle < Rexle
|
|
253
143
|
|
254
144
|
end
|
255
145
|
|
256
|
-
|
257
146
|
end
|
258
147
|
|
259
|
-
def
|
260
|
-
|
261
|
-
# parse the CSS
|
262
|
-
|
263
|
-
a = s.split(/}/)[0..-2].map do |entry|
|
264
|
-
|
265
|
-
raw_selector,raw_styles = entry.split(/{/,2)
|
266
|
-
|
267
|
-
h = raw_styles.split(/;/).inject({}) do |r, x|
|
268
|
-
k, v = x.split(/:/,2).map(&:strip)
|
269
|
-
r.merge(k.to_sym => v)
|
270
|
-
end
|
271
|
-
|
272
|
-
[raw_selector.split(/,\s*/).map(&:strip), h]
|
273
|
-
end
|
274
|
-
|
275
|
-
|
276
|
-
# add each CSS style attribute to the element
|
277
|
-
# e.g. a = [[['line'],{stroke: 'green'}]]
|
278
|
-
|
279
|
-
a.each do |x|
|
280
|
-
|
281
|
-
selectors, style = x
|
282
|
-
|
283
|
-
selectors.each do |selector|
|
284
|
-
|
285
|
-
style.each do |k,v|
|
286
|
-
self.css(selector).each {|element| element.style[k] = v }
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
end
|
293
|
-
|
294
|
-
def scan_element(name, attributes=nil, *children)
|
295
|
-
|
296
|
-
return Rexle::CData.new(children.first) if name == '!['
|
297
|
-
return Rexle::Comment.new(children.first) if name == '!-'
|
298
|
-
|
299
|
-
type = {
|
148
|
+
def defined_elements()
|
149
|
+
{
|
300
150
|
circle: Svgle::Circle,
|
301
151
|
ellipse: Svgle::Ellipse,
|
302
152
|
line: Svgle::Line,
|
@@ -310,37 +160,7 @@ class Svgle < Rexle
|
|
310
160
|
path: Svgle::Path,
|
311
161
|
rect: Svgle::Rect,
|
312
162
|
text: Svgle::Text
|
313
|
-
}
|
314
|
-
|
315
|
-
element = type[name.to_sym].new(name, attributes: attributes, rexle: self)
|
316
|
-
|
317
|
-
if children then
|
318
|
-
|
319
|
-
children.each do |x|
|
320
|
-
if x.is_a? Array then
|
321
|
-
|
322
|
-
element.add_element scan_element(*x)
|
323
|
-
elsif x.is_a? String then
|
324
|
-
|
325
|
-
e = if x.is_a? String then
|
326
|
-
|
327
|
-
x
|
328
|
-
elsif x.name == '![' then
|
329
|
-
|
330
|
-
Rexle::CData.new(x)
|
331
|
-
|
332
|
-
elsif x.name == '!-' then
|
333
|
-
|
334
|
-
Rexle::Comment.new(x)
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
element.add_element e
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
return element
|
163
|
+
}
|
344
164
|
end
|
345
165
|
|
346
|
-
end
|
166
|
+
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,48 +31,28 @@ cert_chain:
|
|
31
31
|
RmHuiq+pC3w5bbeKAS7PA41oFYzip80UozdgPsTbPSjT38fz3RwuIKWLTG0zOXty
|
32
32
|
rUf4C1wr3bOSgQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-11-
|
34
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: domle
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1
|
42
|
+
version: '0.1'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 0.1.0
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1
|
52
|
+
version: '0.1'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
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
|
55
|
+
version: 0.1.0
|
76
56
|
description:
|
77
57
|
email: james@r0bertson.co.uk
|
78
58
|
executables: []
|
@@ -103,6 +83,6 @@ rubyforge_project:
|
|
103
83
|
rubygems_version: 2.4.8
|
104
84
|
signing_key:
|
105
85
|
specification_version: 4
|
106
|
-
summary: Svgle (SVG +
|
86
|
+
summary: Svgle (SVG + Domle) generates an SVG Document Object Model from the given
|
107
87
|
SVG. Suitable for accessing, or modifying SVG elements as objects.
|
108
88
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|