gloo 4.6.1 → 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 (69) 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 +12 -0
  6. data/lib/gloo/app/engine.rb +8 -1
  7. data/lib/gloo/app/running_app.rb +13 -0
  8. data/lib/gloo/app/settings.rb +5 -1
  9. data/lib/gloo/core/dictionary.rb +15 -2
  10. data/lib/gloo/objs/ctrl/each.rb +2 -2
  11. data/lib/gloo/plugin/base.rb +19 -0
  12. data/lib/gloo/plugin/callback.rb +33 -0
  13. data/lib/gloo/plugin/ext_manager.rb +90 -0
  14. data/lib/gloo/plugin/lib_manager.rb +97 -0
  15. data/lib/gloo/verbs/exists.rb +75 -0
  16. data/lib/gloo/verbs/help.rb +58 -1
  17. data/lib/gloo/verbs/load.rb +49 -5
  18. data/lib/gloo/verbs/redirect.rb +2 -1
  19. metadata +38 -166
  20. data/lib/gloo/objs/cli/colorize.rb +0 -73
  21. data/lib/gloo/objs/cli/confirm.rb +0 -96
  22. data/lib/gloo/objs/cli/menu.rb +0 -370
  23. data/lib/gloo/objs/cli/menu_item.rb +0 -95
  24. data/lib/gloo/objs/cli/prompt.rb +0 -110
  25. data/lib/gloo/objs/cli/select.rb +0 -127
  26. data/lib/gloo/objs/ctrl/each_repo.rb +0 -84
  27. data/lib/gloo/objs/data/markdown.rb +0 -133
  28. data/lib/gloo/objs/data/markdown_ext.rb +0 -260
  29. data/lib/gloo/objs/data/mysql.rb +0 -254
  30. data/lib/gloo/objs/data/pg.rb +0 -216
  31. data/lib/gloo/objs/data/query.rb +0 -269
  32. data/lib/gloo/objs/data/query_result.rb +0 -158
  33. data/lib/gloo/objs/data/sqlite.rb +0 -174
  34. data/lib/gloo/objs/data/table.rb +0 -267
  35. data/lib/gloo/objs/dev/git.rb +0 -140
  36. data/lib/gloo/objs/dev/stats.rb +0 -123
  37. data/lib/gloo/objs/system/ssh_exec.rb +0 -126
  38. data/lib/gloo/objs/web/slack.rb +0 -130
  39. data/lib/gloo/objs/web/teams.rb +0 -117
  40. data/lib/gloo/objs/web_svr/element.rb +0 -254
  41. data/lib/gloo/objs/web_svr/field.rb +0 -429
  42. data/lib/gloo/objs/web_svr/form.rb +0 -271
  43. data/lib/gloo/objs/web_svr/page.rb +0 -562
  44. data/lib/gloo/objs/web_svr/partial.rb +0 -210
  45. data/lib/gloo/objs/web_svr/svr.rb +0 -713
  46. data/lib/gloo/utils/stats.rb +0 -206
  47. data/lib/gloo/verbs/alert.rb +0 -79
  48. data/lib/gloo/verbs/beep.rb +0 -40
  49. data/lib/gloo/web_svr/asset.rb +0 -407
  50. data/lib/gloo/web_svr/asset_info.rb +0 -116
  51. data/lib/gloo/web_svr/config.rb +0 -56
  52. data/lib/gloo/web_svr/embedded_renderer.rb +0 -154
  53. data/lib/gloo/web_svr/handler.rb +0 -154
  54. data/lib/gloo/web_svr/request.rb +0 -143
  55. data/lib/gloo/web_svr/request_params.rb +0 -181
  56. data/lib/gloo/web_svr/response.rb +0 -177
  57. data/lib/gloo/web_svr/response_code.rb +0 -69
  58. data/lib/gloo/web_svr/routing/resource_router.rb +0 -47
  59. data/lib/gloo/web_svr/routing/router.rb +0 -232
  60. data/lib/gloo/web_svr/routing/show_routes.rb +0 -94
  61. data/lib/gloo/web_svr/server.rb +0 -105
  62. data/lib/gloo/web_svr/session.rb +0 -215
  63. data/lib/gloo/web_svr/table_renderer.rb +0 -151
  64. data/lib/gloo/web_svr/web_method.rb +0 -54
  65. /data/lib/gloo/objs/{security → str_utils}/cipher.rb +0 -0
  66. /data/lib/gloo/objs/{security → str_utils}/csrf_token.rb +0 -0
  67. /data/lib/gloo/objs/{security → str_utils}/password.rb +0 -0
  68. /data/lib/gloo/objs/{ror → system}/erb.rb +0 -0
  69. /data/lib/gloo/objs/{ror → system}/eval.rb +0 -0
@@ -1,407 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # A helper class for static assets.
5
- #
6
-
7
- module Gloo
8
- module WebSvr
9
- class Asset
10
-
11
- LIB_FOLDER = 'lib'.freeze
12
- ASSET_FOLDER = 'asset'.freeze
13
- IMAGE_FOLDER = 'image'.freeze
14
- STYLESHEET_FOLDER = 'stylesheet'.freeze
15
- JAVASCRIPT_FOLDER = 'javascript'.freeze
16
-
17
- CSS_TYPE = 'text/css'.freeze
18
- JS_TYPE = 'text/javascript'.freeze
19
-
20
- IMAGE_TYPE = 'image/'.freeze
21
- FAVICON_TYPE = 'image/x-icon'.freeze
22
-
23
-
24
- # ---------------------------------------------------------------------
25
- # Initialization
26
- # ---------------------------------------------------------------------
27
-
28
- #
29
- # Set up the web server.
30
- #
31
- def initialize( engine, web_svr_obj )
32
- @engine = engine
33
- @log = @engine.log
34
-
35
- @web_svr_obj = web_svr_obj
36
- end
37
-
38
-
39
- # ---------------------------------------------------------------------
40
- # lib asset Helpers
41
- # ---------------------------------------------------------------------
42
-
43
- #
44
- # Get the asset folder in the User's lib.
45
- # Returns nil if it does not exist.
46
- #
47
- def lib_asset_folder
48
- dir = File.join( @engine.settings.user_root, LIB_FOLDER, ASSET_FOLDER )
49
- return dir if Dir.exist?( dir )
50
-
51
- return nil
52
- end
53
-
54
- #
55
- # Get the stylesheets folder in the User's lib.
56
- # Returns nil if it does not exist.
57
- #
58
- def lib_stylesheet_folder
59
- dir = File.join( lib_asset_folder, STYLESHEET_FOLDER )
60
- return dir if Dir.exist?( dir )
61
-
62
- return nil
63
- end
64
-
65
- #
66
- # Get the javascript folder in the User's lib.
67
- # Returns nil if it does not exist.
68
- #
69
- def lib_javascript_folder
70
- dir = File.join( lib_asset_folder, JAVASCRIPT_FOLDER )
71
- return dir if Dir.exist?( dir )
72
-
73
- return nil
74
- end
75
-
76
- #
77
- # Get the images folder in the User's lib.
78
- # Returns nil if it does not exist.
79
- #
80
- def lib_image_folder
81
- dir = File.join( lib_asset_folder, IMAGE_FOLDER )
82
- return dir if Dir.exist?( dir )
83
-
84
- return nil
85
- end
86
-
87
-
88
- # ---------------------------------------------------------------------
89
- # Asset Helpers
90
- # ---------------------------------------------------------------------
91
-
92
- #
93
- # Get the asset folder in the project.
94
- #
95
- def asset_folder
96
- return File.join( @engine.settings.project_path, ASSET_FOLDER )
97
- end
98
-
99
- #
100
- # Get the images folder in the project.
101
- #
102
- def image_folder
103
- return File.join( asset_folder, IMAGE_FOLDER )
104
- end
105
-
106
- #
107
- # Get the stylesheets folder in the project.
108
- #
109
- def stylesheet_folder
110
- return File.join( asset_folder, STYLESHEET_FOLDER )
111
- end
112
-
113
- #
114
- # Get the stylesheets folder in the project.
115
- #
116
- def javascript_folder
117
- return File.join( asset_folder, JAVASCRIPT_FOLDER )
118
- end
119
-
120
- #
121
- # Find and return the page for the given route.
122
- #
123
- def path_for_file file
124
- pn = file.value
125
-
126
- # Is the file's value a recognizable file?
127
- return pn if File.exist? pn
128
-
129
- # Look in the web server's asset folder.
130
- pn = File.join( asset_folder, pn )
131
-
132
- # Try the lib assets if not found
133
- unless File.exist? pn
134
- lib = lib_asset_folder
135
- pn = File.join( lib, file.value ) if lib
136
- end
137
-
138
- return pn
139
- end
140
-
141
- #
142
- # Get the return type for the given file.
143
- #
144
- def type_for_file file
145
- ext = File.extname( file ).downcase
146
- ext = ext[1..-1] if ext[0] == '.'
147
-
148
- if ext == 'css'
149
- return CSS_TYPE
150
- elsif ext == 'js'
151
- return JS_TYPE
152
- elsif ext == 'ico'
153
- return FAVICON_TYPE
154
- else
155
- return "#{IMAGE_TYPE}#{ext}"
156
- end
157
- end
158
-
159
-
160
- # ---------------------------------------------------------------------
161
- # Render Asset
162
- # ---------------------------------------------------------------------
163
-
164
- #
165
- # Helper to create a successful image response with the given data.
166
- #
167
- def render_file( file )
168
- type = type_for_file file
169
- data = File.binread file
170
- code = Gloo::WebSvr::ResponseCode::SUCCESS
171
-
172
- return Gloo::WebSvr::Response.new( @engine, code, type, data, true )
173
- end
174
-
175
- #
176
- # Check if the given name is an asset.
177
- #
178
- def is_asset? name
179
- return name == ASSET_FOLDER
180
- end
181
-
182
-
183
- # ---------------------------------------------------------------------
184
- # Asset with Fingerprints
185
- # ---------------------------------------------------------------------
186
-
187
- #
188
- # Register an asset with the web server.
189
- # Adds fingerprint to the file names for later access.
190
- #
191
- # full_path is the FILE from which we build the SHA256 hash
192
- # pn is the path and name within the assets directory
193
- # name is the simple file name (icon.png)
194
- #
195
- def register_asset name, pn, full_path
196
- asset_pn = "/asset/#{pn}"
197
- return AssetInfo.new( @engine, full_path, name, asset_pn ).register
198
- end
199
-
200
- #
201
- # Get the published name for the given asset name.
202
- #
203
- def published_name asset_name
204
- return AssetInfo.find_published_name_for( asset_name )
205
- end
206
-
207
-
208
- # ---------------------------------------------------------------------
209
- # Dynamic Add Assets
210
- # ---------------------------------------------------------------------
211
-
212
- #
213
- # Add all asssets to the web server pages (routes).
214
- #
215
- def add_asset_routes
216
- return unless File.exist? asset_folder
217
-
218
- @log.debug 'Adding asset routes to web server…'
219
- @factory = @engine.factory
220
-
221
- add_containers
222
- add_images
223
- add_stylesheets
224
- add_javascript
225
- end
226
-
227
- #
228
- # Create the containers for the assets if they do not exist.
229
- #
230
- def add_containers
231
- pages = @web_svr_obj.pages_container
232
-
233
- @assets = pages.find_child( ASSET_FOLDER ) ||
234
- @factory.create_can( ASSET_FOLDER, pages )
235
-
236
- @images = @assets.find_child( IMAGE_FOLDER ) ||
237
- @factory.create_can( IMAGE_FOLDER, @assets )
238
-
239
- @stylesheets = @assets.find_child( STYLESHEET_FOLDER ) ||
240
- @factory.create_can( STYLESHEET_FOLDER, @assets )
241
-
242
- @javascript = @assets.find_child( JAVASCRIPT_FOLDER ) ||
243
- @factory.create_can( JAVASCRIPT_FOLDER, @assets )
244
- end
245
-
246
- #
247
- # Traverse the given folder and add all files to the container.
248
- # This is a recursive method and look look for files in subfolders.
249
- #
250
- def add_files_in_folder( folder, container, path )
251
- Dir.each_child( folder ) do |name|
252
- pn = File.join( path, name )
253
- full_path = File.join( folder, name )
254
-
255
- if File.directory? full_path
256
- child = container.find_child( name )
257
- child = @factory.create_can( name, container ) if child.nil?
258
-
259
- add_files_in_folder( full_path, child, pn )
260
- else
261
- info = register_asset( name, pn, full_path )
262
- add_file_obj( container, name, pn, info )
263
- end
264
- end
265
- end
266
-
267
- #
268
- # Add the images to the web server pages.
269
- #
270
- def add_images
271
- @log.debug 'Adding image asset routes to web server…'
272
-
273
- lib = lib_image_folder
274
- if lib
275
- add_files_in_folder( lib, @images, IMAGE_FOLDER )
276
- end
277
-
278
- return unless File.exist? image_folder
279
-
280
- # for each file in the images folder
281
- # create a file object and add it to the images container
282
- add_files_in_folder( image_folder, @images, IMAGE_FOLDER )
283
- end
284
-
285
- #
286
- # Add the stylesheets to the web server pages.
287
- #
288
- def add_stylesheets
289
- @log.debug 'Adding stylesheet asset routes to web server…'
290
-
291
- lib = lib_stylesheet_folder
292
- if lib
293
- add_files_in_folder( lib, @stylesheets, STYLESHEET_FOLDER )
294
- end
295
-
296
- return unless File.exist? stylesheet_folder
297
-
298
- # for each file in the stylesheets folder
299
- # create a file object and add it to the stylesheets container
300
- add_files_in_folder( stylesheet_folder, @stylesheets, STYLESHEET_FOLDER )
301
-
302
- # Dir.each_child( stylesheet_folder ) do |name|
303
- # pn = File.join( STYLESHEET_FOLDER, name )
304
- # add_file_obj( @stylesheets, name, pn )
305
- # end
306
- end
307
-
308
- #
309
- # Add the Javascript files to the web server pages.
310
- #
311
- def add_javascript
312
- @log.debug 'Adding javascript asset routes to web server…'
313
-
314
- lib = lib_javascript_folder
315
- if lib
316
- add_files_in_folder( lib, @javascript, JAVASCRIPT_FOLDER )
317
- end
318
-
319
- return unless File.exist? javascript_folder
320
-
321
- # for each file in the javascript folder
322
- # create a file object and add it to the javascript container
323
- add_files_in_folder( javascript_folder, @javascript, JAVASCRIPT_FOLDER )
324
-
325
- # Dir.each_child( javascript_folder ) do |name|
326
- # pn = File.join( JAVASCRIPT_FOLDER, name )
327
- # add_file_obj( @javascript, name, pn )
328
- # end
329
- end
330
-
331
- #
332
- # Add a file object (page route) to the given container.
333
- #
334
- def add_file_obj( can, name, pn, info )
335
- name = name.gsub( '.', '_' )
336
- @log.debug "Adding route for file: #{name}"
337
-
338
- # First make sure the child doesn't already exist.
339
- child = can.find_child( name )
340
- return if child
341
-
342
- @factory.create_file( name, pn, can )
343
- # @factory.create_file( info.published_name, pn, can )
344
- end
345
-
346
-
347
- # ---------------------------------------------------------------------
348
- # List Asset Helpers
349
- # ---------------------------------------------------------------------
350
-
351
- #
352
- # List all image assets.
353
- # This looks in the image container and lists the images found earlier.
354
- # A Debugging tool.
355
- #
356
- def list_image_assets
357
- data = []
358
- @images.children.each do |o|
359
- data << [ o.name, o.pn, o.value ]
360
- end
361
- headers = [ "Name", "PN", "Value" ]
362
-
363
- puts Gloo::App::Platform::RETURN
364
- title = "Image Assets with Routes"
365
- @engine.platform.table.show headers, data, title
366
- puts Gloo::App::Platform::RETURN
367
- end
368
-
369
- #
370
- # List all js assets.
371
- # This looks in the js container and lists the js files found earlier.
372
- # A Debugging tool.
373
- #
374
- def list_js_assets
375
- data = []
376
- @javascript.children.each do |o|
377
- data << [ o.name, o.pn, o.value ]
378
- end
379
- headers = [ "Name", "PN", "Value" ]
380
-
381
- puts Gloo::App::Platform::RETURN
382
- title = "JavaScript Assets with Routes"
383
- @engine.platform.table.show headers, data, title
384
- puts Gloo::App::Platform::RETURN
385
- end
386
-
387
- #
388
- # List all css assets.
389
- # This looks in the css container and lists the css files found earlier.
390
- # A Debugging tool.
391
- #
392
- def list_css_assets
393
- data = []
394
- @stylesheets.children.each do |o|
395
- data << [ o.name, o.pn, o.value ]
396
- end
397
- headers = [ "Name", "PN", "Value" ]
398
-
399
- puts Gloo::App::Platform::RETURN
400
- title = "Stylesheet Assets with Routes"
401
- @engine.platform.table.show headers, data, title
402
- puts Gloo::App::Platform::RETURN
403
- end
404
-
405
- end
406
- end
407
- end
@@ -1,116 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2025 Eric Crane. All rights reserved.
3
- #
4
- # Information about a single asset.
5
- #
6
- # Full Path is the full path to the file in the file system.
7
- # Name is the name of the file with extension.
8
- # PN is the path within assets and the name.
9
- # ie: /asset/stylesheet/stylesheet.css
10
- # Hash is the SHA256 hash of the file.
11
- # Published Name is the name of the file that is published
12
- # to the web server, and includes the hash.
13
- #
14
-
15
- module Gloo
16
- module WebSvr
17
- class AssetInfo
18
-
19
- # Class Variables
20
- @@index_by_published = {}
21
- @@index_by_pn = {}
22
-
23
- attr_reader :name, :pn, :published_name, :published_pn, :hash
24
-
25
-
26
- # ---------------------------------------------------------------------
27
- # Initialization
28
- # ---------------------------------------------------------------------
29
-
30
- #
31
- # Set up an asset information object.
32
- #
33
- def initialize( engine, full_path, name, pn )
34
- @engine = engine
35
- @log = @engine.log
36
-
37
- @full_path = full_path
38
- @name = name
39
- @pn = pn
40
- end
41
-
42
-
43
- # ---------------------------------------------------------------------
44
- # Functions
45
- # ---------------------------------------------------------------------
46
-
47
- #
48
- # Register the asset with indexes, inflating all needed data elements.
49
- #
50
- def register
51
- @log.debug "*** REGISTERING ASSET: #{@name}"
52
- @log.debug "*** #{@full_path} "
53
- @log.debug "*** #PN: #{@pn} name: #{@name}"
54
-
55
- @hash = Gloo::Objs::FileHandle.hash_for_file( @full_path )
56
-
57
- # Build published name
58
- ext = File.extname( @pn ) # Gets just the extension
59
- n = @name[ 0..-ext.length - 1 ]
60
- pn = @pn[ 0..-ext.length - 1 ]
61
-
62
- @published_name = "#{n}-#{@hash}#{ext}"
63
- @published_pn = "#{pn}-#{@hash}#{ext}"
64
-
65
- @log.debug "*** Published Name: #{@published_name}"
66
- @log.debug "*** Published Path: #{@published_pn}"
67
-
68
- # Add to indexes
69
- AssetInfo.index self
70
- end
71
-
72
- #
73
- # Index the the given asset info record.
74
- #
75
- def self.index info
76
- return unless info
77
-
78
- @@index_by_pn[ info.pn ] = info
79
- @@index_by_published[ info.published_pn ] = info
80
- end
81
-
82
- #
83
- # Find the asset info for the given published name.
84
- #
85
- def self.find_published_name_for pn
86
- return nil unless pn
87
-
88
- return @@index_by_pn[ pn ]&.published_pn
89
- end
90
-
91
- #
92
- # Find the asset info for the given published name.
93
- #
94
- def self.find_info_for pn
95
- return @@index_by_published[ pn ]
96
- end
97
-
98
- #
99
- # List All assets.
100
- #
101
- def self.list_all engine
102
- data = []
103
- @@index_by_pn.each do |pn, info|
104
- data << [ info.name, info.pn, info.published_pn ]
105
- end
106
- headers = [ "Name", "Asset Path", "Published" ]
107
-
108
- puts Gloo::App::Platform::RETURN
109
- title = "Assets in Running Web App"
110
- engine.platform.table.show headers, data, title
111
- puts Gloo::App::Platform::RETURN
112
- end
113
-
114
- end
115
- end
116
- end
@@ -1,56 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # Configuration for a gloo web server.
5
- #
6
-
7
- module Gloo
8
- module WebSvr
9
- class Config
10
-
11
- SCHEME_SEPARATOR = '://'
12
- HTTP = 'http'
13
- HTTPS = 'https'
14
- LOCALHOST = 'localhost'
15
- PORT_DEFAULT = '8080'
16
-
17
- attr_reader :scheme, :host, :port
18
-
19
-
20
- # ---------------------------------------------------------------------
21
- # Initialization
22
- # ---------------------------------------------------------------------
23
-
24
- #
25
- # Set up the web server.
26
- #
27
- def initialize( scheme = HTTP, host = LOCALHOST, port = PORT_DEFAULT )
28
- @scheme = scheme
29
- @host = host
30
- @port = port
31
- end
32
-
33
-
34
- # ---------------------------------------------------------------------
35
- # Static Helper Functions
36
- # ---------------------------------------------------------------------
37
-
38
-
39
- # ---------------------------------------------------------------------
40
- # Helper Functions
41
- # ---------------------------------------------------------------------
42
-
43
- #
44
- # The base url, including scheme, host and port.
45
- #
46
- def base_url
47
- url = "#{self.scheme}#{SCHEME_SEPARATOR}#{self.host}"
48
- unless self.port.blank?
49
- url << ":#{self.port}"
50
- end
51
- return url
52
- end
53
-
54
- end
55
- end
56
- end