Class: RightRails::ControllerExtensions::RenderWrapper
- Inherits:
-
Object
- Object
- RightRails::ControllerExtensions::RenderWrapper
- Defined in:
- lib/right_rails/controller_extensions.rb
Overview
This class wraps the standard JavaScript responses in the controller
It delegates all the script generating calls to the JavaScriptGenerator instance, then grabs thre reults and creates a suitable hash of options for the ActionController::Base#render method
Instance Method Summary collapse
-
#initialize(template, options) ⇒ RenderWrapper
constructor
A new instance of RenderWrapper.
- #method_missing(name, *args) ⇒ Object
-
#render ⇒ Object
Compiles the options for the controller#render method.
- #render_block {|@generator| ... } ⇒ Object
Constructor Details
#initialize(template, options) ⇒ RenderWrapper
Returns a new instance of RenderWrapper.
59 60 61 62 63 |
# File 'lib/right_rails/controller_extensions.rb', line 59 def initialize(template, ) @template = template @generator = RightRails::JavaScriptGenerator.new(template) @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
70 71 72 73 |
# File 'lib/right_rails/controller_extensions.rb', line 70 def method_missing(name, *args) @generator.send(name, *args) render end |
Instance Method Details
#render ⇒ Object
Compiles the options for the controller#render method
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/right_rails/controller_extensions.rb', line 78 def render result = {:text => @generator.to_s, :content_type => Mime::JS} # iframed uploads context overloading if @template.request.content_type == 'multipart/form-data' result[:content_type] = Mime::HTML result[:layout] = nil result[:text] = %Q{ <!-- iframed uploads JS responses layout --> <html> <head> <script type="text/javascript"> with (window.parent) { #{result[:text]} } </script> </head> </html> }.strip end result.merge! @options end |
#render_block {|@generator| ... } ⇒ Object
65 66 67 68 |
# File 'lib/right_rails/controller_extensions.rb', line 65 def render_block(&block) yield(@generator) render end |