free_dom 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/free_dom.rb +123 -0
- metadata +110 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b331adf1af2368386b05b4d365a943d57b8252339d4af17ea5631b9f07894e36
|
4
|
+
data.tar.gz: fa9403708d030f64da8b68195d6af5819a713599070a86c5dac1752c83f3fc80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a53b324b2126265b880d82ea254f952b33632c4bf94b4f7288542c0a7fd55217bf1beaa404042625712f346a7b8d21cfdf8c026ec8e50e4138dbce87bb6a7d4b
|
7
|
+
data.tar.gz: 01acf8d7577c0ac0153b074173fd7b5747629b74dea36ef48fb4d72a93b3a0d49a3b10769fed8f8eb261dc5472cc2a8bc6f85b1c228e198d6e19d18de1b1a439
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/free_dom.rb
ADDED
@@ -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).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.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
|
+
cnRzb24vREM9ZXUwggGiM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PRI5PEjl5Q/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: []
|
metadata.gz.sig
ADDED
Binary file
|