apphttp 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/apphttp.rb +4 -156
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0c94ce7dd13c76a44ea9acc3c9daf9b1233471ee468e8a19186916fa32c3534
|
4
|
+
data.tar.gz: 486b7a1fe36388ee94fbfe5329efe52073ca9481821e693957d48c73cbba1cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e8dd863f91ae0c7b4d9a879e8994001dd4b77aed621cb3834bde3c1cf4a385dc3c62a866176fad7e70171225798f466ef42c1c517a658f3269b5a066d21e45
|
7
|
+
data.tar.gz: 38e3cb606a4c0b03c00598b8f65e9c2b1e9b9f59003df57512345fb93e465e54b5ca2fd24c9af8d902fe469571b5b92e224119120dce52edca32bc6516d36742
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/apphttp.rb
CHANGED
@@ -5,9 +5,7 @@
|
|
5
5
|
# desc: Makes it trivial to web enable a Ruby project
|
6
6
|
|
7
7
|
require 'socket'
|
8
|
-
require '
|
9
|
-
require 'c32'
|
10
|
-
require 'kramdown'
|
8
|
+
require 'apphtml_layer'
|
11
9
|
|
12
10
|
|
13
11
|
class AppHttp
|
@@ -18,6 +16,8 @@ class AppHttp
|
|
18
16
|
|
19
17
|
@app, @host, @port, @debug = app, host, port, debug
|
20
18
|
@filepath, @headings = filepath, headings
|
19
|
+
@ah = AppHtmlLayer.new(app, filepath: filepath, headings: headings,
|
20
|
+
debug: debug)
|
21
21
|
|
22
22
|
end
|
23
23
|
|
@@ -55,158 +55,6 @@ class AppHttp
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def get(s)
|
58
|
-
|
59
|
-
if s == '/' then
|
60
|
-
|
61
|
-
fp = File.join(@filepath, 'index.html')
|
62
|
-
return (File.exists?(fp) ? File.read(fp) : default_index() )
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
return [s.to_s, 'text/plain'] if s =~ /^\/\w+\.\w+/
|
67
|
-
|
68
|
-
args = []
|
69
|
-
|
70
|
-
if s.count('/') > 1 then
|
71
|
-
|
72
|
-
name, args = *s.split('/')[1..-1]
|
73
|
-
|
74
|
-
else
|
75
|
-
puts ('s: ' + s.inspect).debug if @debug
|
76
|
-
name, raw_params = s[/(?<=^\/).*/].split('?',2)
|
77
|
-
|
78
|
-
if raw_params then
|
79
|
-
|
80
|
-
puts ('raw_params: ' + raw_params.inspect).debug if @debug
|
81
|
-
raw_pairs = raw_params.split('&')
|
82
|
-
|
83
|
-
h = raw_pairs.inject({}) do |r,x|
|
84
|
-
key,value = x.split('=',2)
|
85
|
-
r.merge(key.to_sym => value) if value
|
86
|
-
end
|
87
|
-
|
88
|
-
return unless h
|
89
|
-
|
90
|
-
h2 = h.inject({}) do |r,x|
|
91
|
-
|
92
|
-
if x.first.to_s =~ /^arg/ then
|
93
|
-
args << x.last
|
94
|
-
else
|
95
|
-
r.merge!(x.first => x.last)
|
96
|
-
end
|
97
|
-
r
|
98
|
-
end
|
99
|
-
|
100
|
-
args << h2 if h2.any?
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
if @app.respond_to? name.to_sym then
|
107
|
-
|
108
|
-
begin
|
109
|
-
|
110
|
-
method = @app.method(name.to_sym)
|
111
|
-
|
112
|
-
if method.arity > 0 and args.length <= 0 then
|
113
|
-
r = "
|
114
|
-
<form action='#{name}'>
|
115
|
-
<input type='text' name='arg'></input>
|
116
|
-
<input type='submit'/>
|
117
|
-
</form>"
|
118
|
-
else
|
119
|
-
r = method.call(*args)
|
120
|
-
end
|
121
|
-
|
122
|
-
fp = File.join(@filepath, File.basename(name) + '.html')
|
123
|
-
|
124
|
-
content = if File.exists?(fp) then
|
125
|
-
render_html(fp, r)
|
126
|
-
else
|
127
|
-
|
128
|
-
if @headings then
|
129
|
-
markdown = "
|
130
|
-
# #{name.capitalize}
|
131
|
-
|
132
|
-
<output>#{r}</output>
|
133
|
-
"
|
134
|
-
|
135
|
-
Kramdown::Document.new(markdown).to_html
|
136
|
-
else
|
137
|
-
|
138
|
-
r
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
rescue
|
145
|
-
content = ($!).inspect
|
146
|
-
end
|
147
|
-
|
148
|
-
case content.class.to_s
|
149
|
-
when "String"
|
150
|
-
media = content.lstrip[0] == '<' ? 'html' : 'plain'
|
151
|
-
[content, 'text/' + media]
|
152
|
-
when "Hash"
|
153
|
-
[content.to_json,'application/json']
|
154
|
-
else
|
155
|
-
[content.to_s, 'text/plain']
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
58
|
+
@ah.lookup s
|
159
59
|
end
|
160
|
-
|
161
|
-
def default_index()
|
162
|
-
|
163
|
-
a = (@app.public_methods - Object.public_methods).sort
|
164
|
-
s = a.map {|x| "* [%s](%s)" % [x,x]}.join("\n")
|
165
|
-
|
166
|
-
markdown = "
|
167
|
-
<html>
|
168
|
-
<head>
|
169
|
-
<title>#{@app.class.to_s}</title>
|
170
|
-
<style>
|
171
|
-
h1 {color: green}
|
172
|
-
h2 {color: orange}
|
173
|
-
div {height: 60%; overflow-y: auto; width: 200px; float: left}
|
174
|
-
</style>
|
175
|
-
</head>
|
176
|
-
<body markdown='1'>
|
177
|
-
|
178
|
-
# #{@app.class.to_s} Index
|
179
|
-
|
180
|
-
## Public Methods
|
181
|
-
|
182
|
-
<div markdown='1'>
|
183
|
-
#{s}
|
184
|
-
</div>
|
185
|
-
<iframe name='i1'></iframe>
|
186
|
-
<div style='clear: both' />
|
187
|
-
<hr/>
|
188
|
-
</body>
|
189
|
-
</html>
|
190
|
-
"
|
191
|
-
#markdown = s
|
192
|
-
doc = Rexle.new(Kramdown::Document.new(markdown).to_html)
|
193
|
-
|
194
|
-
doc.root.xpath('body/div/ul/li/a') do |link|
|
195
|
-
link.attributes[:target] = 'i1'
|
196
|
-
end
|
197
|
-
|
198
|
-
[doc.xml(pretty: true), 'text/html']
|
199
|
-
end
|
200
|
-
|
201
|
-
def render_html(fp, s)
|
202
|
-
|
203
|
-
doc = Rexle.new(File.read fp)
|
204
|
-
e = doc.root.element('//[@class="output"]')
|
205
|
-
e.text = s
|
206
|
-
|
207
|
-
|
208
|
-
doc.xml pretty: true
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apphttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
fhU7xyc9cI6elrvCBt5DlvbaQn1ZdmYHfPPe4BgcB7hg9ADcQubuuZJy+KvRZADs
|
36
36
|
h/GUx4K959hkyRunR+SmqC7C
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-10-
|
38
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: apphtml_layer
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 0.1.0
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '0.1'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 0.1.0
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '0.1'
|
60
60
|
description:
|
61
61
|
email: james@jamesrobertson.eu
|
62
62
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|