gloo 3.2.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/gloo.gemspec +9 -3
- data/lib/VERSION +1 -1
- data/lib/VERSION_NOTES +14 -0
- data/lib/gloo/app/engine.rb +1 -1
- data/lib/gloo/app/log.rb +15 -16
- data/lib/gloo/app/platform.rb +11 -84
- data/lib/gloo/app/prompt.rb +90 -0
- data/lib/gloo/app/table.rb +51 -0
- data/lib/gloo/convert/falseclass_to_integer.rb +20 -0
- data/lib/gloo/convert/nilclass_to_date.rb +21 -0
- data/lib/gloo/convert/nilclass_to_datetime.rb +21 -0
- data/lib/gloo/convert/nilclass_to_integer.rb +21 -0
- data/lib/gloo/convert/nilclass_to_string.rb +21 -0
- data/lib/gloo/convert/nilclass_to_time.rb +21 -0
- data/lib/gloo/convert/trueclass_to_integer.rb +20 -0
- data/lib/gloo/core/error.rb +7 -0
- data/lib/gloo/core/gloo_system.rb +7 -14
- data/lib/gloo/core/it.rb +7 -0
- data/lib/gloo/core/obj.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -3
- data/lib/gloo/objs/basic/container.rb +1 -2
- data/lib/gloo/objs/basic/integer.rb +24 -1
- data/lib/gloo/objs/basic/string.rb +116 -1
- data/lib/gloo/objs/basic/string_generator.rb +49 -0
- data/lib/gloo/objs/basic/text.rb +1 -17
- data/lib/gloo/objs/cli/menu.rb +5 -4
- data/lib/gloo/objs/cli/select.rb +3 -2
- data/lib/gloo/objs/{basic → ctrl}/function.rb +12 -0
- data/lib/gloo/objs/data/markdown.rb +59 -6
- data/lib/gloo/objs/data/mysql.rb +39 -27
- data/lib/gloo/objs/data/pg.rb +1 -1
- data/lib/gloo/objs/data/query_result.rb +4 -9
- data/lib/gloo/objs/data/table.rb +1 -1
- data/lib/gloo/objs/security/cipher.rb +193 -0
- data/lib/gloo/objs/security/password.rb +167 -0
- data/lib/gloo/objs/system/file_handle.rb +1 -3
- data/lib/gloo/objs/web/json.rb +3 -0
- data/lib/gloo/objs/web_svr/page.rb +26 -6
- data/lib/gloo/objs/web_svr/partial.rb +7 -6
- data/lib/gloo/objs/web_svr/svr.rb +267 -14
- data/lib/gloo/verbs/invoke.rb +80 -0
- data/lib/gloo/verbs/version.rb +1 -1
- data/lib/gloo/web_svr/asset.rb +54 -33
- data/lib/gloo/web_svr/config.rb +1 -1
- data/lib/gloo/web_svr/embedded_renderer.rb +1 -1
- data/lib/gloo/web_svr/handler.rb +6 -4
- data/lib/gloo/web_svr/request.rb +34 -8
- data/lib/gloo/web_svr/response.rb +14 -2
- data/lib/gloo/web_svr/response_code.rb +1 -1
- data/lib/gloo/web_svr/routing/router.rb +1 -2
- data/lib/gloo/web_svr/routing/show_routes.rb +4 -7
- data/lib/gloo/web_svr/server.rb +1 -1
- data/lib/gloo/web_svr/session.rb +161 -0
- data/lib/gloo/web_svr/table_renderer.rb +1 -1
- metadata +81 -26
- data/lib/gloo/objs/cli/banner.rb +0 -118
- data/lib/gloo/objs/cli/bar.rb +0 -133
- data/lib/gloo/objs/cli/pastel.rb +0 -104
@@ -11,18 +11,45 @@ module Gloo
|
|
11
11
|
KEYWORD = 'server'.freeze
|
12
12
|
KEYWORD_SHORT = 'svr'.freeze
|
13
13
|
|
14
|
-
#
|
15
|
-
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
# CONFIGURATION KEYS
|
16
|
+
# ---------------------------------------------------------------------
|
17
|
+
CONFIG = 'config'.freeze
|
18
|
+
SCHEME = 'scheme'.freeze
|
19
|
+
HTTP = 'http'.freeze
|
20
|
+
HTTPS = 'https'.freeze
|
16
21
|
HOST = 'host'.freeze
|
17
22
|
PORT = 'port'.freeze
|
23
|
+
SESSION_NAME = 'session_name'.freeze
|
24
|
+
ENCRYPT_KEY = 'encryption_key'.freeze
|
25
|
+
ENCRYPT_IV = 'encryption_iv'.freeze
|
26
|
+
COOKIE_EXPIRES = 'cookie_expires'.freeze
|
27
|
+
COOKIE_PATH = 'cookie_path'.freeze
|
28
|
+
DEFAULT_COOKIE_PATH = '/'.freeze
|
18
29
|
|
19
30
|
# SSL Configuration
|
20
31
|
SSL_CERT = 'ssl_cert'.freeze
|
21
32
|
SSL_KEY = 'ssl_key'.freeze
|
22
33
|
|
34
|
+
# ---------------------------------------------------------------------
|
35
|
+
# OTHER KEYS
|
36
|
+
# ---------------------------------------------------------------------
|
37
|
+
|
23
38
|
# Events
|
24
39
|
ON_START = 'on_start'.freeze
|
25
40
|
ON_STOP = 'on_stop'.freeze
|
41
|
+
ON_REQUEST = 'on_request'.freeze
|
42
|
+
ON_RESPONSE = 'on_response'.freeze
|
43
|
+
RESQUEST_DATA = 'request_data'.freeze
|
44
|
+
METHOD = 'method'.freeze
|
45
|
+
PATH = 'path'.freeze
|
46
|
+
QUERY = 'query'.freeze
|
47
|
+
IP = 'ip'.freeze
|
48
|
+
RESPONSE_DATA = 'response_data'.freeze
|
49
|
+
TYPE = 'type'.freeze
|
50
|
+
CODE = 'code'.freeze
|
51
|
+
ELAPSED = 'elapsed'.freeze
|
52
|
+
DB = 'db'.freeze
|
26
53
|
|
27
54
|
# Container with pages in the web app.
|
28
55
|
PAGES = 'pages'.freeze
|
@@ -34,6 +61,9 @@ module Gloo
|
|
34
61
|
HOME = 'home'.freeze
|
35
62
|
ERR_PAGE = 'error'.freeze
|
36
63
|
|
64
|
+
# Session
|
65
|
+
SESSION = 'session'.freeze
|
66
|
+
|
37
67
|
|
38
68
|
# Messages
|
39
69
|
SERVER_NOT_RUNNING = 'The web server is not running!'.freeze
|
@@ -44,6 +74,7 @@ module Gloo
|
|
44
74
|
# of the one requested.
|
45
75
|
#
|
46
76
|
attr_accessor :redirect, :router, :asset, :embedded_renderer
|
77
|
+
attr_accessor :session
|
47
78
|
|
48
79
|
#
|
49
80
|
# The name of the object type.
|
@@ -74,12 +105,29 @@ module Gloo
|
|
74
105
|
return false
|
75
106
|
end
|
76
107
|
|
108
|
+
#
|
109
|
+
# Get the default layout for the app.
|
110
|
+
#
|
111
|
+
def default_page_layout
|
112
|
+
o = find_child LAYOUT
|
113
|
+
return nil unless o
|
114
|
+
|
115
|
+
o = Gloo::Objs::Alias.resolve_alias( @engine, o )
|
116
|
+
return o
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# ---------------------------------------------------------------------
|
121
|
+
# Configuration
|
122
|
+
# ---------------------------------------------------------------------
|
123
|
+
|
77
124
|
#
|
78
125
|
# Get the Scheme (http or https) from the child object.
|
79
126
|
# Returns nil if there is none.
|
80
127
|
#
|
81
128
|
def scheme_value
|
82
|
-
|
129
|
+
config = find_child CONFIG
|
130
|
+
scheme = config.find_child SCHEME
|
83
131
|
return nil unless scheme
|
84
132
|
|
85
133
|
return scheme.value
|
@@ -90,7 +138,8 @@ module Gloo
|
|
90
138
|
# Returns nil if there is none.
|
91
139
|
#
|
92
140
|
def host_value
|
93
|
-
|
141
|
+
config = find_child CONFIG
|
142
|
+
host = config.find_child HOST
|
94
143
|
return nil unless host
|
95
144
|
|
96
145
|
return host.value
|
@@ -101,24 +150,163 @@ module Gloo
|
|
101
150
|
# Returns nil if there is none.
|
102
151
|
#
|
103
152
|
def port_value
|
104
|
-
|
153
|
+
config = find_child CONFIG
|
154
|
+
port = config.find_child PORT
|
105
155
|
return nil unless port
|
106
156
|
|
107
157
|
return port.value
|
108
158
|
end
|
109
159
|
|
160
|
+
#
|
161
|
+
# Is this server configured to use a session?
|
162
|
+
# It is if theere is a non-empty session name.
|
163
|
+
#
|
164
|
+
def use_session?
|
165
|
+
return ! session_name.blank?
|
166
|
+
end
|
110
167
|
|
111
168
|
#
|
112
|
-
# Get the
|
169
|
+
# Get the session cookie name.
|
113
170
|
#
|
114
|
-
def
|
115
|
-
|
171
|
+
def session_name
|
172
|
+
config = find_child CONFIG
|
173
|
+
session_name = config.find_child SESSION_NAME
|
174
|
+
return nil unless session_name
|
175
|
+
|
176
|
+
name = session_name.value
|
177
|
+
return nil if name.blank?
|
178
|
+
|
179
|
+
return name
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# Get the key for the encryption cipher.
|
184
|
+
#
|
185
|
+
def encryption_key
|
186
|
+
config = find_child CONFIG
|
187
|
+
o = config.find_child ENCRYPT_KEY
|
116
188
|
return nil unless o
|
117
189
|
|
118
190
|
o = Gloo::Objs::Alias.resolve_alias( @engine, o )
|
191
|
+
return o.value
|
192
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# Get the initialization vector for the cipher.
|
196
|
+
#
|
197
|
+
def encryption_iv
|
198
|
+
config = find_child CONFIG
|
199
|
+
o = config.find_child ENCRYPT_IV
|
200
|
+
return nil unless o
|
201
|
+
|
202
|
+
o = Gloo::Objs::Alias.resolve_alias( @engine, o )
|
203
|
+
return o.value
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# Get the path for the session cookie.
|
208
|
+
# If not specified, use the root path.
|
209
|
+
#
|
210
|
+
def session_cookie_path
|
211
|
+
config = find_child CONFIG
|
212
|
+
o = config.find_child COOKIE_PATH
|
213
|
+
if o
|
214
|
+
return o.value
|
215
|
+
else
|
216
|
+
return DEFAULT_COOKIE_PATH
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
#
|
221
|
+
# Get the expiration time for the session cookie.
|
222
|
+
# If not specified, use one week from now.
|
223
|
+
#
|
224
|
+
def session_cookie_expires
|
225
|
+
config = find_child CONFIG
|
226
|
+
o = config.find_child COOKIE_EXPIRES
|
227
|
+
if o
|
228
|
+
dt = Chronic.parse( o.value )
|
229
|
+
return dt
|
230
|
+
else
|
231
|
+
return 1.week.from_now
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
#
|
236
|
+
# Should the session cookie be secure?
|
237
|
+
# Get the value from the scheme settings/config.
|
238
|
+
#
|
239
|
+
def session_cookie_secure
|
240
|
+
return scheme_value.downcase == HTTPS
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
# ---------------------------------------------------------------------
|
245
|
+
# Session
|
246
|
+
# ---------------------------------------------------------------------
|
247
|
+
|
248
|
+
#
|
249
|
+
# Get the session container object.
|
250
|
+
# If there is none, one will be created.
|
251
|
+
#
|
252
|
+
def session_container
|
253
|
+
o = find_child SESSION
|
254
|
+
|
255
|
+
unless o
|
256
|
+
o = add_session_container
|
257
|
+
end
|
258
|
+
|
119
259
|
return o
|
120
260
|
end
|
121
261
|
|
262
|
+
#
|
263
|
+
# Add the session container because it is missing.
|
264
|
+
#
|
265
|
+
def add_session_container
|
266
|
+
fac = @engine.factory
|
267
|
+
return fac.create_can SESSION, self
|
268
|
+
end
|
269
|
+
|
270
|
+
#
|
271
|
+
# Get the data from the session container.
|
272
|
+
# Data will be in the form of a hash ( key => value ).
|
273
|
+
#
|
274
|
+
def get_session_data
|
275
|
+
data = {}
|
276
|
+
|
277
|
+
session_container.children.each do |session_var|
|
278
|
+
key = session_var.name
|
279
|
+
value = session_var.value
|
280
|
+
data[ key ] = value
|
281
|
+
end
|
282
|
+
|
283
|
+
return data
|
284
|
+
end
|
285
|
+
|
286
|
+
#
|
287
|
+
# Get the session child object with the given value.
|
288
|
+
# Create the child if it does not exist.
|
289
|
+
#
|
290
|
+
def set_session_var( key, value )
|
291
|
+
child_obj = session_container.find_child( key )
|
292
|
+
unless child_obj
|
293
|
+
fac = @engine.factory
|
294
|
+
child_obj = fac.create_string key, value, session_obj
|
295
|
+
end
|
296
|
+
child_obj.value = value
|
297
|
+
end
|
298
|
+
|
299
|
+
#
|
300
|
+
# Clear out all session data.
|
301
|
+
# Important to do this after the response is sent
|
302
|
+
# to avoid holding on to data that is no longer needed.
|
303
|
+
#
|
304
|
+
def clear_session_data
|
305
|
+
session_container.children.each do |session_var|
|
306
|
+
session_var.value = ''
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
122
310
|
|
123
311
|
# ---------------------------------------------------------------------
|
124
312
|
# SSL
|
@@ -190,15 +378,20 @@ module Gloo
|
|
190
378
|
def add_default_children
|
191
379
|
fac = @engine.factory
|
192
380
|
|
193
|
-
|
194
|
-
fac.
|
195
|
-
fac.create_string
|
381
|
+
# Configuration
|
382
|
+
config = fac.create_can CONFIG, self
|
383
|
+
fac.create_string SCHEME, HTTP, config
|
384
|
+
fac.create_string HOST, 'localhost', config
|
385
|
+
fac.create_string PORT, '8080', config
|
196
386
|
|
197
387
|
fac.create_script ON_START, '', self
|
198
388
|
fac.create_script ON_STOP, '', self
|
199
389
|
|
390
|
+
fac.create_alias LAYOUT, nil, self
|
391
|
+
fac.create_alias HOME, nil, self
|
392
|
+
fac.create_alias ERR_PAGE, nil, self
|
393
|
+
|
200
394
|
fac.create_can PAGES, self
|
201
|
-
fac.create_can HOME, self
|
202
395
|
end
|
203
396
|
|
204
397
|
|
@@ -274,6 +467,8 @@ module Gloo
|
|
274
467
|
|
275
468
|
@embedded_renderer = Gloo::WebSvr::EmbeddedRenderer.new( @engine, self )
|
276
469
|
|
470
|
+
@session = Gloo::WebSvr::Session.new( @engine, self )
|
471
|
+
|
277
472
|
run_on_start
|
278
473
|
@engine.log.info "Web server started and listening…"
|
279
474
|
end
|
@@ -283,6 +478,10 @@ module Gloo
|
|
283
478
|
#
|
284
479
|
def stop
|
285
480
|
@engine.log.info "Stopping web server…"
|
481
|
+
|
482
|
+
# Last chance to clear out session data.
|
483
|
+
clear_session_data
|
484
|
+
|
286
485
|
@web_server.stop
|
287
486
|
@web_server = nil
|
288
487
|
@router = nil
|
@@ -297,7 +496,7 @@ module Gloo
|
|
297
496
|
# ---------------------------------------------------------------------
|
298
497
|
|
299
498
|
#
|
300
|
-
# Run the on
|
499
|
+
# Run the on start script if there is one.
|
301
500
|
#
|
302
501
|
def run_on_start
|
303
502
|
o = find_child ON_START
|
@@ -307,7 +506,7 @@ module Gloo
|
|
307
506
|
end
|
308
507
|
|
309
508
|
#
|
310
|
-
# Run the on
|
509
|
+
# Run the on stop script if there is one.
|
311
510
|
#
|
312
511
|
def run_on_stop
|
313
512
|
o = find_child ON_STOP
|
@@ -316,6 +515,60 @@ module Gloo
|
|
316
515
|
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
317
516
|
end
|
318
517
|
|
518
|
+
#
|
519
|
+
# Run the on request script if there is one.
|
520
|
+
#
|
521
|
+
def run_on_request
|
522
|
+
o = find_child ON_REQUEST
|
523
|
+
return unless o
|
524
|
+
o = Gloo::Objs::Alias.resolve_alias( @engine, o )
|
525
|
+
|
526
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
527
|
+
end
|
528
|
+
|
529
|
+
#
|
530
|
+
# Run the on response script if there is one.
|
531
|
+
#
|
532
|
+
def run_on_response
|
533
|
+
o = find_child ON_RESPONSE
|
534
|
+
return unless o
|
535
|
+
o = Gloo::Objs::Alias.resolve_alias( @engine, o )
|
536
|
+
|
537
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
538
|
+
end
|
539
|
+
|
540
|
+
#
|
541
|
+
# Set up the request data for the page load.
|
542
|
+
# This is done before the on_request event is fired.
|
543
|
+
#
|
544
|
+
def set_request_data( request )
|
545
|
+
data = find_child RESQUEST_DATA
|
546
|
+
return unless data
|
547
|
+
data = Gloo::Objs::Alias.resolve_alias( @engine, data )
|
548
|
+
|
549
|
+
data.find_child( METHOD )&.set_value( request.method )
|
550
|
+
data.find_child( HOST )&.set_value( request.host )
|
551
|
+
data.find_child( PATH )&.set_value( request.path )
|
552
|
+
data.find_child( QUERY )&.set_value( request.query )
|
553
|
+
data.find_child( IP )&.set_value( request.ip )
|
554
|
+
end
|
555
|
+
|
556
|
+
#
|
557
|
+
# Set up the response data for the page load.
|
558
|
+
# This is done after the page is rendered and before
|
559
|
+
# the on_response event is fired.
|
560
|
+
#
|
561
|
+
def set_response_data( request, response )
|
562
|
+
data = find_child RESPONSE_DATA
|
563
|
+
return unless data
|
564
|
+
data = Gloo::Objs::Alias.resolve_alias( @engine, data )
|
565
|
+
|
566
|
+
data.find_child( ELAPSED )&.set_value( request.elapsed )
|
567
|
+
data.find_child( DB )&.set_value( request.db )
|
568
|
+
data.find_child( TYPE )&.set_value( response.type )
|
569
|
+
data.find_child( CODE )&.set_value( response.code )
|
570
|
+
end
|
571
|
+
|
319
572
|
|
320
573
|
# ---------------------------------------------------------------------
|
321
574
|
# Pages and standard elements.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Invoke a function from a script.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Verbs
|
9
|
+
class Invoke < Gloo::Core::Verb
|
10
|
+
|
11
|
+
KEYWORD = 'invoke'.freeze
|
12
|
+
KEYWORD_SHORT = '~>'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# Run the verb.
|
16
|
+
#
|
17
|
+
def run
|
18
|
+
if @tokens.token_count > 1
|
19
|
+
ob = @tokens.first
|
20
|
+
|
21
|
+
# Get the function object
|
22
|
+
pn = Gloo::Core::Pn.new( @engine, @tokens.second )
|
23
|
+
func = pn.resolve
|
24
|
+
|
25
|
+
# Is the object a function?
|
26
|
+
if func&.is_function?
|
27
|
+
params = get_params_arr
|
28
|
+
|
29
|
+
@engine.log.debug "invoking function: #{func.pn}"
|
30
|
+
result = func.invoke( params )
|
31
|
+
@engine.log.debug "function returned: #{result}"
|
32
|
+
@engine.heap.it.set_to result
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get the Verb's keyword.
|
40
|
+
#
|
41
|
+
def self.keyword
|
42
|
+
return KEYWORD
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the Verb's keyword shortcut.
|
47
|
+
#
|
48
|
+
def self.keyword_shortcut
|
49
|
+
return KEYWORD_SHORT
|
50
|
+
end
|
51
|
+
|
52
|
+
# ---------------------------------------------------------------------
|
53
|
+
# Private functions
|
54
|
+
# ---------------------------------------------------------------------
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
#
|
59
|
+
# Get params array.
|
60
|
+
#
|
61
|
+
def get_params_arr
|
62
|
+
@engine.log.debug "token params: #{@tokens.params}"
|
63
|
+
params = @tokens.params[1..-1]
|
64
|
+
|
65
|
+
@engine.log.info "params: #{params}"
|
66
|
+
evaluated_params = []
|
67
|
+
|
68
|
+
params.each do |p|
|
69
|
+
expr = Gloo::Expr::Expression.new( @engine, [ p ] )
|
70
|
+
evaluated_params << expr.evaluate
|
71
|
+
end
|
72
|
+
|
73
|
+
@engine.log.debug "evaluated_params: #{evaluated_params}"
|
74
|
+
|
75
|
+
return evaluated_params
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/gloo/verbs/version.rb
CHANGED
data/lib/gloo/web_svr/asset.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
3
|
#
|
4
4
|
# A helper class for static assets.
|
5
5
|
#
|
@@ -8,9 +8,9 @@ module Gloo
|
|
8
8
|
module WebSvr
|
9
9
|
class Asset
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
ASSET_FOLDER = 'asset'.freeze
|
12
|
+
IMAGE_FOLDER = 'image'.freeze
|
13
|
+
STYLESHEET_FOLDER = 'stylesheet'.freeze
|
14
14
|
JAVASCRIPT_FOLDER = 'javascript'.freeze
|
15
15
|
|
16
16
|
CSS_TYPE = 'text/css'.freeze
|
@@ -42,29 +42,29 @@ module Gloo
|
|
42
42
|
#
|
43
43
|
# Get the asset folder in the project.
|
44
44
|
#
|
45
|
-
def
|
46
|
-
return File.join( @engine.settings.project_path,
|
45
|
+
def asset_folder
|
46
|
+
return File.join( @engine.settings.project_path, ASSET_FOLDER )
|
47
47
|
end
|
48
48
|
|
49
49
|
#
|
50
50
|
# Get the images folder in the project.
|
51
51
|
#
|
52
|
-
def
|
53
|
-
return File.join(
|
52
|
+
def image_folder
|
53
|
+
return File.join( asset_folder, IMAGE_FOLDER )
|
54
54
|
end
|
55
55
|
|
56
56
|
#
|
57
57
|
# Get the stylesheets folder in the project.
|
58
58
|
#
|
59
|
-
def
|
60
|
-
return File.join(
|
59
|
+
def stylesheet_folder
|
60
|
+
return File.join( asset_folder, STYLESHEET_FOLDER )
|
61
61
|
end
|
62
62
|
|
63
63
|
#
|
64
64
|
# Get the stylesheets folder in the project.
|
65
65
|
#
|
66
66
|
def javascript_folder
|
67
|
-
return File.join(
|
67
|
+
return File.join( asset_folder, JAVASCRIPT_FOLDER )
|
68
68
|
end
|
69
69
|
|
70
70
|
#
|
@@ -77,7 +77,7 @@ module Gloo
|
|
77
77
|
return pn if File.exist? pn
|
78
78
|
|
79
79
|
# Look in the web server's asset folder.
|
80
|
-
pn = File.join(
|
80
|
+
pn = File.join( asset_folder, pn )
|
81
81
|
|
82
82
|
return pn
|
83
83
|
end
|
@@ -125,7 +125,7 @@ module Gloo
|
|
125
125
|
# Add all asssets to the web server pages (routes).
|
126
126
|
#
|
127
127
|
def add_asset_routes
|
128
|
-
return unless File.exist?
|
128
|
+
return unless File.exist? asset_folder
|
129
129
|
|
130
130
|
@log.debug 'Adding asset routes to web server…'
|
131
131
|
@factory = @engine.factory
|
@@ -142,33 +142,50 @@ module Gloo
|
|
142
142
|
def add_containers
|
143
143
|
pages = @web_svr_obj.pages_container
|
144
144
|
|
145
|
-
@assets = pages.find_child(
|
146
|
-
@factory.create_can(
|
145
|
+
@assets = pages.find_child( ASSET_FOLDER ) ||
|
146
|
+
@factory.create_can( ASSET_FOLDER, pages )
|
147
147
|
|
148
|
-
@images = @assets.find_child(
|
149
|
-
@factory.create_can(
|
148
|
+
@images = @assets.find_child( IMAGE_FOLDER ) ||
|
149
|
+
@factory.create_can( IMAGE_FOLDER, @assets )
|
150
150
|
|
151
|
-
@stylesheets = @assets.find_child(
|
152
|
-
@factory.create_can(
|
151
|
+
@stylesheets = @assets.find_child( STYLESHEET_FOLDER ) ||
|
152
|
+
@factory.create_can( STYLESHEET_FOLDER, @assets )
|
153
153
|
|
154
154
|
@javascript = @assets.find_child( JAVASCRIPT_FOLDER ) ||
|
155
155
|
@factory.create_can( JAVASCRIPT_FOLDER, @assets )
|
156
156
|
end
|
157
157
|
|
158
|
+
#
|
159
|
+
# Traverse the given folder and add all files to the container.
|
160
|
+
# This is a recursive method and look look for files in subfolders.
|
161
|
+
#
|
162
|
+
def add_files_in_folder( folder, container, path )
|
163
|
+
Dir.each_child( folder ) do |name|
|
164
|
+
pn = File.join( path, name )
|
165
|
+
full_path = File.join( folder, name )
|
166
|
+
|
167
|
+
if File.directory? full_path
|
168
|
+
child = container.find_child( name )
|
169
|
+
child = @factory.create_can( name, container ) if child.nil?
|
170
|
+
|
171
|
+
add_files_in_folder( full_path, child, pn )
|
172
|
+
else
|
173
|
+
add_file_obj( container, name, pn )
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
158
178
|
#
|
159
179
|
# Add the images to the web server pages.
|
160
180
|
#
|
161
181
|
def add_images
|
162
182
|
@log.debug 'Adding image asset routes to web server…'
|
163
183
|
|
164
|
-
return unless File.exist?
|
184
|
+
return unless File.exist? image_folder
|
165
185
|
|
166
186
|
# for each file in the images folder
|
167
187
|
# create a file object and add it to the images container
|
168
|
-
|
169
|
-
pn = File.join( IMAGES_FOLDER, name )
|
170
|
-
add_file_obj( @images, name, pn )
|
171
|
-
end
|
188
|
+
add_files_in_folder( image_folder, @images, IMAGE_FOLDER )
|
172
189
|
end
|
173
190
|
|
174
191
|
#
|
@@ -177,14 +194,16 @@ module Gloo
|
|
177
194
|
def add_stylesheets
|
178
195
|
@log.debug 'Adding stylesheet asset routes to web server…'
|
179
196
|
|
180
|
-
return unless File.exist?
|
197
|
+
return unless File.exist? stylesheet_folder
|
181
198
|
|
182
199
|
# for each file in the stylesheets folder
|
183
200
|
# create a file object and add it to the stylesheets container
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
201
|
+
add_files_in_folder( stylesheet_folder, @stylesheets, STYLESHEET_FOLDER )
|
202
|
+
|
203
|
+
# Dir.each_child( stylesheet_folder ) do |name|
|
204
|
+
# pn = File.join( STYLESHEET_FOLDER, name )
|
205
|
+
# add_file_obj( @stylesheets, name, pn )
|
206
|
+
# end
|
188
207
|
end
|
189
208
|
|
190
209
|
#
|
@@ -197,10 +216,12 @@ module Gloo
|
|
197
216
|
|
198
217
|
# for each file in the javascript folder
|
199
218
|
# create a file object and add it to the javascript container
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
219
|
+
add_files_in_folder( javascript_folder, @javascript, JAVASCRIPT_FOLDER )
|
220
|
+
|
221
|
+
# Dir.each_child( javascript_folder ) do |name|
|
222
|
+
# pn = File.join( JAVASCRIPT_FOLDER, name )
|
223
|
+
# add_file_obj( @javascript, name, pn )
|
224
|
+
# end
|
204
225
|
end
|
205
226
|
|
206
227
|
#
|
data/lib/gloo/web_svr/config.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
3
|
#
|
4
4
|
# A helper class used to render parameters (ERB) in text.
|
5
5
|
# Also uses helper functions to render.
|
data/lib/gloo/web_svr/handler.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
3
|
#
|
4
4
|
# Web application request handler.
|
5
5
|
# Takes a request and does what is needed to create a response.
|
@@ -41,13 +41,15 @@ module Gloo
|
|
41
41
|
request.id = id
|
42
42
|
if page
|
43
43
|
if page.is_a? Gloo::Objs::FileHandle
|
44
|
-
|
44
|
+
result = handle_file page
|
45
45
|
else
|
46
|
-
|
46
|
+
result = handle_page page
|
47
47
|
end
|
48
|
+
else
|
49
|
+
result = server_error_result
|
48
50
|
end
|
49
51
|
|
50
|
-
return
|
52
|
+
return result
|
51
53
|
end
|
52
54
|
|
53
55
|
#
|