gloo 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/gloo.gemspec +1 -0
  3. data/lib/VERSION +1 -1
  4. data/lib/VERSION_NOTES +13 -0
  5. data/lib/gloo/app/log.rb +46 -6
  6. data/lib/gloo/app/platform.rb +7 -1
  7. data/lib/gloo/app/running_app.rb +42 -1
  8. data/lib/gloo/convert/falseclass_to_integer.rb +20 -0
  9. data/lib/gloo/convert/nilclass_to_date.rb +21 -0
  10. data/lib/gloo/convert/nilclass_to_datetime.rb +21 -0
  11. data/lib/gloo/convert/nilclass_to_integer.rb +21 -0
  12. data/lib/gloo/convert/nilclass_to_string.rb +21 -0
  13. data/lib/gloo/convert/nilclass_to_time.rb +21 -0
  14. data/lib/gloo/convert/trueclass_to_integer.rb +20 -0
  15. data/lib/gloo/core/error.rb +7 -0
  16. data/lib/gloo/core/it.rb +7 -0
  17. data/lib/gloo/core/obj.rb +41 -1
  18. data/lib/gloo/core/parser.rb +6 -3
  19. data/lib/gloo/exec/exec_env.rb +4 -0
  20. data/lib/gloo/exec/script.rb +9 -1
  21. data/lib/gloo/objs/basic/container.rb +18 -2
  22. data/lib/gloo/objs/basic/integer.rb +1 -0
  23. data/lib/gloo/objs/cli/menu.rb +9 -3
  24. data/lib/gloo/objs/{basic → ctrl}/function.rb +12 -0
  25. data/lib/gloo/objs/data/markdown.rb +60 -2
  26. data/lib/gloo/objs/data/mysql.rb +35 -7
  27. data/lib/gloo/objs/data/pg.rb +8 -0
  28. data/lib/gloo/objs/data/query.rb +66 -11
  29. data/lib/gloo/objs/data/query_result.rb +22 -1
  30. data/lib/gloo/objs/data/sqlite.rb +17 -2
  31. data/lib/gloo/objs/data/table.rb +143 -4
  32. data/lib/gloo/objs/web/json.rb +2 -0
  33. data/lib/gloo/objs/web_svr/element.rb +13 -5
  34. data/lib/gloo/objs/web_svr/page.rb +44 -2
  35. data/lib/gloo/objs/web_svr/partial.rb +7 -2
  36. data/lib/gloo/objs/web_svr/svr.rb +71 -4
  37. data/lib/gloo/verbs/break.rb +44 -0
  38. data/lib/gloo/verbs/create.rb +6 -0
  39. data/lib/gloo/verbs/invoke.rb +80 -0
  40. data/lib/gloo/verbs/log.rb +26 -5
  41. data/lib/gloo/verbs/redirect.rb +54 -6
  42. data/lib/gloo/web_svr/asset.rb +51 -23
  43. data/lib/gloo/web_svr/handler.rb +4 -2
  44. data/lib/gloo/web_svr/request.rb +35 -2
  45. data/lib/gloo/web_svr/routing/resource_router.rb +47 -0
  46. data/lib/gloo/web_svr/routing/router.rb +218 -0
  47. data/lib/gloo/web_svr/routing/show_routes.rb +98 -0
  48. data/lib/gloo/web_svr/server.rb +10 -2
  49. data/lib/gloo/web_svr/table_renderer.rb +147 -0
  50. data/lib/gloo/web_svr/web_method.rb +54 -0
  51. metadata +31 -4
  52. data/lib/gloo/web_svr/router.rb +0 -179
@@ -1,179 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 20124 Eric Crane. All rights reserved.
3
- #
4
- # A helper class for page routing.
5
- #
6
-
7
- module Gloo
8
- module WebSvr
9
- class Router
10
-
11
- PAGE_CONTAINER = 'page'.freeze
12
- INDEX = 'index'.freeze
13
- SEGMENT_DIVIDER = '/'.freeze
14
-
15
- attr_reader :route_segments
16
-
17
-
18
- # ---------------------------------------------------------------------
19
- # Initialization
20
- # ---------------------------------------------------------------------
21
-
22
- #
23
- # Set up the web server.
24
- #
25
- def initialize( engine, web_svr_obj )
26
- @engine = engine
27
- @log = @engine.log
28
-
29
- @web_svr_obj = web_svr_obj
30
- end
31
-
32
-
33
- # ---------------------------------------------------------------------
34
- # Routing
35
- # ---------------------------------------------------------------------
36
-
37
- #
38
- # Find and return the page for the given route.
39
- #
40
- def page_for_route path
41
- @engine.log.info "routing to #{path}"
42
- detect_segments path
43
-
44
- return @web_svr_obj.home_page if is_root_path?
45
-
46
- pages = @web_svr_obj.pages_container
47
- return find_route_segment( pages.children ) if pages
48
-
49
- return nil
50
- end
51
-
52
-
53
- # ---------------------------------------------------------------------
54
- # Dynamic Add Page Routes
55
- # ---------------------------------------------------------------------
56
-
57
- #
58
- # Get the root level page container.
59
- #
60
- def page_container
61
- pn = Gloo::Core::Pn.new( @engine, PAGE_CONTAINER )
62
- return pn.resolve
63
- end
64
-
65
- #
66
- # Add all page routes to the web server pages (routes).
67
- #
68
- def add_page_routes
69
- can = page_container
70
- return unless can
71
-
72
- @log.debug 'Adding page routes to web server…'
73
- @factory = @engine.factory
74
-
75
- add_pages can, @web_svr_obj.pages_container
76
- end
77
-
78
- #
79
- # Add the pages to the web server pages.
80
- # This is a recursive function that will add all
81
- # pages in the folder and subfolders.
82
- #
83
- def add_pages can, parent
84
- # for each file in the page container
85
- # create a page object and add it to the routes
86
- can.children.each do |obj|
87
- if obj.class == Gloo::Objs::Container
88
- child_can = parent.find_add_child( obj.name, 'container' )
89
- add_pages( obj, child_can )
90
- elsif obj.class == Gloo::Objs::Page
91
- add_route_alias( parent, obj.name, obj.pn )
92
- end
93
- end
94
- end
95
-
96
- #
97
- # Add route alias to the page.
98
- #
99
- def add_route_alias( parent, name, pn )
100
- name = name.gsub( '.', '_' )
101
-
102
- # First make sure the child doesn't already exist.
103
- child = parent.find_child( name )
104
- return if child
105
-
106
- @factory.create_alias( name, pn, parent )
107
- end
108
-
109
-
110
- # ---------------------------------------------------------------------
111
- # Helper funcions
112
- # ---------------------------------------------------------------------
113
-
114
- #
115
- # Find the route segment in the object container.
116
- #
117
- def find_route_segment objs
118
- this_segment = next_segment
119
-
120
- this_segment = INDEX if this_segment.blank?
121
-
122
- objs.each do |o|
123
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
124
-
125
- if o.name == this_segment
126
- if o.class == Gloo::Objs::Page
127
- @engine.log.debug "found page for route: #{o.pn}"
128
- return o
129
- elsif o.class == Gloo::Objs::FileHandle
130
- @engine.log.debug "found static file for route: #{o.pn}"
131
- return o
132
- else
133
- return nil unless o.child_count > 0
134
-
135
- return find_route_segment( o.children )
136
- end
137
- end
138
- end
139
-
140
- return nil
141
- end
142
-
143
- #
144
- # Get the next segment in the route.
145
- #
146
- def next_segment
147
- this_segment = @route_segments.shift
148
- return nil if this_segment.nil?
149
-
150
- # A URL might include a dot in a name, but we can't do that
151
- # because dot is a reserve path thing. So we replace it with
152
- # an underscore.
153
- this_segment = this_segment.gsub( '.', '_' )
154
-
155
- return this_segment
156
- end
157
-
158
- #
159
- # Is this the root path?
160
- def is_root_path?
161
- return @route_segments.count == 0
162
- end
163
-
164
- #
165
- # Create a list of path segments.
166
- #
167
- def detect_segments path
168
- # Split the path into segments.
169
- @route_segments = path.split SEGMENT_DIVIDER
170
-
171
- # Remove the first segment if it is empty.
172
- @route_segments.shift if @route_segments.first.blank?
173
-
174
- return @route_segments
175
- end
176
-
177
- end
178
- end
179
- end