free_dom 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ec91ddff5c295dbb9b06b4c0abaa02fcfad8dc763cf5d8b75ec54f4c73293d7
4
+ data.tar.gz: 22a422768d58c6e362145640379a037ef763517103022db716258bec08af3329
5
+ SHA512:
6
+ metadata.gz: 7a6536d5f6d10bb3baa4016e96e079fc725dab51bc6aa36ece18d65d29f6f442c01d275300ca73c5a62bfb09f4e5d9d795cbb758a0e031fadbfbc2822f763072
7
+ data.tar.gz: 9e5a63d0dc4864d7e89aa044df12ebcbacccb7c4e9a4855d32b8a93377aa2f9da3ef12ad78e93db427abc9de3373865dac07a0a046b0e20a3a779ef36dfa2358
Binary file
Binary file
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: free_dom.rb
4
+
5
+ require 'domle'
6
+ require 'xml_to_sliml'
7
+
8
+
9
+ class FreeDom < Domle
10
+
11
+ def initialize(s, debug: false)
12
+
13
+ @debug = debug
14
+
15
+ xml = s =~ /^</ ? s : LineTree.new(s).to_xml
16
+ @doc = Rexle.new(xml)
17
+
18
+ h = {}
19
+
20
+ @doc.root.each_recursive do |e|
21
+
22
+ h[e.name.to_sym] ||= {}
23
+
24
+ # if there's a custom attribute, add a default trigger called trigger_change
25
+ a = e.attributes.keys.reject {|x| %i(id name class style).include? x }
26
+ e.attributes.merge!({trigger_change: a.first}) if a.any?
27
+
28
+ # add a trigger attribute for each *on* event attribute
29
+ events = e.attributes.keys.select {|x| x =~ /^on/}\
30
+ .map {|x| 'trigger_' + x.to_s[/(?<=^on)\w+/]}
31
+ e.attributes.merge! events.zip(['']*events.length).to_h
32
+
33
+ h[e.name.to_sym].merge!(e.attributes)
34
+ end
35
+
36
+ @defined_elements = {}
37
+
38
+ h.each do |name, attributelist|
39
+
40
+ klass = Class.new(Domle::Element) do
41
+
42
+ a = attributelist.keys
43
+
44
+ triggers = a.select {|x| x =~ /^trigger_/ }
45
+ attr2_accessor *((a - triggers) + %i(onchange)).uniq
46
+
47
+ triggers.each do |x|
48
+
49
+ trigger = x.to_s[/(?<=^trigger_).*/].to_sym
50
+ puts 'trigger: ' + trigger.inspect if @debug
51
+
52
+ define_method(trigger) do
53
+ statement = method(('on' + trigger.to_s).to_sym).call
54
+ eval statement, $env if statement
55
+ end
56
+
57
+ if trigger == :change then
58
+
59
+ attribute = attributelist[x].to_sym
60
+
61
+ define_method((attribute.to_s + '=').to_sym) do |val|
62
+
63
+ oldval = attributes[attribute]
64
+ attributes[attribute] = val
65
+
66
+ @rexle.refresh if @rexle
67
+ change() unless val == oldval
68
+
69
+ val
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ custom_class = FreeDom.const_set name.to_s.capitalize, klass
79
+ @defined_elements.merge!({name => custom_class})
80
+
81
+ end
82
+
83
+ # remove the trigger declaration attributes
84
+ @doc.root.each_recursive do |e|
85
+ e.attributes.keys.select {|x| x =~ /^trigger_/ }\
86
+ .each {|x| e.attributes.delete x }
87
+ end
88
+
89
+ super(@doc.root.xml, debug: @debug)
90
+ script()
91
+
92
+ end
93
+
94
+
95
+ # used within the scope of the script tags
96
+ #
97
+ def doc()
98
+ self
99
+ end
100
+
101
+ def script()
102
+ s = @doc.root.xpath('//script').map {|x| x.text.unescape }.join
103
+ eval s
104
+ $env = binding
105
+ end
106
+
107
+ def to_sliml()
108
+
109
+ xml = @doc.root.element('*').xml(pretty: true)
110
+ puts 'xml: ' + xml.inspect if @debug
111
+ XmlToSliml.new(xml.gsub(/ style=''/,"")).to_s
112
+
113
+ end
114
+
115
+
116
+ private
117
+
118
+ def defined_elements()
119
+ @defined_elements
120
+ end
121
+
122
+ end
123
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: free_dom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire: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RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAcIlboY8Gudv/UW9j4CvT0bXK3lJ/qg/nnE0vqiKP
29
+ +ror3CE2vG0bN5J1ia7VZgepPMt55f4eMfFdYKcCzE+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-05-02 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.4'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.4.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.4'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.4.1
60
+ - !ruby/object:Gem::Dependency
61
+ name: xml_to_sliml
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.1'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.1.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.1'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.1.2
80
+ description:
81
+ email: james@jamesrobertson.eu
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/free_dom.rb
87
+ homepage: https://github.com/jrobertson/free_dom
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Dynamically builds a DOM from XML.
110
+ test_files: []
@@ -0,0 +1,3 @@
1
+ ��M;�5`լ7��o���ਉ���rC��|CX����9.��,��{�VԮ�Q���.��ڃ��b���~B_z�rHH��wW�ș��}��&u5��qn���"�2wM�JX�+�.�d��)x�����l�����/�4ւ{��
2
+ aMG�t?��S(�d��QF+j̯?xG�ՆCg^T\o�k� 1��:(Ӯ/�6�=1륙Z+��Ɂ9�E<�U_T�L3�s�������[x&�@a�ۿm$��]:����W;��伶�T6�o�����
3
+ N�m%˫o|<L�4T9`��J�i� x��Gz<�p�ů�Dx��Ժ��̑�vy��>�;�ڤ��