domle 0.1.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/lib/domle.rb +204 -0
- data.tar.gz.sig +3 -0
- metadata +107 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b669ac04fc6c2f2b7cb65e5bede13659a1af8fb8
|
4
|
+
data.tar.gz: 43f8dd92c69ead467c7b8fd2e8c26e981f8720e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41407e72d054a16ce636d3ce1756d20e5413e947058e4a07f2d0c5ad7005639d2e6b1c43f69901839508a57cbeba0045c3520f73a10723e158f489944afb2492
|
7
|
+
data.tar.gz: 3f7ad78ef84fad0336336553d585b569a0fbf876e676bad5149b8aa928d75470ad246c93f2b5811b6d6f19d34ef88a571ffa39f3da0aaba236ff49d77f4a86e5
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/lib/domle.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: domle.rb
|
4
|
+
|
5
|
+
require 'rexle'
|
6
|
+
require 'rxfhelper'
|
7
|
+
|
8
|
+
|
9
|
+
class Style < Hash
|
10
|
+
|
11
|
+
def initialize(parent, h)
|
12
|
+
@parent = parent
|
13
|
+
|
14
|
+
super().merge! h
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(k,v)
|
19
|
+
|
20
|
+
super(k,v)
|
21
|
+
@parent[:style] = self.map{|x| x.join(':') }.join(';')
|
22
|
+
@parent.callback.refresh
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Attributes
|
28
|
+
|
29
|
+
attr_reader :callback
|
30
|
+
|
31
|
+
def initialize(parent: nil)
|
32
|
+
@callback = parent
|
33
|
+
end
|
34
|
+
|
35
|
+
def style(parent=nil)
|
36
|
+
|
37
|
+
@callback ||= parent
|
38
|
+
|
39
|
+
if @style.nil? then
|
40
|
+
|
41
|
+
h = self[:style].split(';').inject({}) do |r, x|
|
42
|
+
k, v = x.split(':',2)
|
43
|
+
r.merge(k.to_sym => v)
|
44
|
+
end
|
45
|
+
|
46
|
+
@style = Style.new(self, h)
|
47
|
+
|
48
|
+
end
|
49
|
+
@style
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class Domle < Rexle
|
55
|
+
|
56
|
+
class Element < Rexle::Element
|
57
|
+
|
58
|
+
def initialize(name=nil, value: nil, \
|
59
|
+
attributes: Attributes.new(parent: self), rexle: nil)
|
60
|
+
|
61
|
+
attributes.merge!(style: '') unless attributes.has_key? :style
|
62
|
+
super(name, value: value, attributes: attributes, rexle: rexle)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.attr2_accessor(*a)
|
67
|
+
|
68
|
+
a.concat %i(id transform)
|
69
|
+
a.concat %i(onmousemove onmousedown) # DOM events
|
70
|
+
|
71
|
+
a.each do |attribute|
|
72
|
+
|
73
|
+
class_eval do
|
74
|
+
|
75
|
+
define_method attribute.to_s.gsub('-','_').to_sym do
|
76
|
+
attributes[attribute]
|
77
|
+
end
|
78
|
+
|
79
|
+
define_method (attribute.to_s + '=').to_sym do |val|
|
80
|
+
attributes[attribute] = val
|
81
|
+
@rexle.refresh
|
82
|
+
val
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def style()
|
90
|
+
attributes.style(@rexle)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def hotspot?(x,y)
|
95
|
+
|
96
|
+
(boundary.first.is_a?(Array) ? boundary : [boundary]).all? do |box|
|
97
|
+
x1, y1, x2, y2 = box
|
98
|
+
(x1..x2).include? x and (y1..y2).include? y
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Script < Element
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
class Style < Element
|
108
|
+
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
def initialize(x=nil, callback: nil)
|
113
|
+
super x
|
114
|
+
find_add_css()
|
115
|
+
@callback = callback
|
116
|
+
end
|
117
|
+
|
118
|
+
def refresh()
|
119
|
+
@callback.refresh if @callback
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def add_css(s)
|
125
|
+
|
126
|
+
# parse the CSS
|
127
|
+
|
128
|
+
a = s.split(/}/)[0..-2].map do |entry|
|
129
|
+
|
130
|
+
raw_selector,raw_styles = entry.split(/{/,2)
|
131
|
+
|
132
|
+
h = raw_styles.split(/;/).inject({}) do |r, x|
|
133
|
+
k, v = x.split(/:/,2).map(&:strip)
|
134
|
+
r.merge(k.to_sym => v)
|
135
|
+
end
|
136
|
+
|
137
|
+
[raw_selector.split(/,\s*/).map(&:strip), h]
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# add each CSS style attribute to the element
|
142
|
+
# e.g. a = [[['line'],{stroke: 'green'}]]
|
143
|
+
|
144
|
+
a.each do |x|
|
145
|
+
|
146
|
+
selectors, style = x
|
147
|
+
|
148
|
+
selectors.each do |selector|
|
149
|
+
|
150
|
+
style.each do |k,v|
|
151
|
+
self.css(selector).each {|element| element.style[k] = v }
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
def defined_elements()
|
160
|
+
|
161
|
+
# override this method in your own class
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
def scan_element(name, attributes=nil, *children)
|
166
|
+
|
167
|
+
return Rexle::CData.new(children.first) if name == '!['
|
168
|
+
return Rexle::Comment.new(children.first) if name == '!-'
|
169
|
+
|
170
|
+
type = defined_elements()
|
171
|
+
|
172
|
+
element = type[name.to_sym].new(name, attributes: attributes, rexle: self)
|
173
|
+
|
174
|
+
if children then
|
175
|
+
|
176
|
+
children.each do |x|
|
177
|
+
if x.is_a? Array then
|
178
|
+
|
179
|
+
element.add_element scan_element(*x)
|
180
|
+
elsif x.is_a? String then
|
181
|
+
|
182
|
+
e = if x.is_a? String then
|
183
|
+
|
184
|
+
x
|
185
|
+
elsif x.name == '![' then
|
186
|
+
|
187
|
+
Rexle::CData.new(x)
|
188
|
+
|
189
|
+
elsif x.name == '!-' then
|
190
|
+
|
191
|
+
Rexle::Comment.new(x)
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
element.add_element e
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
return element
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: domle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE1MTEyNTA3MDI0NFoXDTE2MTEyNDA3MDI0NFowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBAMN/NpuJ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000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rexle
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.3'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.9
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.3'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
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
|
76
|
+
description:
|
77
|
+
email: james@r0bertson.co.uk
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- lib/domle.rb
|
83
|
+
homepage: https://github.com/jrobertson/domle
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.4.8
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: The document object model used by the Svgle gem
|
107
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|