lib/gloo/objs/web_svr/page.rb in gloo-3.1.1 vs lib/gloo/objs/web_svr/page.rb in gloo-3.2.0
- old
+ new
@@ -15,10 +15,11 @@
ON_RENDER = 'on_render'.freeze
ON_RENDERED = 'on_rendered'.freeze
# Parameters used during render.
PARAMS = 'params'.freeze
+ ID = 'id'.freeze
# Content
HEAD = 'head'.freeze
BODY = 'body'.freeze
CONTENT = 'content'.freeze
@@ -110,10 +111,23 @@
#
def params_hash
params_can = find_child PARAMS
return nil unless params_can
+ if @request
+ url_params = @request.query_params
+ url_params.each do |k,v|
+ o = params_can.find_child k
+ o.set_value( v ) if o
+ end
+
+ @request.body_params.each do |k,v|
+ o = params_can.find_child k
+ o.set_value( v ) if o
+ end
+ end
+
h = {}
params_can.children.each do |o|
h[ o.name ] = o.value
end
@@ -280,18 +294,41 @@
return false unless @engine.app_running?
return @engine.running_app.obj.redirect
end
#
+ # Set the ID parameter if there is one.
+ #
+ def set_id
+ return unless @request.id
+ @engine.log.info "Setting ID: #{@request.id}"
+
+ params_can = find_child PARAMS
+ return nil unless params_can
+
+ id_obj = params_can.find_child( ID )
+ return unless id_obj
+
+ id_obj.set_value( @request.id )
+ end
+
+ #
# Render the page.
+ # If this is being called from the web server,
+ # the request will be passed in and will include
+ # request context such as params.
#
- def render
- run_on_render
- return nil if redirect_set?
+ def render request=nil
+ @request = request
+ set_id if @request
+ # Set Params before running on render
params = params_hash
+ run_on_render
+ return nil if redirect_set?
+
if is_html?
contents = render_html params
elsif is_json?
contents = render_json
elsif is_text?
@@ -300,9 +337,10 @@
@engine.log.error "Unknown content type: #{content_type}"
return nil
end
run_on_rendered
+ @request = nil
return nil if redirect_set?
return contents
end