domle 0.4.0 → 0.5.3

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 +0 -0
  4. data/lib/domle.rb +112 -29
  5. metadata +20 -20
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1603ab1131e919539aca6ca3ea4bc45088d811a09fdf623f4ce587c00998205
4
- data.tar.gz: 9d05226c9c07646e789c4194ca77091a06cd718861ac117bf27db4f98180a4b7
3
+ metadata.gz: 2d512c1472aa41ac55fe92d96e214fa1445fb3a98ae0744756c81557440e63e6
4
+ data.tar.gz: c5208b775e3158e858dfc38b6a6d1c352224b300979bdf5bac6d50ea872b4e1e
5
5
  SHA512:
6
- metadata.gz: 51433b3b698d31a7e40133f2155624fa1d92825d79f8b401a1cf90d7d540850022ae1e288bee39065415980685309bdb24589bf8b27e62d2cef2a087ce5f1500
7
- data.tar.gz: 9ce9647e9fa15e1de9939fae49208a6bf7aebc11f5dad2a07b69606fd4e4a224746e528af79cc1331701a8702146739e9e8ab496b08dcb14809b387d71f2e1f9
6
+ metadata.gz: 7fb4ab6bf36510479f860dfa4c242e605a1a14312147a5932bfcd5c66f00a1a77921152d40ff182daa348d06c45d23a3c8aa52baa8016beb81ee874122fa66b0
7
+ data.tar.gz: dca8f1a4803c9a6364c6f26b64d4a895abffc0b6b0bba5ec9ca8703fefbe5af76cd3dd7d261c2e1b2bb73e2aa1411100b136e9b9dbf4f37be93d9d1ed896302d
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -20,7 +20,10 @@ class Style < Hash
20
20
 
21
21
  super(k,v)
22
22
  @parent[:style] = self.map{|x| x.join(':') }.join(';')
23
- @parent.callback.refresh if @parent.callback
23
+
24
+ if @parent.callback and @parent.callback.respond_to? :refresh then
25
+ @parent.callback.refresh
26
+ end
24
27
 
25
28
  end
26
29
  end
@@ -54,12 +57,30 @@ class VisualAttributes < Attributes
54
57
  end
55
58
 
56
59
  class Domle < Rexle
60
+ using ColouredText
57
61
 
58
62
  class Element < Rexle::Element
63
+
64
+
65
+ class ClassList
66
+
67
+ def initialize(a, rexle, node)
68
+ @a, @rexle, @node = a, rexle, node
69
+ end
70
+
71
+ def toggle(name)
72
+ @a.include?(name) ? @a.delete(name) : @a << name
73
+ puts '@rexle?: ' + @rexle.inspect if @debug
74
+ @rexle.refresh_css(@node) if @rexle
75
+ end
76
+ end
59
77
 
60
78
  @default = {}
79
+ @attr_map = {}
80
+ attr_reader :attr_map
81
+
61
82
  def initialize(name=self.class.to_s.downcase[/\w+$/], value: nil, \
62
- attributes: VisualAttributes.new(parent: self), rexle: nil)
83
+ attributes: {}, rexle: nil)
63
84
 
64
85
  attributes.merge!(style: '') unless attributes.has_key? :style
65
86
  super(name, value: value, attributes: VisualAttributes.new(attributes), rexle: rexle)
@@ -83,12 +104,26 @@ class Domle < Rexle
83
104
 
84
105
  define_method (attribute.to_s + '=').to_sym do |val|
85
106
  attributes[attribute] = val
86
- @rexle.refresh if @rexle
107
+ rexle().refresh if rexle?
108
+ attr_update(attribute, val)
87
109
  val
88
110
  end
89
111
 
90
112
  end
91
113
  end
114
+
115
+ def rexle?()
116
+ not @rexle.nil?
117
+ end
118
+
119
+ def rexle()
120
+ @rexle
121
+ end
122
+
123
+ end
124
+
125
+ def self.attr_mapper(h)
126
+ @attr_map = h
92
127
  end
93
128
 
94
129
  def active?()
@@ -102,12 +137,12 @@ class Domle < Rexle
102
137
  def classlist()
103
138
 
104
139
  a = attributes[:class]
140
+ cl = ClassList.new(a, @rexle, self)
105
141
 
106
- def a.toggle(name)
107
- self.include?(name) ? self.delete(name) : self << name
108
- end
142
+
109
143
 
110
- return a
144
+
145
+ return cl
111
146
  end
112
147
 
113
148
  def style()
@@ -122,6 +157,24 @@ class Domle < Rexle
122
157
  (x1..x2).include? x and (y1..y2).include? y
123
158
  end
124
159
  end
160
+
161
+ def obj=(v)
162
+ @obj = v
163
+ end
164
+
165
+ def obj()
166
+ @obj
167
+ end
168
+
169
+
170
+ private
171
+
172
+ def attr_update(name, val)
173
+ return unless @attr_map
174
+ puts 'inside attr_update, @attr_map: ' + @attr_map.inspect if @debug
175
+ name = (@attr_map[name].to_s + '=').to_sym
176
+ @obj.method(name).call(val) if @obj.respond_to? name
177
+ end
125
178
  end
126
179
 
127
180
  class Script < Element
@@ -135,32 +188,56 @@ class Domle < Rexle
135
188
 
136
189
  attr_reader :event
137
190
 
138
- def initialize(x='<svg/>', callback: nil, rexle: self, debug: false)
191
+ def initialize(src='<svg/>', callback: nil, rexle: nil, debug: false)
192
+
193
+ @callback, @debug, @rexle = callback, debug, rexle
194
+ puts 'inside Domle initialize'.info if @debug
195
+ puts 'src:' + src.inspect if @debug
196
+
197
+ super(RXFHelper.read(src).first, rexle: self)
198
+ @debug = debug
199
+
200
+ puts 'before find add_css' if @debug
201
+ find_add_css() if src
139
202
 
140
- super RXFHelper.read(x).first, rexle: rexle
141
- find_add_css() if x
142
- @callback, @debug = callback, debug
143
203
 
144
204
  @event = {
145
- keydown: []
205
+ keydown: [],
206
+ keyup: [],
207
+ mousemove: [],
208
+ mousedown: [],
209
+ mouseenter: [],
210
+ mouseleave: [],
211
+ scroll: []
146
212
  }
147
213
 
148
214
  end
149
215
 
150
216
  def addevent_listener(event, method_name)
151
217
 
152
- @event[:keydown] << method_name
218
+ @event[event.to_sym] << method_name
153
219
 
154
220
  end
155
221
 
156
222
 
157
223
  def element_by_id(id)
158
224
  @doc.root.element("//*[@id='#{id}']")
159
- end
225
+ end
160
226
 
227
+ def elements_by_name(name)
228
+ @doc.root.xpath("//*[@name='#{name}']")
229
+ end
230
+
231
+ def elements_by_tagname(name)
232
+ @doc.root.xpath("//#{name}")
233
+ end
161
234
 
162
235
  def refresh()
163
- @callback.refresh if @callback
236
+ @callback.refresh if @callback and @callback.respond_to? :refresh
237
+ end
238
+
239
+ def refresh_css(node)
240
+ find_add_css(node.parent)
164
241
  end
165
242
 
166
243
  protected
@@ -168,7 +245,7 @@ class Domle < Rexle
168
245
  def add_default_css()
169
246
  end
170
247
 
171
- def add_external_css()
248
+ def add_external_css(node=nil)
172
249
 
173
250
  # check for an external CSS file
174
251
  if @instructions and @instructions.any? then
@@ -183,29 +260,35 @@ class Domle < Rexle
183
260
  end
184
261
  end
185
262
 
186
- add_css hrefs.map{|x| RXFHelper.read(x).first}.join
263
+ add_css hrefs.map{|x| RXFHelper.read(x).first}.join, node
187
264
 
188
265
  end
189
266
 
190
267
  end
191
268
 
192
- def add_inline_css()
193
- @doc.root.xpath('//style').each {|e| add_css e.text }
269
+ def add_inline_css(node=nil)
270
+ puts 'inside add_inline_css' if @debug
271
+ @doc.root.xpath('//style').each {|e| add_css e.text.to_s, node }
194
272
  end
195
273
 
196
- def find_add_css()
197
- add_default_css()
198
- add_inline_css()
199
- add_external_css()
200
- end
274
+ def find_add_css(node=nil)
275
+
276
+ puts 'inside find_add_css' if @debug
277
+ add_default_css() unless node
278
+ add_inline_css(node)
279
+ add_external_css(node)
280
+ end
201
281
 
202
282
  private
203
283
 
204
- def add_css(s, override: true)
205
-
206
- css = CSSLite.new s
207
- css.propagate self.root
208
-
284
+ def add_css(s, node=@doc, override: true)
285
+
286
+ puts 'add_css s: ' + s.inspect if @debug
287
+ css = CSSLite.new s, debug: @debug
288
+ node ||= @doc
289
+ puts 'before propagate node: ' + node.inspect if @debug
290
+ css.propagate node
291
+ puts node.xml if @debug
209
292
  end
210
293
 
211
294
  # override this method in your own class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ewt0cFO7UqEB/yC8KNeXJjd19INo+w98LYjFZQEzLAg15Sz7ca5bUbr/LuYQUk4y
36
36
  Lvi3w1KUp4YuUbhbhnEQXuPH
37
37
  -----END CERTIFICATE-----
38
- date: 2020-05-01 00:00:00.000000000 Z
38
+ date: 2020-08-31 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '1.5'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.5.15
49
+ version: 1.5.6
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,47 +56,47 @@ dependencies:
56
56
  version: '1.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.15
59
+ version: 1.5.6
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: csslite
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '0.1'
67
64
  - - ">="
68
65
  - !ruby/object:Gem::Version
69
- version: 0.1.3
66
+ version: 0.2.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.2'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '0.1'
77
74
  - - ">="
78
75
  - !ruby/object:Gem::Version
79
- version: 0.1.3
76
+ version: 0.2.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.2'
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rxfhelper
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - "~>"
85
- - !ruby/object:Gem::Version
86
- version: '0.9'
87
84
  - - ">="
88
85
  - !ruby/object:Gem::Version
89
- version: 0.9.4
86
+ version: 1.0.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.9'
97
94
  - - ">="
98
95
  - !ruby/object:Gem::Version
99
- version: 0.9.4
96
+ version: 1.0.0
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.0'
100
100
  description:
101
101
  email: james@jamesrobertson.eu
102
102
  executables: []
metadata.gz.sig CHANGED
Binary file