free_dom 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 40cbd83a7e122bdd21f6d29050f461007647ba5c30bf82bb381fb0631e08b677
4
+ data.tar.gz: ee9de9c48dd84e74d7a2baf4606c842ffef705be469c92f227931ab6623290c6
5
+ SHA512:
6
+ metadata.gz: 1e9355485a6b657d33a4db93477ac70d0ba6df4e85cde5bfad9aa6aa4e1b3b240f853af58d11a4bef7d1a695b4c808d1da79cfc24ff804517220a38737c5d218
7
+ data.tar.gz: 1d2c09f362b8319ad5119d0c1b66ffac47cf8a08f0563c3f9b06d939489badaa1d5ac010104712475b13505dd890d86d16e2559ab330ffa0a73ed1d2fbe0fa08
Binary file
Binary file
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: free_dom.rb
4
+
5
+ require 'domle'
6
+
7
+
8
+ class FreeDom < Domle
9
+
10
+ def initialize(xml, debug: false)
11
+
12
+ @doc, @debug = Rexle.new(xml), debug
13
+
14
+ h = {}
15
+
16
+ @doc.root.each_recursive do |e|
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
+
29
+ h[e.name.to_sym].merge!(e.attributes)
30
+ end
31
+
32
+ @defined_elements = {}
33
+
34
+ h.each do |name, attributelist|
35
+
36
+ klass = Class.new(Domle::Element) do
37
+
38
+ a = attributelist.keys
39
+
40
+ triggers = a.select {|x| x =~ /^trigger_/ }
41
+ attr2_accessor *((a - triggers) + %i(onchange)).uniq
42
+
43
+ triggers.each do |x|
44
+
45
+ trigger = x.to_s[/(?<=^trigger_).*/].to_sym
46
+ puts 'trigger: ' + trigger.inspect if @debug
47
+
48
+ define_method(trigger) do
49
+ statement = method(('on' + trigger.to_s).to_sym).call
50
+ eval statement, $env if statement
51
+ end
52
+
53
+ if trigger == :change then
54
+
55
+ attribute = attributelist[x].to_sym
56
+
57
+ define_method((attribute.to_s + '=').to_sym) do |val|
58
+
59
+ oldval = attributes[attribute]
60
+ attributes[attribute] = val
61
+
62
+ @rexle.refresh if @rexle
63
+ change() unless val == oldval
64
+
65
+ val
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ custom_class = FreeDom.const_set name.to_s.capitalize, klass
75
+ @defined_elements.merge!({name => custom_class})
76
+
77
+ end
78
+
79
+ # remove the trigger declaration attributes
80
+ @doc.root.each_recursive do |e|
81
+ e.attributes.keys.select {|x| x =~ /^trigger_/ }\
82
+ .each {|x| e.attributes.delete x }
83
+ end
84
+
85
+ super(@doc.root.xml)
86
+ script()
87
+
88
+ end
89
+
90
+
91
+ # used within the scope of the script tags
92
+ #
93
+ def doc()
94
+ self
95
+ end
96
+
97
+ def script()
98
+ s = @doc.root.xpath('//script').map {|x| x.text.unescape }.join
99
+ eval s
100
+ $env = binding
101
+ end
102
+
103
+
104
+ private
105
+
106
+ def defined_elements()
107
+ @defined_elements
108
+ end
109
+
110
+ end
111
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: free_dom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNy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zE+YM9RaSa35qnfSPUR1omNs
30
+ /Jl8KmKdgHiCvcFI0+Q7kSX1xrNgdcEaUcutvHgY4Wg5hW04cC2QPRI5PEjl5Q/4
31
+ HzUsuWKv8oP3ulRUg2z97x4TVyewO7HJ9n0swcim4uieLQHc/t/VL8KQ8Ynx1T2M
32
+ 5+McK4ekR1ed0QY8vM/zp4hsvKByre05f2XVRxe37YjPpS9xP+JGfoKU8KG+mlWt
33
+ L6oTXKicNcV/O9GCnVPArudFdeOAAvEGI2izAUI42nMPpu7rgNEPzjrLIQ4qsMFJ
34
+ 4DK35MuFK8T+fQUKswdRSdOTJsKbggzHYbZMoMiKPui5jjoucWoWhGc+jZg9SdO7
35
+ VxSuuHhAXplX7wWmd1FzAAH5bk4OPlKGt5fxQbax+FSoEzTsnoDcLTY2i0WOxwRo
36
+ 76nAi+UZoU87S6brj88/rtOL
37
+ -----END CERTIFICATE-----
38
+ date: 2020-04-30 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: domle
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.3'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.3.1
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.3'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.3.1
60
+ description:
61
+ email: james@jamesrobertson.eu
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/free_dom.rb
67
+ homepage: https://github.com/jrobertson/free_dom
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Dynamically builds a DOM from XML.
90
+ test_files: []
Binary file