gloo 4.7.0 → 5.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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/gloo.gemspec +22 -11
  4. data/lib/VERSION +1 -1
  5. data/lib/VERSION_NOTES +7 -0
  6. data/lib/gloo/app/engine.rb +3 -2
  7. data/lib/gloo/app/running_app.rb +13 -0
  8. data/lib/gloo/core/dictionary.rb +13 -2
  9. data/lib/gloo/objs/ctrl/each.rb +2 -2
  10. data/lib/gloo/{ext → plugin}/base.rb +1 -1
  11. data/lib/gloo/{ext → plugin}/callback.rb +2 -3
  12. data/lib/gloo/{ext/manager.rb → plugin/ext_manager.rb} +2 -2
  13. data/lib/gloo/plugin/lib_manager.rb +97 -0
  14. data/lib/gloo/verbs/exists.rb +75 -0
  15. data/lib/gloo/verbs/help.rb +28 -0
  16. data/lib/gloo/verbs/load.rb +8 -2
  17. data/lib/gloo/verbs/redirect.rb +2 -1
  18. metadata +38 -164
  19. data/lib/gloo/objs/cli/colorize.rb +0 -73
  20. data/lib/gloo/objs/cli/confirm.rb +0 -96
  21. data/lib/gloo/objs/cli/menu.rb +0 -370
  22. data/lib/gloo/objs/cli/menu_item.rb +0 -95
  23. data/lib/gloo/objs/cli/prompt.rb +0 -110
  24. data/lib/gloo/objs/cli/select.rb +0 -127
  25. data/lib/gloo/objs/ctrl/each_repo.rb +0 -84
  26. data/lib/gloo/objs/data/markdown.rb +0 -133
  27. data/lib/gloo/objs/data/markdown_ext.rb +0 -260
  28. data/lib/gloo/objs/data/mysql.rb +0 -254
  29. data/lib/gloo/objs/data/query.rb +0 -269
  30. data/lib/gloo/objs/data/query_result.rb +0 -158
  31. data/lib/gloo/objs/data/sqlite.rb +0 -174
  32. data/lib/gloo/objs/data/table.rb +0 -267
  33. data/lib/gloo/objs/dev/git.rb +0 -140
  34. data/lib/gloo/objs/dev/stats.rb +0 -123
  35. data/lib/gloo/objs/system/ssh_exec.rb +0 -126
  36. data/lib/gloo/objs/web_svr/element.rb +0 -254
  37. data/lib/gloo/objs/web_svr/field.rb +0 -429
  38. data/lib/gloo/objs/web_svr/form.rb +0 -271
  39. data/lib/gloo/objs/web_svr/page.rb +0 -562
  40. data/lib/gloo/objs/web_svr/partial.rb +0 -210
  41. data/lib/gloo/objs/web_svr/svr.rb +0 -713
  42. data/lib/gloo/utils/stats.rb +0 -206
  43. data/lib/gloo/web_svr/asset.rb +0 -407
  44. data/lib/gloo/web_svr/asset_info.rb +0 -116
  45. data/lib/gloo/web_svr/config.rb +0 -56
  46. data/lib/gloo/web_svr/embedded_renderer.rb +0 -154
  47. data/lib/gloo/web_svr/handler.rb +0 -154
  48. data/lib/gloo/web_svr/request.rb +0 -143
  49. data/lib/gloo/web_svr/request_params.rb +0 -181
  50. data/lib/gloo/web_svr/response.rb +0 -177
  51. data/lib/gloo/web_svr/response_code.rb +0 -69
  52. data/lib/gloo/web_svr/routing/resource_router.rb +0 -47
  53. data/lib/gloo/web_svr/routing/router.rb +0 -232
  54. data/lib/gloo/web_svr/routing/show_routes.rb +0 -94
  55. data/lib/gloo/web_svr/server.rb +0 -105
  56. data/lib/gloo/web_svr/session.rb +0 -215
  57. data/lib/gloo/web_svr/table_renderer.rb +0 -151
  58. data/lib/gloo/web_svr/web_method.rb +0 -54
  59. /data/lib/gloo/objs/{security → str_utils}/cipher.rb +0 -0
  60. /data/lib/gloo/objs/{security → str_utils}/csrf_token.rb +0 -0
  61. /data/lib/gloo/objs/{security → str_utils}/password.rb +0 -0
  62. /data/lib/gloo/objs/{ror → system}/erb.rb +0 -0
  63. /data/lib/gloo/objs/{ror → system}/eval.rb +0 -0
@@ -1,562 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # A web page hosted in a gloo web server.
5
- #
6
-
7
- module Gloo
8
- module Objs
9
- class Page < Gloo::Core::Obj
10
-
11
- KEYWORD = 'page'.freeze
12
- KEYWORD_SHORT = 'page'.freeze
13
-
14
- # Events
15
- ON_RENDER = 'on_render'.freeze
16
- ON_PRERENDER = 'on_prerender'.freeze
17
- AFTER_RENDER = 'after_render'.freeze
18
-
19
- # Parameters used during render.
20
- PARAMS = 'params'.freeze
21
- ID = 'id'.freeze
22
-
23
- # Content
24
- HEAD = 'head'.freeze
25
- BODY = 'body'.freeze
26
- CONTENT = 'content'.freeze
27
- TITLE = 'title'.freeze
28
-
29
- # Layout for this page.
30
- # If not specified, use the layout for the app.
31
- LAYOUT = 'layout'.freeze
32
-
33
- # Return Content type and HTML Code
34
- CONTENT_TYPE = 'content_type'.freeze
35
- HTML_CONTENT = 'html'.freeze
36
- TEXT_CONTENT = 'text'.freeze
37
- JSON_CONTENT = 'json'.freeze
38
- FILE_CONTENT = 'file'.freeze
39
- RETURN_CODE = 'return_code'.freeze
40
-
41
- # Children for FILE pages.
42
- FILE_TYPE = 'file_type'.freeze
43
- FILE_PATH = 'file_path'.freeze
44
- FILE_NAME = 'file_name'.freeze
45
- FILE_DATA = 'file_data'.freeze
46
- DOWNLOAD_FILE = 'download_file'.freeze
47
-
48
- #
49
- # The name of the object type.
50
- #
51
- def self.typename
52
- return KEYWORD
53
- end
54
-
55
- #
56
- # The short name of the object type.
57
- #
58
- def self.short_typename
59
- return KEYWORD_SHORT
60
- end
61
-
62
- #
63
- # Set the value with any necessary type conversions.
64
- #
65
- def set_value( new_value )
66
- self.value = new_value.to_s
67
- end
68
-
69
- #
70
- # Does this object support multi-line values?
71
- # Initially only true for scripts.
72
- #
73
- def multiline_value?
74
- return false
75
- end
76
-
77
- #
78
- # Get the head element.
79
- #
80
- def head
81
- return find_child HEAD
82
- end
83
-
84
- #
85
- # Get the header content.
86
- # This might be in a content child, or it might be
87
- # the head object itself.
88
- #
89
- def head_content
90
- head_obj = head
91
- return nil unless head_obj
92
-
93
- content_obj = head_obj.find_child CONTENT
94
- return content_obj ? content_obj : head_obj
95
- end
96
-
97
- #
98
- # Get the body element.
99
- #
100
- def body
101
- return find_child BODY
102
- end
103
-
104
- #
105
- # Get the body content.
106
- # This might be in a content child, or it might be
107
- # the body object itself.
108
- #
109
- def body_content
110
- body_obj = body
111
- return nil unless body_obj
112
-
113
- content_obj = body_obj.find_child CONTENT
114
- return content_obj ? content_obj : body_obj
115
- end
116
-
117
- #
118
- # Init params container with request values.
119
- #
120
- def init_params
121
- params_can = find_child PARAMS
122
- return nil unless params_can
123
-
124
- # First set URL route params if there are any.
125
- if @request&.request_params&.route_params
126
- @request.request_params.route_params.each_with_index do |route_p,i|
127
- o = params_can.children[i]
128
- o.set_value( route_p ) if o && o.name != ID
129
- end
130
- end
131
-
132
- if @request
133
- url_params = @request.request_params.query_params
134
- url_params.each do |k,v|
135
- o = params_can.find_child k
136
- o.set_value( v ) if o
137
- end
138
-
139
- @request.request_params.body_params.each do |k,v|
140
- o = params_can.find_child k
141
- o.set_value( v ) if o
142
- end
143
- end
144
- end
145
-
146
- #
147
- # Get the params hash from the child object.
148
- # Returns nil if there is none.
149
- #
150
- def params_hash
151
- params_can = find_child PARAMS
152
- return nil unless params_can
153
-
154
- h = {}
155
- params_can.children.each do |o|
156
- # resolve aliases
157
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
158
- h[ o.name ] = o.value
159
- end
160
-
161
- return h
162
- end
163
-
164
- #
165
- # Get the return code.
166
- # SUCCESS is the default if none is set.
167
- #
168
- def return_code
169
- code = find_child RETURN_CODE
170
- return code ? code.value : Gloo::WebSvr::ResponseCode::SUCCESS
171
- end
172
-
173
- #
174
- # Get the content type.
175
- #
176
- def content_type
177
- type = find_child CONTENT_TYPE
178
- return type ? type.value : nil
179
- end
180
-
181
- #
182
- # Get the layout for this page.
183
- #
184
- def page_layout
185
- o = find_child LAYOUT
186
- return nil unless o
187
-
188
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
189
- return o
190
- end
191
-
192
- #
193
- # Is the return type HTML?
194
- #
195
- def is_html?
196
- return true if content_type.nil?
197
- return content_type == HTML_CONTENT
198
- end
199
-
200
- #
201
- # Is the return type TEXT?
202
- #
203
- def is_text?
204
- return content_type == TEXT_CONTENT
205
- end
206
-
207
- #
208
- # Is the return type JSON?
209
- #
210
- def is_json?
211
- return content_type == JSON_CONTENT
212
- end
213
-
214
- def is_file?
215
- return content_type == FILE_CONTENT
216
- end
217
-
218
-
219
- # ---------------------------------------------------------------------
220
- # Events
221
- # ---------------------------------------------------------------------
222
-
223
- #
224
- # Run the on prerender script if there is one.
225
- #
226
- def run_on_prerender
227
- o = find_child ON_PRERENDER
228
- return unless o
229
-
230
- @engine.log.debug "running on_prerender for page"
231
-
232
- Gloo::Exec::Dispatch.message( @engine, 'run', o )
233
- end
234
-
235
- #
236
- # Run the on render script if there is one.
237
- #
238
- def run_on_render
239
- o = find_child ON_RENDER
240
- return unless o
241
-
242
- @engine.log.debug "running on_render for page"
243
-
244
- Gloo::Exec::Dispatch.message( @engine, 'run', o )
245
- end
246
-
247
- #
248
- # Run the on rendered script if there is one.
249
- #
250
- def run_after_render
251
- o = find_child AFTER_RENDER
252
- return unless o
253
-
254
- @engine.log.debug "running after_render for page"
255
-
256
- Gloo::Exec::Dispatch.message( @engine, 'run', o )
257
- end
258
-
259
-
260
- # ---------------------------------------------------------------------
261
- # Children
262
- # ---------------------------------------------------------------------
263
-
264
- #
265
- # Does this object have children to add when an object
266
- # is created in interactive mode?
267
- # This does not apply during obj load, etc.
268
- #
269
- def add_children_on_create?
270
- return true
271
- end
272
-
273
- #
274
- # Add children to this object.
275
- # This is used by containers to add children needed
276
- # for default configurations.
277
- #
278
- def add_default_children
279
- fac = @engine.factory
280
-
281
- fac.create_script ON_RENDER, '', self
282
- fac.create_script AFTER_RENDER, '', self
283
- fac.create_can PARAMS, self
284
-
285
- params = { :name => HEAD,
286
- :type => Gloo::Objs::Element.typename,
287
- :value => nil,
288
- :parent => self }
289
- head = fac.create params
290
- content = fac.create_can CONTENT, head
291
- params = { :name => TITLE,
292
- :type => Gloo::Objs::Element.typename,
293
- :value => nil,
294
- :parent => content }
295
- title = fac.create params
296
-
297
- params = { :name => BODY,
298
- :type => Gloo::Objs::Element.typename,
299
- :value => nil,
300
- :parent => self }
301
- body = fac.create params
302
- content = fac.create_can CONTENT, body
303
- end
304
-
305
-
306
- # ---------------------------------------------------------------------
307
- # Messages
308
- # ---------------------------------------------------------------------
309
-
310
- #
311
- # Get a list of message names that this object receives.
312
- #
313
- def self.messages
314
- return super + [ 'render' ]
315
- end
316
-
317
- #
318
- # Get the expiration date for the certificate.
319
- #
320
- def msg_render
321
- content = self.render
322
- @engine.heap.it.set_to content
323
- return content
324
- end
325
-
326
-
327
- # ---------------------------------------------------------------------
328
- # Render
329
- # ---------------------------------------------------------------------
330
-
331
- #
332
- # Wrap the content in the tag with id and class.
333
- #
334
- def wrap( tag, content, id=nil, classes=nil )
335
- return "<#{tag}>#{content}</#{tag}>"
336
- end
337
-
338
- #
339
- # Is there a redirect page set in the running app?
340
- #
341
- def redirect_set?
342
- return false unless @engine.app_running?
343
- return @engine.running_app.obj.redirect
344
- end
345
-
346
- #
347
- # Set the ID parameter if there is one.
348
- #
349
- def set_id
350
- return unless @request.request_params.id
351
- @engine.log.info "Setting ID: #{@request.request_params.id}"
352
-
353
- params_can = find_child PARAMS
354
- return nil unless params_can
355
-
356
- id_obj = params_can.find_child( ID )
357
- return unless id_obj
358
-
359
- id_obj.set_value( @request.request_params.id )
360
- end
361
-
362
- #
363
- # Render the page.
364
- # If this is being called from the web server,
365
- # the request will be passed in and will include
366
- # request context such as params.
367
- #
368
- def render request=nil
369
- @request = request
370
-
371
- # TODO : refactor this
372
- set_id if @request
373
-
374
- # Put params from request into params container.
375
- init_params
376
-
377
- # Run the on prerender script
378
- run_on_prerender
379
-
380
- # Get Params hash before running on render
381
- params = params_hash
382
-
383
- run_on_render
384
- return nil if redirect_set?
385
-
386
- if is_html?
387
- contents = render_html params
388
- elsif is_json?
389
- contents = render_json
390
- elsif is_text?
391
- contents = render_text params
392
- elsif is_file?
393
- contents = render_file params
394
- else
395
- @engine.err "Unknown content type: #{content_type}"
396
- return nil
397
- end
398
-
399
- run_after_render
400
- @request = nil
401
- return nil if redirect_set?
402
-
403
- return contents
404
- end
405
-
406
- #
407
- # Render the page as HTML.
408
- #
409
- def render_html params
410
- head_obj = render_with_params head_content, :render_html, params
411
- body_obj = render_with_params body_content, :render_html, params
412
-
413
- layout = page_layout_or_app_layout
414
- if layout
415
- @engine.log.debug "Using Page Layout: #{layout.pn}"
416
- contents = layout.render_layout( head_obj, body_obj )
417
- else
418
- @engine.log.debug "No layout for page."
419
- contents = wrap( 'html', head_obj + body_obj )
420
- end
421
-
422
- return Gloo::WebSvr::Response.html_response(
423
- @engine, contents, return_code )
424
- end
425
-
426
- #
427
- # Get the layout for this page or if none for the app.
428
- #
429
- def page_layout_or_app_layout
430
- layout = page_layout
431
- return layout if layout
432
-
433
- return nil unless @engine.app_running?
434
- return @engine.running_app.obj.default_page_layout
435
- end
436
-
437
- #
438
- # Render the page as JSON.
439
- #
440
- def render_json
441
- json_content = Gloo::Objs::Json.convert_obj_to_json( body )
442
-
443
- return Gloo::WebSvr::Response.json_response( @engine, json_content, return_code )
444
- end
445
-
446
- #
447
- # Render the page as TEXT.
448
- #
449
- def render_text params
450
- text_content = render_with_params body_content, :render_text, params
451
- return Gloo::WebSvr::Response.text_response( @engine, text_content, return_code )
452
- end
453
-
454
- #
455
- # Given an object and a render message, render the object.
456
- # If the obj is nil, return an empty string.
457
- # If the params are nil, no param rendering is done.
458
- #
459
- def render_with_params obj, render_ƒ, params
460
- return '' unless obj
461
-
462
- content = Element.render_obj( obj, render_ƒ, @engine )
463
- # content = Page.render_params( content, params ) if params
464
- content = @engine.running_app.obj.embedded_renderer.render content, params
465
-
466
- return content
467
- end
468
-
469
- #
470
- # Render content with the given params.
471
- # Params might be nil, in which case the content
472
- # is returned with no changes.
473
- #
474
- def self.render_params content, params
475
- return content unless params
476
-
477
- renderer = ERB.new( content )
478
- content = renderer.result_with_hash( params )
479
-
480
- return content
481
- end
482
-
483
-
484
- # ---------------------------------------------------------------------
485
- # File Renderer
486
- # ---------------------------------------------------------------------
487
-
488
- #
489
- # Get the type of the file.
490
- #
491
- def file_type
492
- o = find_child FILE_TYPE
493
- return nil unless o
494
-
495
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
496
- return o&.value
497
- end
498
-
499
- #
500
- # Get the path to the file.
501
- #
502
- def file_path
503
- o = find_child FILE_PATH
504
- return nil unless o
505
-
506
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
507
- return o&.value
508
- end
509
-
510
- #
511
- # Get the File content
512
- #
513
- def file_data
514
- o = find_child FILE_DATA
515
- return nil unless o
516
-
517
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
518
- return o&.value
519
- end
520
-
521
- #
522
- # Get the name of the file.
523
- #
524
- def file_name
525
- o = find_child FILE_NAME
526
- return nil unless o
527
-
528
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
529
- return o&.value
530
- end
531
-
532
- def download_file
533
- o = find_child DOWNLOAD_FILE
534
- return false unless o
535
-
536
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
537
- return o&.value
538
- end
539
-
540
- #
541
- # Render a file.
542
- #
543
- def render_file params
544
- type = file_type
545
- inline_content = file_data
546
- if inline_content.nil?
547
- data = File.binread( file_path )
548
- else
549
- data = inline_content
550
- end
551
- code = Gloo::WebSvr::ResponseCode::SUCCESS
552
- fname = file_name
553
- download = download_file
554
-
555
- return Gloo::WebSvr::Response.new(
556
- @engine, code, type, data, true, fname, download )
557
- end
558
-
559
-
560
- end
561
- end
562
- end