o2html 0.1.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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/lib/o2html.rb +183 -0
  5. metadata +91 -0
  6. metadata.gz.sig +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87c96e43523965e570a314f599d88113b1ec56611a095bf5e89f7201306596c2
4
+ data.tar.gz: e4e46af79e7dd94426fbcfa32b953a65040062a17fa6c7a8cc9330d6ecf97972
5
+ SHA512:
6
+ metadata.gz: 58a5fbbee5793381d44b680edc428e3d96840e65b8b1408d5f6958e90814037e0c9e40ff4cb86c69ec0b39c20d5a742419eff225df91066e34d604b058381bbd
7
+ data.tar.gz: 6cbdf067bf851b77a278528310f90d8af130d0d9277bfa6329e0719c44e605427585a2f1f66ebe56ea76dba316a6b699dc3d9f4325b0b9fb42b5eb9030f9f1be
Binary file
@@ -0,0 +1,3 @@
1
+ Vr]Vj��k9�5��w��:�'ejq<���h &⺡E�(nf?�>܌ƥb��,����Ϛ�,&�\��~oa\�GPO�K`�八:BP�²��P
2
+ ����Q�Rxw�2XR"�:־�7�e� �90�>��>�{k�8Lɋ��-�o���K�]-.��a��e �S�Mc���-fh��@�bOZ��.O��
3
+ ɢ�YFu}�9.�x�Ġ������5�Ib3ImD�&H��;*���M�I��X��\��]��� 0�\��v���Ä6d�A~l�4�y��:z�`��" �!��ց|!��#���5Ƹ.4Tx�pD�>DZ@�g�I��k�md�Iӳ����-;~�܈6�[0G`���o]~(�/ ;�g�@D��.�z�
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: o2html.rb
4
+ # description: Transforms custom HTML objects to HTML elements and JavaScript objects. Experimental gem under development.
5
+
6
+
7
+ require 'rexle'
8
+ #require 'html-to-css'
9
+ require 'requestor'
10
+ eval Requestor.read('http://a0.jamesrobertson.eu/rorb/r/ruby'){|x| x.require 'html-to-css' }
11
+
12
+
13
+
14
+ class O2Html
15
+
16
+ class Div
17
+
18
+ def self.define(attr)
19
+
20
+ h = {}
21
+
22
+ if attr[:scroll] then
23
+ h = {style: 'overflow-y: scroll'}
24
+ attr.delete :scroll
25
+ end
26
+
27
+ ['div', h]
28
+
29
+ end
30
+ end
31
+
32
+ class InputBox
33
+
34
+ def self.define(attr)
35
+ ['input', {type: 'text'}]
36
+ end
37
+
38
+ def onenter()
39
+ puts 'onenter'
40
+ end
41
+ end
42
+
43
+ class Ajax
44
+ def onresponse()
45
+ puts 'inside onresponse'
46
+ end
47
+ def submit()
48
+ puts 'submit'
49
+ end
50
+ end
51
+
52
+ class SrButton
53
+
54
+ def self.define(attr)
55
+ ['button', {type: 'button'}]
56
+ end
57
+
58
+ def onresponse()
59
+ puts 'inside onresponse'
60
+ end
61
+ end
62
+
63
+ class Sound
64
+ end
65
+
66
+
67
+ def initialize(s, debug: false)
68
+
69
+ @s, @debug = s, debug
70
+
71
+ @lookup = {
72
+ div: Div,
73
+ inputbox: InputBox,
74
+ ajax: Ajax,
75
+ sr_button: SrButton,
76
+ sound: Sound
77
+ }
78
+
79
+ end
80
+
81
+ def to_css()
82
+ @css
83
+ end
84
+
85
+ def to_html()
86
+
87
+ userdoc = Rexle.new(@s)
88
+ e = userdoc.root.element('body/controls')
89
+ e.delete if e
90
+ doc = Rexle.new(scan2html(Rexle.new(userdoc.xml).to_a))
91
+
92
+ puts 'before htmltocss: ' + doc.xml.inspect if @debug
93
+ htc = HtmlToCss.new(doc.xml)
94
+ puts 'before to_css' if @debug
95
+ @css = htc.to_css
96
+ puts 'after htmltocss' if @debug
97
+
98
+ doc.root.each_recursive {|e| e.attributes.delete :style }
99
+
100
+ head = doc.root.element('head')
101
+
102
+ if not head then
103
+
104
+ head = Rexle::Element.new('head')
105
+ doc.root.element('body').insert_before head
106
+
107
+ end
108
+
109
+ style = Rexle::Element.new('style').add_text("\n" + @css + "\n\n")
110
+ head.add style
111
+
112
+ doc.xml pretty: true
113
+
114
+ end
115
+
116
+ def to_js()
117
+ end
118
+
119
+ def validate()
120
+
121
+ doc = Rexle.new(@s)
122
+ puts doc.root.element('body/script').xml
123
+
124
+ a = []
125
+ doc.root.each_recursive do |e|
126
+
127
+ type = e.attributes[:type]
128
+ next unless type
129
+ puts 'type: ' + type.inspect
130
+ puts 'e: ' + e.name if type
131
+ a << "#{e.name} = @lookup[:#{type.to_sym}].new"
132
+ end
133
+
134
+ scripts = doc.root.xpath('//script').map(&:text).join
135
+ a << scripts.gsub!(/_on/,'.on')
136
+
137
+ a << 'sr1_onresponse("fun")'.gsub(/_on/,'.on')
138
+ eval a.join("\n")
139
+ end
140
+
141
+
142
+ private
143
+
144
+ def scan2html(nodes)
145
+
146
+ if nodes.is_a?(Array) and nodes.first.is_a? Array then
147
+ nodes.map do |node|
148
+ scan2html(node)
149
+ end
150
+ elsif nodes.is_a? String
151
+ nodes
152
+ else
153
+ name, attr, val, *remaining = nodes
154
+
155
+ if attr and attr[:type] then
156
+
157
+ puts 'attr: ' + attr.inspect if @debug
158
+ attr ||= {}
159
+
160
+ attr[:id] = name
161
+ attr[:name] = name
162
+ name, attr2 = @lookup[attr[:type].to_sym].define(attr)
163
+
164
+ attr.merge!(attr2)
165
+
166
+ attr.delete :type
167
+ end
168
+
169
+ r = scan2html(remaining) if remaining and remaining.any?
170
+ [name, attr, val, *r].compact
171
+ end
172
+
173
+ end
174
+
175
+ end
176
+
177
+
178
+ if __FILE__ == $0 then
179
+
180
+ o2h = O2Html.new(ARGV[0])
181
+ o2h.validate
182
+
183
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: o2html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CER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G9w0BAQsFAAOCAYEAopLnQxI6OdhWEz9cMKOPkBSTlEv+7xVq5YmqW9as
29
+ ommCRxd+rxfqOalCDA+H8FXbKkmANLBtTApHVHNxU9fr43744QFbY/yiOVhFbgL5
30
+ zO2Ior1UeMJ0t9G/0gJJ05RaM5wb0qNy7Hy/IF5Xu9Rh5fwIf767PEfCtcLbn0rj
31
+ omILlhqSw8jrDZWDPEu8iz5Qu5lRGoP3xgqo1TFd2E1uypDY26DPf5+aGjGV5Ltx
32
+ rBsHnR186g2Xl19ovZsG7L/HjKaPjt2azx54Ys46gIbSHWyE9ih/QfFY5WSRa/B+
33
+ LtcaxKJPfTxWnqanKDA8fNexUTc9SDnNN7FLynzzPCo6pvQNlMGp8v/XBKIBMdab
34
+ s0MtnKIh/8mUPeioLlYmIJR22d10IIYqztTFM1frcKuJ48rN48rZJqD9qTEzDjEj
35
+ 7td+PDVolB3CzPyylPMFWJoQZwKpS8ArI6jmevrMPKTxzXObIcIijy2dLMLKKZL/
36
+ rzyo63G96DzUF4rq1zeDI9wG
37
+ -----END CERTIFICATE-----
38
+ date: 2020-07-10 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: html-to-css
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.1'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.10
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.1'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.1.10
60
+ description:
61
+ email: james@jamesrobertson.eu
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/o2html.rb
67
+ homepage: https://github.com/jrobertson/o2html
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: Experimental gem under development. Transforms custom HTML objects to HTML
90
+ elements and JavaScript objects.
91
+ test_files: []
Binary file