free_dom 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 0b25006295cb48501f306a796923819b86162ba2479c3daa84e490bc201d9364
4
- data.tar.gz: 87796929372ea091459a75facb1a8d01b94d3368dbe8e99d6e37e4a8614b2149
3
+ metadata.gz: 40cbd83a7e122bdd21f6d29050f461007647ba5c30bf82bb381fb0631e08b677
4
+ data.tar.gz: ee9de9c48dd84e74d7a2baf4606c842ffef705be469c92f227931ab6623290c6
5
5
  SHA512:
6
- metadata.gz: ec3355fdef23b6ff5d9c8c668db1a258dec3f4cd58cdd942e324e587f1b03729ae4f9d91a9df321ba4f2a97eb548da1565b881f5ad53c32d388fc8ad02e6e350
7
- data.tar.gz: 850c75e8fa3fc0b91d13cd31d7702d311c9a6635bcbfe89ed6e8ac6ad2cb7a4767853dd0799511a4a550ae37d220ca210660587095b1489aa0c44a711635c7cf
6
+ metadata.gz: 1e9355485a6b657d33a4db93477ac70d0ba6df4e85cde5bfad9aa6aa4e1b3b240f853af58d11a4bef7d1a695b4c808d1da79cfc24ff804517220a38737c5d218
7
+ data.tar.gz: 1d2c09f362b8319ad5119d0c1b66ffac47cf8a08f0563c3f9b06d939489badaa1d5ac010104712475b13505dd890d86d16e2559ab330ffa0a73ed1d2fbe0fa08
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -14,7 +14,18 @@ class FreeDom < Domle
14
14
  h = {}
15
15
 
16
16
  @doc.root.each_recursive do |e|
17
+
17
18
  h[e.name.to_sym] ||= {}
19
+
20
+ # if there's a custom attribute, add a default trigger called trigger_change
21
+ a = e.attributes.keys.reject {|x| %i(id name class).include? x }
22
+ e.attributes.merge!({trigger_change: a.first}) if a.any?
23
+
24
+ # add a trigger attribute for each *on* event attribute
25
+ events = e.attributes.keys.select {|x| x =~ /^on/}\
26
+ .map {|x| 'trigger_' + x.to_s[/(?<=^on)\w+/]}
27
+ e.attributes.merge! events.zip(['']*events.length).to_h
28
+
18
29
  h[e.name.to_sym].merge!(e.attributes)
19
30
  end
20
31
 
@@ -26,9 +37,8 @@ class FreeDom < Domle
26
37
 
27
38
  a = attributelist.keys
28
39
 
29
- triggers = a.select {|x| x =~ /^trigger_/ }
30
-
31
- attr2_accessor *(a - triggers)
40
+ triggers = a.select {|x| x =~ /^trigger_/ }
41
+ attr2_accessor *((a - triggers) + %i(onchange)).uniq
32
42
 
33
43
  triggers.each do |x|
34
44
 
@@ -36,21 +46,22 @@ class FreeDom < Domle
36
46
  puts 'trigger: ' + trigger.inspect if @debug
37
47
 
38
48
  define_method(trigger) do
39
- eval method(('on' + trigger.to_s).to_sym).call, $env
49
+ statement = method(('on' + trigger.to_s).to_sym).call
50
+ eval statement, $env if statement
40
51
  end
41
52
 
42
- if trigger == :change then
43
-
44
- #puts 'change found'
53
+ if trigger == :change then
45
54
 
46
55
  attribute = attributelist[x].to_sym
47
56
 
48
57
  define_method((attribute.to_s + '=').to_sym) do |val|
58
+
49
59
  oldval = attributes[attribute]
50
60
  attributes[attribute] = val
51
- #puts 'inside change='
61
+
52
62
  @rexle.refresh if @rexle
53
63
  change() unless val == oldval
64
+
54
65
  val
55
66
  end
56
67
 
@@ -97,3 +108,4 @@ class FreeDom < Domle
97
108
  end
98
109
 
99
110
  end
111
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: free_dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file