module Apotomo::Rails::ControllerMethods
Public Instance Methods
apotomo_request_processor()
click to toggle source
# File lib/apotomo/rails/controller_methods.rb, line 48 def apotomo_request_processor return @apotomo_request_processor if @apotomo_request_processor # happens once per request: options = {:js_framework => Apotomo.js_framework} @apotomo_request_processor = Apotomo::RequestProcessor.new(self, options, self.class.has_widgets_blocks) end
apotomo_root()
click to toggle source
# File lib/apotomo/rails/controller_methods.rb, line 57 def apotomo_root apotomo_request_processor.root end
render_event_response()
click to toggle source
# File lib/apotomo/rails/controller_methods.rb, line 65 def render_event_response page_updates = apotomo_request_processor.process_for(params) return render_iframe_updates(page_updates) if params[:apotomo_iframe] render :text => page_updates.join("\n"), :content_type => Mime::JS end
render_widget(*args, &block)
click to toggle source
# File lib/apotomo/rails/controller_methods.rb, line 61 def render_widget(*args, &block) apotomo_request_processor.render_widget_for(*args, &block) end
url_for_event(type, options)
click to toggle source
Returns the url to trigger a type
event from :source
, which is a non-optional parameter. Additional options
will be appended to the query string.
Note that this method will use the frameworkâs internal routing if available (e.g. url_for in Rails
).
Example:
url_for_event(:paginate, :source => 'mouse', :page => 2) #=> http://apotomo.de/mouse/process_event_request?type=paginate&source=mouse&page=2
# File lib/apotomo/rails/controller_methods.rb, line 81 def url_for_event(type, options) options.reverse_merge!(:type => type) apotomo_event_path(apotomo_request_processor.address_for(options)) end
Protected Instance Methods
render_iframe_updates(page_updates)
click to toggle source
Renders the page updates through an iframe. Copied from responds_to_parent, see github.com/markcatley/responds_to_parent .
# File lib/apotomo/rails/controller_methods.rb, line 90 def render_iframe_updates(page_updates) escaped_script = Apotomo::JavascriptGenerator.escape(page_updates.join("\n")) render :text => "<html><body><script type='text/javascript' charset='utf-8'> var loc = document.location; with(window.parent) { setTimeout(function() { window.eval('#{escaped_script}'); window.loc && loc.replace('about:blank'); }, 1) } </script></body></html>", :content_type => 'text/html' end