apphtml_layer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3aced5a8e6c3bf21bb153679c3714739adb87bc8361868c9cd0fc4796f6912c
4
- data.tar.gz: ed25dc425646840ee82fdf23236d0665b72922465e07c2a1c18ab89010970311
3
+ metadata.gz: 895fab8f277c269d759859a4449cf9ed1f3ce395846239a0617a175f6392fb03
4
+ data.tar.gz: 0f50045c40962bc85b6455d737920f79835f58c41372c76bb7aa3af4c8702380
5
5
  SHA512:
6
- metadata.gz: d2499af62de9fa482220ec1b0caa265b8e13158c982192ef9b0e30fc90763a66dedfaae1b0863d1d6c37396b48a18d757e41159c91392670472c82bc5b8cde2e
7
- data.tar.gz: c36cda8d3b70376348cecf7861bd0a343be1e9ad80122bcaa7472053517d3e72c610e2adc3beb45c5b83ab0e0c5eeeff6c634ae126b03275cc75d52e1f9f6d33
6
+ metadata.gz: 81d2f12a0f3a86693a72d07d9e4824f9bfa79b62aa38b49eceb8ed30a776f1ffdcf6b49c4533d0004bcc2581c44808605446fb1dad988c399c0fb1bd747947a1
7
+ data.tar.gz: e8ae9e4c1c7be589843f1a753143c10722d311c3782123acbe8181cbf5b01ac6c68094069084b8cdb7542176a0c65a0707deceb8bb68a0021760e6f82f7607fb
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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(app, filepath: '.', headings: false, debug: false)
14
- @app, @filepath, @headings, @debug = app, filepath, headings, debug
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
- return (File.exists?(fp) ? File.read(fp) : default_index() )
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
- uri = URI(s)
68
+ a2 = s.split('/')
69
+ basepath = a2[0..-2].join('/')
70
+ uri = URI(a2[-1])
29
71
 
30
- a = uri.path.split('/')
31
- a.shift
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
- if @app.respond_to? name.to_sym then
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 = @app.method(name.to_sym)
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
- r = args.is_a?(Array) ? method.call(*args) : method.call(args)
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
- def default_index()
165
+ private
166
+
167
+ def default_index(app)
109
168
 
110
- a = (@app.public_methods - Object.public_methods).sort
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>#{@app.class.to_s}</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
- # #{@app.class.to_s} Index
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.1.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-10-26 00:00:00.000000000 Z
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
- rubyforge_project:
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