free_dom 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b25006295cb48501f306a796923819b86162ba2479c3daa84e490bc201d9364
4
+ data.tar.gz: 87796929372ea091459a75facb1a8d01b94d3368dbe8e99d6e37e4a8614b2149
5
+ SHA512:
6
+ metadata.gz: ec3355fdef23b6ff5d9c8c668db1a258dec3f4cd58cdd942e324e587f1b03729ae4f9d91a9df321ba4f2a97eb548da1565b881f5ad53c32d388fc8ad02e6e350
7
+ data.tar.gz: 850c75e8fa3fc0b91d13cd31d7702d311c9a6635bcbfe89ed6e8ac6ad2cb7a4767853dd0799511a4a550ae37d220ca210660587095b1489aa0c44a711635c7cf
Binary file
Binary file
@@ -0,0 +1,99 @@
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
+ h[e.name.to_sym] ||= {}
18
+ h[e.name.to_sym].merge!(e.attributes)
19
+ end
20
+
21
+ @defined_elements = {}
22
+
23
+ h.each do |name, attributelist|
24
+
25
+ klass = Class.new(Domle::Element) do
26
+
27
+ a = attributelist.keys
28
+
29
+ triggers = a.select {|x| x =~ /^trigger_/ }
30
+
31
+ attr2_accessor *(a - triggers)
32
+
33
+ triggers.each do |x|
34
+
35
+ trigger = x.to_s[/(?<=^trigger_).*/].to_sym
36
+ puts 'trigger: ' + trigger.inspect if @debug
37
+
38
+ define_method(trigger) do
39
+ eval method(('on' + trigger.to_s).to_sym).call, $env
40
+ end
41
+
42
+ if trigger == :change then
43
+
44
+ #puts 'change found'
45
+
46
+ attribute = attributelist[x].to_sym
47
+
48
+ define_method((attribute.to_s + '=').to_sym) do |val|
49
+ oldval = attributes[attribute]
50
+ attributes[attribute] = val
51
+ #puts 'inside change='
52
+ @rexle.refresh if @rexle
53
+ change() unless val == oldval
54
+ val
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ custom_class = FreeDom.const_set name.to_s.capitalize, klass
64
+ @defined_elements.merge!({name => custom_class})
65
+
66
+ end
67
+
68
+ # remove the trigger declaration attributes
69
+ @doc.root.each_recursive do |e|
70
+ e.attributes.keys.select {|x| x =~ /^trigger_/ }\
71
+ .each {|x| e.attributes.delete x }
72
+ end
73
+
74
+ super(@doc.root.xml)
75
+ script()
76
+
77
+ end
78
+
79
+
80
+ # used within the scope of the script tags
81
+ #
82
+ def doc()
83
+ self
84
+ end
85
+
86
+ def script()
87
+ s = @doc.root.xpath('//script').map {|x| x.text.unescape }.join
88
+ eval s
89
+ $env = binding
90
+ end
91
+
92
+
93
+ private
94
+
95
+ def defined_elements()
96
+ @defined_elements
97
+ end
98
+
99
+ end
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.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwNDI5MDAwMjU5WhcN
15
+ MjEwNDI5MDAwMjU5WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDJxo8z
17
+ LE3kbe2gTKh0kwQ5YsK7rW8RYTkDqV45vXNXJdVdPS+f6xkaABLZXTxkJ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V/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