gloo-web 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6900b170922bb867ef849c9391a960487bdc632f90fa15f90e7cd1d277646335
4
+ data.tar.gz: b5073a6ef232aa5c104151cf83ab709f6637be3d0ec72d06b9636cdbc37b5756
5
+ SHA512:
6
+ metadata.gz: 7379751042a00c1e76e49c32ca645241e65d8f33bf994fa2ce08cbe46f368e507eecc279e47940ad13124179fb3ed58ff86695b71ec197855de8c01d621cdf16
7
+ data.tar.gz: 26d890475c4ef8e1e32696b5d8ed7e685b5cf350465b05daa416887d49991928d741986727e35f37726b43db774cf19b24a4ea9ce8cb72ca92f1c7cf7ddd23e5
data/lib/gloo-web.rb ADDED
@@ -0,0 +1,48 @@
1
+ #
2
+ # Shim to allow `require 'gloo-web'`
3
+ #
4
+ # This file is loaded when someone does `require 'gloo-web'`
5
+ #
6
+ require 'objs/element'
7
+ require 'objs/field'
8
+ require 'objs/form'
9
+ require 'objs/page'
10
+ require 'objs/partial'
11
+ require 'objs/svr'
12
+
13
+ require 'routing/show_routes'
14
+ require 'routing/resource_router'
15
+ require 'routing/router'
16
+
17
+ require 'web_svr/asset_info'
18
+ require 'web_svr/asset'
19
+ require 'web_svr/config'
20
+ require 'web_svr/embedded_renderer'
21
+ require 'web_svr/handler'
22
+ require 'web_svr/request_params'
23
+ require 'web_svr/request'
24
+ require 'web_svr/response_code'
25
+ require 'web_svr/response'
26
+ require 'web_svr/server'
27
+ require 'web_svr/session'
28
+ require 'web_svr/table_renderer'
29
+ require 'web_svr/web_method'
30
+
31
+ #
32
+ # Registers the extension.
33
+ #
34
+ class WebInit < Gloo::Plugin::Base
35
+
36
+ #
37
+ # Register verbs and objects.
38
+ #
39
+ def register( callback )
40
+ callback.register_obj( Objs::Element )
41
+ callback.register_obj( Objs::Field )
42
+ callback.register_obj( Objs::Form )
43
+ callback.register_obj( Objs::Page )
44
+ callback.register_obj( Objs::Partial )
45
+ callback.register_obj( Objs::Svr )
46
+ end
47
+
48
+ end
@@ -0,0 +1,252 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
+ #
4
+ # An HTML Element.
5
+ # Note that the object name is the tag!
6
+ #
7
+ # An Element's content can be in a container of that nane,
8
+ # or it can be the simple value of the obj. If there is no
9
+ # content child, the simple value will be used.
10
+ #
11
+ # Attibutes is a container with all attributes of the tag.
12
+ # ID and CLASSES attributes can be called out more simply
13
+ # as children of the element obj.
14
+ #
15
+
16
+ module Objs
17
+ class Element < Gloo::Core::Obj
18
+
19
+ KEYWORD = 'element'.freeze
20
+ KEYWORD_SHORT = 'e'.freeze
21
+
22
+ # Element
23
+ ID = 'id'.freeze
24
+ CLASSES = 'classes'.freeze
25
+ ATTRIBUTES = 'attributes'.freeze
26
+ CONTENT = 'content'.freeze
27
+
28
+
29
+ #
30
+ # The name of the object type.
31
+ #
32
+ def self.typename
33
+ return KEYWORD
34
+ end
35
+
36
+ #
37
+ # The short name of the object type.
38
+ #
39
+ def self.short_typename
40
+ return KEYWORD_SHORT
41
+ end
42
+
43
+ #
44
+ # Set the value with any necessary type conversions.
45
+ #
46
+ def set_value( new_value )
47
+ self.value = new_value.to_s
48
+ end
49
+
50
+ #
51
+ # Does this object support multi-line values?
52
+ # Initially only true for scripts.
53
+ #
54
+ def multiline_value?
55
+ return false
56
+ end
57
+
58
+ #
59
+ # Return the array of attributes if there are any.
60
+ #
61
+ def attributes_hash
62
+ attr_can = find_child ATTRIBUTES
63
+
64
+ if attr_can && attr_can.children.size > 0
65
+ h = {}
66
+ attr_can.children.each do |o|
67
+ h[ o.name ] = o.value
68
+ end
69
+ return h
70
+ end
71
+
72
+ return {}
73
+ end
74
+
75
+ #
76
+ # Get all attributes of the tag.
77
+ #
78
+ def tag_attributes
79
+ attr_h = attributes_hash
80
+ return nil unless attr_h && attr_h.size > 0
81
+
82
+ attr_str = ''
83
+ attr_h.each do |k,v|
84
+ unless v.blank?
85
+ attr_str << " #{k}=\"#{v}\""
86
+ end
87
+ end
88
+
89
+ return attr_str
90
+ end
91
+
92
+ #
93
+ # Get the tag.
94
+ # This is the name, up until an '_' char.
95
+ # Because name must be unique in the parent, and with HTML
96
+ # we need a way to have multiple of the same tag at the
97
+ # same level.
98
+ #
99
+ def tag
100
+ i = self.name.index( '_' )
101
+ return i ? self.name[ 0..(i-1) ] : self.name
102
+ end
103
+
104
+ #
105
+ # Get the opening tag.
106
+ #
107
+ def tag_open
108
+ tag_attributes = self.tag_attributes
109
+ if tag_attributes
110
+ return "<#{tag}#{tag_attributes}>"
111
+ else
112
+ return "<#{tag}>"
113
+ end
114
+ end
115
+
116
+ #
117
+ # Get the closing tag.
118
+ #
119
+ def tag_close
120
+ return "</#{tag}>"
121
+ end
122
+
123
+ #
124
+ # Get all the children elements of the content.
125
+ #
126
+ def content_child
127
+ return find_child CONTENT
128
+ end
129
+
130
+ # ---------------------------------------------------------------------
131
+ # Children
132
+ # ---------------------------------------------------------------------
133
+
134
+ #
135
+ # Does this object have children to add when an object
136
+ # is created in interactive mode?
137
+ # This does not apply during obj load, etc.
138
+ #
139
+ def add_children_on_create?
140
+ return true
141
+ end
142
+
143
+ #
144
+ # Add children to this object.
145
+ # This is used by containers to add children needed
146
+ # for default configurations.
147
+ #
148
+ def add_default_children
149
+ fac = @engine.factory
150
+
151
+ # Create attributes with ID and Classes
152
+ attr = fac.create_can ATTRIBUTES, self
153
+ fac.create_string ID, '', attr
154
+ fac.create_string CLASSES, '', attr
155
+
156
+ fac.create_can CONTENT, self
157
+ end
158
+
159
+
160
+ # ---------------------------------------------------------------------
161
+ # Messages
162
+ # ---------------------------------------------------------------------
163
+
164
+ #
165
+ # Get a list of message names that this object receives.
166
+ #
167
+ def self.messages
168
+ return super + [ 'render' ]
169
+ end
170
+
171
+ #
172
+ # Get the expiration date for the certificate.
173
+ #
174
+ def msg_render
175
+ content = self.render_html
176
+ @engine.heap.it.set_to content
177
+ return content
178
+ end
179
+
180
+
181
+ # ---------------------------------------------------------------------
182
+ # Render
183
+ # ---------------------------------------------------------------------
184
+
185
+ #
186
+ # Render the element as HTML.
187
+ #
188
+ def render_html
189
+ content_text = render_content :render_html
190
+
191
+ return "#{tag_open}#{content_text}#{tag_close}"
192
+ end
193
+
194
+ #
195
+ # Render the element as text, without tags.
196
+ #
197
+ def render_text
198
+ content_text = render_content :render_text
199
+
200
+ return "#{content_text}"
201
+ end
202
+
203
+ #
204
+ # Render the element content using the specified render function.
205
+ # This is a recursive function (through one of the other render functions).
206
+ #
207
+ def render_content render_ƒ
208
+ obj = content_child
209
+ obj = self if obj.nil?
210
+
211
+ return Element.render_obj( obj, render_ƒ, @engine )
212
+ end
213
+
214
+ #
215
+ # Render an object which might be an element,
216
+ # a container of items, or something else.
217
+ #
218
+ def self.render_obj obj, render_ƒ, engine
219
+ rendered_obj_content = ''
220
+ return nil unless obj
221
+
222
+ if obj.children.size > 0
223
+ obj.children.each do |e|
224
+
225
+ e = Gloo::Objs::Alias.resolve_alias( engine, e )
226
+ if e.class == Element
227
+ rendered_obj_content << e.send( render_ƒ )
228
+ elsif e.class == Form
229
+ rendered_obj_content << e.render
230
+ elsif e
231
+ data = render_thing e, render_ƒ, engine
232
+ ( rendered_obj_content << data ) if data # e.render( render_ƒ )
233
+ end
234
+ end
235
+ else
236
+ rendered_obj_content << obj.value
237
+ end
238
+
239
+ return rendered_obj_content
240
+ end
241
+
242
+ def self.render_thing e, render_ƒ, engine
243
+ begin
244
+ return e.render( render_ƒ )
245
+ rescue => e
246
+ engine.log_exception e
247
+ return ''
248
+ end
249
+ end
250
+
251
+ end
252
+ end