apphtml_layer 0.1.0 → 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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/apphtml_layer.rb +88 -20
- metadata +23 -4
- 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: 895fab8f277c269d759859a4449cf9ed1f3ce395846239a0617a175f6392fb03
|
4
|
+
data.tar.gz: 0f50045c40962bc85b6455d737920f79835f58c41372c76bb7aa3af4c8702380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d2f12a0f3a86693a72d07d9e4824f9bfa79b62aa38b49eceb8ed30a776f1ffdcf6b49c4533d0004bcc2581c44808605446fb1dad988c399c0fb1bd747947a1
|
7
|
+
data.tar.gz: e8ae9e4c1c7be589843f1a753143c10722d311c3782123acbe8181cbf5b01ac6c68094069084b8cdb7542176a0c65a0707deceb8bb68a0021760e6f82f7607fb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/apphtml_layer.rb
CHANGED
@@ -3,33 +3,74 @@
|
|
3
3
|
# file: apphtml_layer.rb
|
4
4
|
|
5
5
|
require 'uri'
|
6
|
-
require 'json'
|
7
6
|
require 'c32'
|
7
|
+
require 'json'
|
8
|
+
require 'hpath'
|
8
9
|
require 'kramdown'
|
9
10
|
|
11
|
+
|
12
|
+
module HashPath
|
13
|
+
|
14
|
+
refine Hash do
|
15
|
+
|
16
|
+
def path(s)
|
17
|
+
Hpath.get(self, s)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
10
24
|
class AppHtmlLayer
|
25
|
+
using HashPath
|
11
26
|
using ColouredText
|
27
|
+
|
28
|
+
attr_reader :apps
|
12
29
|
|
13
|
-
def initialize(
|
14
|
-
|
30
|
+
def initialize(apps={}, filepath: '.', headings: false, debug: false)
|
31
|
+
|
32
|
+
@apps = if apps.is_a? Hash
|
33
|
+
apps
|
34
|
+
else
|
35
|
+
{apps.class.to_s.downcase.to_sym => apps}
|
36
|
+
end
|
37
|
+
|
38
|
+
@filepath, @headings, @debug = filepath, headings, debug
|
39
|
+
|
15
40
|
end
|
16
41
|
|
17
42
|
def lookup(s)
|
18
43
|
|
19
|
-
if s == '/' then
|
44
|
+
if s[-1] == '/' then
|
20
45
|
|
21
46
|
fp = File.join(@filepath, 'index.html')
|
22
|
-
|
47
|
+
|
48
|
+
if File.exists?(fp) then
|
49
|
+
|
50
|
+
return File.read(fp)
|
51
|
+
|
52
|
+
else
|
53
|
+
|
54
|
+
app = path(s)
|
55
|
+
|
56
|
+
if app then
|
57
|
+
return default_index(app)
|
58
|
+
else
|
59
|
+
return ['path not found', 'text/plain', '404']
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
23
63
|
|
24
64
|
end
|
25
65
|
|
26
66
|
return [s.to_s, 'text/plain'] if s =~ /^\/\w+\.\w+/
|
27
67
|
|
28
|
-
|
68
|
+
a2 = s.split('/')
|
69
|
+
basepath = a2[0..-2].join('/')
|
70
|
+
uri = URI(a2[-1])
|
29
71
|
|
30
|
-
|
31
|
-
|
32
|
-
name, *args = a
|
72
|
+
name = a2[-1][-1] == '?' ? a2[-1] : uri.path
|
73
|
+
puts 'name: ' + name.inspect if @debug
|
33
74
|
|
34
75
|
if uri.query then
|
35
76
|
|
@@ -39,14 +80,19 @@ class AppHtmlLayer
|
|
39
80
|
|
40
81
|
puts ('h: ' + h.inspect).debug if @debug
|
41
82
|
args = h[:arg] ? [h[:arg]] : h
|
42
|
-
|
83
|
+
puts 'args: ' + args.inspect if @debug
|
84
|
+
|
43
85
|
end
|
44
86
|
|
45
|
-
|
87
|
+
puts 's: ' + s.inspect if @debug
|
88
|
+
app = path(basepath)
|
89
|
+
puts 'app: ' + app.inspect if @debug
|
90
|
+
|
91
|
+
if app and app.respond_to? name.to_sym then
|
46
92
|
|
47
93
|
begin
|
48
94
|
|
49
|
-
method =
|
95
|
+
method = app.method(name.to_sym)
|
50
96
|
|
51
97
|
if method.arity > 0 and args.length <= 0 then
|
52
98
|
|
@@ -58,12 +104,23 @@ class AppHtmlLayer
|
|
58
104
|
else
|
59
105
|
|
60
106
|
puts ('args: ' + args.inspect).debug if @debug
|
61
|
-
|
107
|
+
|
108
|
+
r = case args
|
109
|
+
when Array
|
110
|
+
method.call(*args)
|
111
|
+
when Hash
|
112
|
+
args.empty? ? method.call : method.call(args)
|
113
|
+
else
|
114
|
+
method.call
|
115
|
+
end
|
62
116
|
|
63
117
|
end
|
64
|
-
|
118
|
+
|
119
|
+
puts ('name' + name.inspect) if @debug
|
120
|
+
|
65
121
|
fp = File.join(@filepath, File.basename(name) + '.html')
|
66
|
-
|
122
|
+
puts 'fp: ' + fp.inspect if @debug
|
123
|
+
|
67
124
|
content = if File.exists?(fp) then
|
68
125
|
render_html(fp, r)
|
69
126
|
else
|
@@ -105,15 +162,17 @@ class AppHtmlLayer
|
|
105
162
|
|
106
163
|
end
|
107
164
|
|
108
|
-
|
165
|
+
private
|
166
|
+
|
167
|
+
def default_index(app)
|
109
168
|
|
110
|
-
a = (
|
169
|
+
a = (app.public_methods - Object.public_methods).sort
|
111
170
|
s = a.map {|x| "* [%s](%s)" % [x,x]}.join("\n")
|
112
171
|
|
113
172
|
markdown = "
|
114
173
|
<html>
|
115
174
|
<head>
|
116
|
-
<title>#{
|
175
|
+
<title>#{app.class.to_s}</title>
|
117
176
|
<style>
|
118
177
|
h1 {color: green}
|
119
178
|
h2 {color: orange}
|
@@ -122,7 +181,7 @@ div {height: 60%; overflow-y: auto; width: 200px; float: left}
|
|
122
181
|
</head>
|
123
182
|
<body markdown='1'>
|
124
183
|
|
125
|
-
# #{
|
184
|
+
# #{app.class.to_s} Index
|
126
185
|
|
127
186
|
## Public Methods
|
128
187
|
|
@@ -145,6 +204,16 @@ div {height: 60%; overflow-y: auto; width: 200px; float: left}
|
|
145
204
|
[doc.xml(pretty: true), 'text/html']
|
146
205
|
end
|
147
206
|
|
207
|
+
def path(s)
|
208
|
+
|
209
|
+
if @apps.length < 2 then
|
210
|
+
@apps.path("/%s/%s" % [@apps.keys.first, s])
|
211
|
+
else
|
212
|
+
@apps.path(s)
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
148
217
|
def render_html(fp, s)
|
149
218
|
|
150
219
|
doc = Rexle.new(File.read fp)
|
@@ -156,4 +225,3 @@ div {height: 60%; overflow-y: auto; width: 200px; float: left}
|
|
156
225
|
end
|
157
226
|
|
158
227
|
end
|
159
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apphtml_layer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
yoJvKaZL2qWoAZHs/MGOlsTMVHkz5YV3AaLaViO2SE/hVvFfFHJDX224xRsUHIHx
|
36
36
|
za7UEBvPemTf/f9WiN5bG3dD
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-
|
38
|
+
date: 2020-11-01 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: c32
|
@@ -57,6 +57,26 @@ dependencies:
|
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0.3'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: hpath
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.1.0
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.1'
|
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.0
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.1'
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
81
|
name: kramdown
|
62
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
123
|
- !ruby/object:Gem::Version
|
104
124
|
version: '0'
|
105
125
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.7.10
|
126
|
+
rubygems_version: 3.0.3
|
108
127
|
signing_key:
|
109
128
|
specification_version: 4
|
110
129
|
summary: Add a basic HTML wrapper to your Ruby object. Suitable for use with a web
|
metadata.gz.sig
CHANGED
Binary file
|