gloo-web 1.2 → 1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15a8ed82554f9691848a3595dc35c1514be0993e332050e6743009f46d3f777b
4
- data.tar.gz: 0b353704a315cb1e9204deb0f8017f323008e9a65190bf38eb1094ce8eb15345
3
+ metadata.gz: db9c3c1ddca5986e3acf080e031fd88187c7fc743152d066677908652bf802ae
4
+ data.tar.gz: cc217525025e16cd209d109aeb5b4b564bf3312854a50236fd022a65ef92cdac
5
5
  SHA512:
6
- metadata.gz: 778d8d07bc02f32c5810f02ada22eba83d81adb4494f4da094b6a264f6ea381767a074d0cb30f01a2e4fd4381846829d205f8135ab64c58eb69e988cf6512e87
7
- data.tar.gz: 36c5287f9c031223729550df5c545c54e746a71ab79fcc6fd3309dc31893fdafffea9a55c8e6b041cbd747d0c3f64d78b06adc2bc3023e99fe5ef72d6069609b
6
+ metadata.gz: faa216dabd0a11c80e23b697fe55c5caf84a2756451d41d20df0fafd6f8812a5432e40245241e6229771e5898bc40db2c7bf30ed50c448037b887da487704d54
7
+ data.tar.gz: 5388fb65528f5c1bd6df05e41d64c62fcca58ba77eab5676c12932d721aa041327a822765413f3e9e07fb4a5a623a1fc8c1bca02fad10d5ee5ca4ed2aec19f17
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # gloo-web
2
+
3
+ A core gloo library with a web server and web application framework.
4
+
5
+ Provides pages, forms, and HTML elements, hosted by an in-process web server, with routing, sessions, and AJAX support built in.
6
+
7
+ ## Usage
8
+
9
+ Load this library in a gloo script:
10
+
11
+ ```gloo
12
+ > load lib web
13
+ ```
14
+
15
+ ## Objects
16
+
17
+ - `server` — a web server running inside gloo
18
+ - `page` — a web page hosted in a gloo web server
19
+ - `partial` — a partial web page (a reusable fragment, rendered into other pages)
20
+ - `form` — an HTML form, containing a collection of form fields
21
+ - `field` — an HTML form field (text field, checkbox, etc.)
22
+ - `element` — an HTML element
23
+
24
+ ## Full Reference
25
+
26
+ Every object's children and messages are documented in-app once the library is loaded — e.g. `help> object page`.
data/lib/objs/element.rb CHANGED
@@ -248,5 +248,40 @@ module Objs
248
248
  end
249
249
  end
250
250
 
251
+ # ---------------------------------------------------------------------
252
+ # Object Documentation
253
+ # ---------------------------------------------------------------------
254
+
255
+ #
256
+ # Get the object's documentation data.
257
+ #
258
+ def self.doc_data
259
+ {
260
+ :name => KEYWORD,
261
+ :shortcut => KEYWORD_SHORT,
262
+ :description => 'An HTML element.',
263
+ :children => [
264
+ 'attributes (container) — All attributes are optional. The attributes of the HTML element, e.g. id (string) — the element id; classes (string) — element classes and styles (css).',
265
+ 'content (container) — The element contents.'
266
+ ],
267
+ :messages => [
268
+ 'render — Manually render the HTML element. Normally the render is called by the web server when the page containing the element is requested.'
269
+ ],
270
+ :examples => <<~EXAMPLES.strip
271
+ div_sub [e] :
272
+ attributes [can] :
273
+ id [string] : sub_area
274
+ class [string] : mt-3
275
+ content [can] :
276
+ h2 [e] : Sub
277
+ p [e] :
278
+ attributes [can] :
279
+ class [string] : lead
280
+ content [can] :
281
+ msg [string] : Sub area text goes here.
282
+ EXAMPLES
283
+ }
284
+ end
285
+
251
286
  end
252
287
  end
data/lib/objs/field.rb CHANGED
@@ -409,14 +409,14 @@ module Objs
409
409
  HTML
410
410
  end
411
411
 
412
- #
412
+ #
413
413
  # Render the select field as HTML.
414
- #
414
+ #
415
415
  def render_select
416
416
  return <<~HTML
417
417
  <div class="#{field_group_styles} #{cols_tag}">
418
418
  #{label_tag}
419
- <select class="#{field_control_styles}"
419
+ <select class="#{field_control_styles}"
420
420
  name="#{name_value}" id="#{name_value}">
421
421
  #{select_options}
422
422
  </select>
@@ -424,5 +424,70 @@ module Objs
424
424
  HTML
425
425
  end
426
426
 
427
+ # ---------------------------------------------------------------------
428
+ # Object Documentation
429
+ # ---------------------------------------------------------------------
430
+
431
+ #
432
+ # Get the object's documentation data.
433
+ #
434
+ def self.doc_data
435
+ {
436
+ :name => KEYWORD,
437
+ :shortcut => KEYWORD_SHORT,
438
+ :description => 'An HTML form field. Might be a text field, a ' \
439
+ 'checkbox, a select list or other type of form field.',
440
+ :children => [
441
+ 'name (string) — Optional; if not specified, the name of the object is used. Used for both the name and the id of the field element.',
442
+ 'type (string) — Required. Examples: text, checkbox, hidden, textarea, select, etc. Some other children depend on the type of the field.',
443
+ 'value (string) — Optional. The value of the field.',
444
+ 'label (string) — Optional; if not specified, the name of the field is used. The label for the field.',
445
+ 'autofocus (boolean) — Optional, default false. Whether the field should be focused when the page loads.',
446
+ 'placeholder (string) — Optional. The placeholder text for the field.',
447
+ 'cols (string) — Optional. The number of columns for the field, appended to the bootstrap column class (can also add offset or other column classes). Example: 6.',
448
+ 'rows (integer) — Optional. The number of rows for a textarea field; only used for textarea fields.',
449
+ 'field_group (string) — Optional override for form styles: the field group style classes.',
450
+ 'field_label (string) — Optional override for form styles: the field label style classes.',
451
+ 'field_control (string) — Optional override for form styles: the field control style classes.',
452
+ 'options (container) — Optional; only used for select fields. The options for the select field.',
453
+ 'checked (boolean) — Optional; only used for checkbox fields. Whether the checkbox field is checked.'
454
+ ],
455
+ :messages => [
456
+ 'render — Manually render the HTML field. Normally the render is called by the web server when the page containing the element is requested.'
457
+ ],
458
+ :examples => <<~EXAMPLES.strip
459
+ f [form] :
460
+ name [string] : message_form
461
+ action [string] : /messages
462
+ method [string] : post
463
+ cancel_path [string] : /messages
464
+ styles [alias] : form_styles
465
+ content [can] :
466
+ id [field] :
467
+ type [string] : hidden
468
+ value [string] : 13
469
+ message [field] :
470
+ type [string] : text
471
+ autofocus [boolean] : true
472
+ placeholder [string] : the message goes here…
473
+ description [field] :
474
+ type [string] : text
475
+ placeholder [string] : longer description…
476
+ opt [field] :
477
+ label [string] : Option
478
+ type [string] : select
479
+ value [string] : Option 3
480
+ options [can] :
481
+ 1 [string] : Option 1
482
+ 2 [string] : Option 2
483
+ 3 [string] : Option 3
484
+ box [field] :
485
+ type [string] : checkbox
486
+ checked [boolean] : false
487
+ description [string] : Check this box if you want to box it.
488
+ EXAMPLES
489
+ }
490
+ end
491
+
427
492
  end
428
493
  end
data/lib/objs/form.rb CHANGED
@@ -253,9 +253,9 @@ module Objs
253
253
  return fields
254
254
  end
255
255
 
256
- #
256
+ #
257
257
  # Render a string or other object.
258
- #
258
+ #
259
259
  def render_thing e
260
260
  begin
261
261
  return e.render( 'render_html' )
@@ -265,5 +265,60 @@ module Objs
265
265
  end
266
266
  end
267
267
 
268
+ # ---------------------------------------------------------------------
269
+ # Object Documentation
270
+ # ---------------------------------------------------------------------
271
+
272
+ #
273
+ # Get the object's documentation data.
274
+ #
275
+ def self.doc_data
276
+ {
277
+ :name => KEYWORD,
278
+ :shortcut => KEYWORD_SHORT,
279
+ :description => 'An HTML form. Contains a collection of form fields.',
280
+ :children => [
281
+ 'name (string) — The name of the form, used for both the name and the id of the form element.',
282
+ 'action (string) — The URL to which the form is submitted.',
283
+ "method (string) — Optional, default 'post'. The HTTP method used to submit the form.",
284
+ 'cancel_path (string) — The URL to which the form is submitted when the cancel button is clicked.',
285
+ 'styles (container) — Container of style classes for the form. Children: actions_div, submit, cancel, field_group, field_label, field_control.',
286
+ 'content (container) — The collection of form fields. Other elements can also be included here, for formatting or extra buttons.'
287
+ ],
288
+ :messages => [
289
+ 'render — Manually render the HTML form. Normally the render is called by the web server when the page containing the element is requested.'
290
+ ],
291
+ :examples => <<~EXAMPLES.strip
292
+ page [can] :
293
+ messages [can] :
294
+ new [page] :
295
+
296
+ head [e] :
297
+ content [can] :
298
+ title [e] : New Message
299
+
300
+ body [e] :
301
+ content [can] :
302
+ nav [alias] : shared.nav
303
+ h2 [e] : New Message
304
+ f [form] :
305
+ name [string] : message_form
306
+ action [string] : /messages
307
+ method [string] : post
308
+ cancel_path [string] : /messages
309
+ styles [alias] : form_styles
310
+ content [can] :
311
+ id [field] :
312
+ type [string] : hidden
313
+ value [string] : 13
314
+ message [field] :
315
+ type [string] : text
316
+ autofocus [boolean] : true
317
+ placeholder [string] : the message goes here…
318
+
319
+ EXAMPLES
320
+ }
321
+ end
322
+
268
323
  end
269
324
  end
data/lib/objs/page.rb CHANGED
@@ -551,10 +551,56 @@ module Objs
551
551
  fname = file_name
552
552
  download = download_file
553
553
 
554
- return WebSvr::Response.new(
554
+ return WebSvr::Response.new(
555
555
  @engine, code, type, data, true, fname, download )
556
556
  end
557
557
 
558
+ # ---------------------------------------------------------------------
559
+ # Object Documentation
560
+ # ---------------------------------------------------------------------
561
+
562
+ #
563
+ # Get the object's documentation data.
564
+ #
565
+ def self.doc_data
566
+ {
567
+ :name => KEYWORD,
568
+ :shortcut => KEYWORD_SHORT,
569
+ :description => 'A web page hosted in a gloo web server.',
570
+ :children => [
571
+ 'layout (partial) — Optional, uses the server default if not specified.',
572
+ 'on_prerender (script) — Optional. Run before the page is rendered. Mostly used if you need to manually update parameters to the page.',
573
+ 'on_render (script) — Run when the page is going to be rendered.',
574
+ 'after_render (script) — Run after the page has been rendered.',
575
+ 'params (container) — Optional. Parameters to the page when rendered — values populated by scripts, or query parameters mapped to children of the same name (children are not auto-created to match query params; they must be declared to specify which ones are expected).',
576
+ 'head (element) — Elements to be added to the page header.',
577
+ 'body (element) — Elements to be added to the page body.',
578
+ 'For file-rendering pages (rendering a file instead of HTML):',
579
+ "content_type (string) — Value 'file'. Indicates that this page renders a file rather than HTML.",
580
+ 'file_type (string) — Example: image/png. The type of file to be rendered.',
581
+ 'file_path (file) — Optional; used when the content refers to a file on disk. Either file_path or file_data must be specified, not both.',
582
+ 'file_data (text) — Optional; used when the content is dynamically generated. Either file_path or file_data must be specified, not both.',
583
+ 'file_name (string) — Optional. Name of the file to be rendered; may differ from the URL used to access it.',
584
+ 'download_file (boolean) — Optional, default false. If true, the browser is instructed to download the file instead of rendering it.'
585
+ ],
586
+ :messages => [
587
+ 'render — Manually render the content of the page. Normally the render is called by the web server when the page is requested.'
588
+ ],
589
+ :examples => <<~EXAMPLES.strip
590
+ page [can] :
591
+ home [page] :
592
+ layout [alias] : layout.primary
593
+ params [container] :
594
+ msg [string] : Hello World!
595
+ head [can] :
596
+ title [e] : My Page
597
+ body [e] :
598
+ content [can] :
599
+ h1 [e] : Hello!
600
+ p [e] : message <%= msg %>
601
+ EXAMPLES
602
+ }
603
+ end
558
604
 
559
605
  end
560
606
  end
data/lib/objs/partial.rb CHANGED
@@ -204,5 +204,49 @@ module Objs
204
204
  return part_content
205
205
  end
206
206
 
207
+ # ---------------------------------------------------------------------
208
+ # Object Documentation
209
+ # ---------------------------------------------------------------------
210
+
211
+ #
212
+ # Get the object's documentation data.
213
+ #
214
+ def self.doc_data
215
+ {
216
+ :name => KEYWORD,
217
+ :shortcut => KEYWORD_SHORT,
218
+ :description => 'A partial web page hosted in a gloo web ' \
219
+ 'server. By convention use an underscore prefix in the name ' \
220
+ "of the partial — e.g. _icons.gloo — to set it apart from " \
221
+ 'pages and other gloo files.',
222
+ :children => [
223
+ 'on_render (script) — Run when the partial page is going to be rendered.',
224
+ 'after_render (script) — Run after the partial page has been rendered.',
225
+ 'params (container) — Optional. Parameters to the partial page when rendered.',
226
+ 'content (element) — The contents of the partial page.'
227
+ ],
228
+ :messages => [
229
+ 'render — Manually render the content of the partial page. Normally the render is called by the web server when the page containing the partial is requested.'
230
+ ],
231
+ :examples => <<~EXAMPLES.strip
232
+ shared [can] :
233
+ nav [part] :
234
+ on_render [script] :
235
+ put ^.params.cnt + 1 into ^.params.cnt
236
+ params [container] :
237
+ cnt [int] : 0
238
+ content [can] :
239
+ div_nav [e] : BEGIN
240
+ <div class="mt-1 mb-3">
241
+ <a href="/">
242
+ <button type="button" class="btn btn-primary">
243
+ Home </button></a>
244
+ <%= cnt %>
245
+ </div>
246
+ END
247
+ EXAMPLES
248
+ }
249
+ end
250
+
207
251
  end
208
252
  end
data/lib/objs/svr.rb CHANGED
@@ -696,9 +696,9 @@ module Objs
696
696
  return o
697
697
  end
698
698
 
699
- #
699
+ #
700
700
  # Get the default layout for pages.
701
- #
701
+ #
702
702
  def default_layout
703
703
  o = find_child LAYOUT
704
704
  return nil unless o
@@ -707,5 +707,80 @@ module Objs
707
707
  return o
708
708
  end
709
709
 
710
+ # ---------------------------------------------------------------------
711
+ # Object Documentation
712
+ # ---------------------------------------------------------------------
713
+
714
+ #
715
+ # Get the object's documentation data.
716
+ #
717
+ def self.doc_data
718
+ {
719
+ :name => KEYWORD,
720
+ :shortcut => KEYWORD_SHORT,
721
+ :description => 'A web server running inside gloo.',
722
+ :children => [
723
+ 'config (container) — Configuration and settings for the server. See below for its children.',
724
+ 'on_start (script) — Run when the web server is started.',
725
+ 'on_stop (script) — Run when the web server is stopped.',
726
+ "layout (partial) — By convention an alias pointing to the layout used for all pages (layouts live in the layout root-level folder).",
727
+ 'home (page) — By convention an alias pointing to the home page object (pages live in the page root-level folder).',
728
+ 'error (page) — By convention an alias pointing to the default error page object.',
729
+ 'pages (container) — Routes. By convention, aliases pointing to pages in the page root-level folder.',
730
+ 'config.scheme (string) — \'http\' or \'https\'.',
731
+ "config.host (string) — Default: 'localhost'.",
732
+ "config.port (string) — Default: '8080'.",
733
+ 'config.session_name (string) — Optional. Example: \'_myapp_session\'. The name of the session cookie.',
734
+ 'config.encryption_key (string) — Optional. Encryption key for the session cookie.',
735
+ 'config.encryption_iv (string) — Optional. Initialization vector for the session cookie encryption key.',
736
+ "config.cookie_expires (string) — Optional, default 'in 1 week'. When the session expires.",
737
+ "config.cookie_path (string) — Optional, default '/'. The path for the session cookie.",
738
+ 'config.ssl_cert (string) — Optional, required for SSL. Path to certificate.pem.',
739
+ 'config.ssl_key (string) — Optional, required for SSL. Path to key.pem.',
740
+ 'on_request (script) — Optional. Run when the web server receives a request.',
741
+ 'request_data (container) — Optional. Data available for use in on_request or elsewhere in the page rendering life-cycle: method, host, path, query, ip (all string, all optional, populated only if present).',
742
+ 'on_response (script) — Optional. Run when the web server is done rendering and about to return a response.',
743
+ 'response_data (container) — Optional. Data available for use in on_response (request_data is also available at this point): page, type, code, elapsed, db (all string, all optional, populated only if present).'
744
+ ],
745
+ :messages => [
746
+ 'start — Start the web server.',
747
+ 'stop — Stop the web server.',
748
+ 'list_routes — Show the routing table. A debugging tool.',
749
+ 'list_assets — Show the list of assets. A debugging tool.',
750
+ 'list_asset_img — Show the list of image assets. A debugging tool.',
751
+ 'list_asset_css — Show the list of CSS assets. A debugging tool.',
752
+ 'list_asset_js — Show the list of JavaScript assets. A debugging tool.',
753
+ 'add_session_to_response — Tell the gloo web server to include the session data in the response (put in the session cookie). Use when the user successfully authenticates.',
754
+ 'clear_session_data — Clear the session data and tell the gloo web server to include the session data in the response. This destroys the session; use when the user logs out.'
755
+ ],
756
+ :examples => <<~EXAMPLES.strip
757
+ app [can] :
758
+ # The address of the running web server.
759
+ url [uri] : http://localhost:8083/
760
+
761
+ svr [svr] :
762
+ # Configuration for the web server.
763
+ config [container] :
764
+ scheme [string] : http
765
+ host [string] : localhost
766
+ port [string] : 8083
767
+
768
+ # Scripts to run when the server starts and stops.
769
+ on_start [script] : show '*** started ***'
770
+ on_stop [script] : show '*** stopped ***'
771
+
772
+ # Default Routes for the web server.
773
+ layout [alias] : layout.primary
774
+ home [alias] : page.home
775
+ error [alias] : page.err
776
+
777
+ # Routes for the web server.
778
+ pages [container] :
779
+ home [alias] : page.home
780
+ other [alias] : page.other
781
+ EXAMPLES
782
+ }
783
+ end
784
+
710
785
  end
711
786
  end
@@ -163,8 +163,13 @@ module WebSvr
163
163
  def decode_decrypt( data )
164
164
  return nil unless data && key && iv
165
165
 
166
- data = Gloo::Objs::Cipher.decrypt( data, key, iv )
167
- return JSON.parse( data )
166
+ begin
167
+ data = Gloo::Objs::Cipher.decrypt( data, key, iv )
168
+ return JSON.parse( data )
169
+ rescue => e
170
+ @engine.log_exception e
171
+ return nil
172
+ end
168
173
  end
169
174
 
170
175
  #
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo-web
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-02-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: thin
@@ -31,6 +30,7 @@ executables: []
31
30
  extensions: []
32
31
  extra_rdoc_files: []
33
32
  files:
33
+ - README.md
34
34
  - lib/gloo-web.rb
35
35
  - lib/objs/element.rb
36
36
  - lib/objs/field.rb
@@ -54,12 +54,12 @@ files:
54
54
  - lib/web_svr/session.rb
55
55
  - lib/web_svr/table_renderer.rb
56
56
  - lib/web_svr/web_method.rb
57
- homepage: https://gloo.ecrane.us/
57
+ homepage: https://github.com/ecrane/gloo
58
58
  licenses:
59
59
  - MIT
60
60
  metadata:
61
61
  gloo.type: core-library
62
- post_install_message:
62
+ documentation_uri: https://github.com/ecrane/gloo
63
63
  rdoc_options: []
64
64
  require_paths:
65
65
  - lib
@@ -74,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.5.16
78
- signing_key:
77
+ rubygems_version: 4.0.17
79
78
  specification_version: 4
80
79
  summary: Gloo core library. Web Server and framework.
81
80
  test_files: []