class Cuba::Tools::Widget::Responder
Public Class Methods
new(app, env)
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 4 def initialize(app, env) @app = app @env = env end
Public Instance Methods
respond()
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 9 def respond if widget_path widget_name, widget_event, events = Widget.load_all @app, req, res events.trigger widget_name, widget_event, req.params # res.write "$('head > meta[name=csrf-token]').attr('content', '#{csrf_token}');" res.write '$(document).trigger("page:change");' end res.finish end
Private Instance Methods
path()
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 47 def path @env['PATH_INFO'] end
req()
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 23 def req @req ||= Rack::Request.new(@env) end
res()
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 27 def res @res ||= begin if not widget_path status, headers, body = @app.call(req.env) else status, headers, body = [ 200, {"Content-Type" => "text/javascript; charset=utf-8"}, [""] ] end Rack::Response.new(body, status, headers) end end
widget_path()
click to toggle source
# File lib/cuba/tools/widget/responder.rb, line 43 def widget_path path[Regexp.new("^#{Widget.config.url_path}($|\\?.*)")] end