lib/flammarion/engraving.rb in flammarion_rails-0.2.0 vs lib/flammarion/engraving.rb in flammarion_rails-0.2.1
- old
+ new
@@ -10,14 +10,11 @@
# connected (i.e., displayed)
# @option options [Proc] :on_disconnect Called when the display windows is
# disconnected (i.e., closed)
# @option options [Boolean] :exit_on_disconnect (false) Will call +exit+
# when the widow is closed if this option is true.
- # @option options [Boolean] :close_on_exit (false) Will close the window
- # when the process exits if this is true. Otherwise, it will just stay
- # around, but not actually be interactive.
- # @raise {SetupError} if neither chrome is set up correctly and
+ # @raise {SetupError} if chrome is not set up correctly and
# and Flammarion is unable to display the engraving.
def initialize(**options)
@chrome = OpenStruct.new
@sockets = []
@on_connect = options[:on_connect]
@@ -26,25 +23,18 @@
start_server
@window_id = @@server.register_window(self)
open_a_window(options) unless options[:no_window]
wait_for_a_connection unless options[:no_wait]
-
- at_exit {close if window_open?} if options.fetch(:close_on_exit, true)
end
# Blocks the current thread until the window has been closed. All user
# interactions and callbacks will continue in other threads.
def wait_until_closed
sleep 1 until @sockets.empty?
end
- # Is this Engraving displayed on the screen.
- def window_open?
- !@sockets.empty?
- end
-
def disconnect(ws)
@sockets.delete ws
exit 0 if @exit_on_disconnect
@on_disconnect.call if @on_disconnect
end
@@ -53,22 +43,18 @@
params = JSON.parse(msg).with_indifferent_access
action = params.delete(:action) || 'page'
dispatch(params)
if status == 302
- params = {
- url: headers['Location'].sub(/^.*:\/{2}(:\d{0,4})?/i, ''),
- session: response.request.session
- }.with_indifferent_access
- dispatch(params)
- render(action: 'page', html: response.body)
+ dispatch(url: headers['Location'].sub(/^.*:\/{2}(:\d{0,4})?/i, ''), session: response.request.session)
+ render(action: 'page', body: response.body)
elsif headers['Content-Transfer-Encoding'] == 'binary'
filename = headers['Content-Disposition'].sub(/.*filename=/, '').gsub(/(^"|"$)/, '')
render(action: 'file', name: filename)
render(response.body)
else
- render(action: action, html: response.body)
+ render(action: action, body: response.body)
end
rescue => e
Rails.logger.error "[EXCEPTION][#{msg}]"
Rails.logger.error " [#{e.class}]\n#{e.message}\n" << e.backtrace.first(20).join("\n")
@@ -88,23 +74,24 @@
params.merge!(Rack::Utils.parse_nested_query(params.delete(:form)))
end
if params.key?(:_method)
params[:method] = params[:_method]
end
- params[:method] ||= :get
+ http_method = (params[:method] ||= :get).to_s.upcase!
- path_params = recognize_path(url, params)
+ path_params = recognize_path(uri.path, params.merge!(query_params))
unless path_params.key?(:controller)
- raise ActionController::RoutingError, "No route matches [#{url}]#{params.inspect}"
+ raise ActionController::RoutingError, "No route matches [#{http_method}] #{url}"
end
controller_name = "#{path_params[:controller].underscore.camelize}Controller"
controller = ActiveSupport::Dependencies.constantize(controller_name)
action = path_params[:action] || 'index'
request_env = {
'rack.input' => '',
- 'REQUEST_METHOD' => params[:method].to_s.upcase,
- 'action_dispatch.request.parameters' => path_params.merge!(params).merge!(query_params),
+ 'REQUEST_METHOD' => http_method,
+ 'action_dispatch.request.parameters' => params.merge!(path_params),
+ 'action_dispatch.request.path_parameters' => path_params,
}
request_env['rack.session'] = session if session
self.request = ActionDispatch::Request.new(request_env)
response = controller.make_response! request