Module | Cms::Behaviors::InstanceMethods |
In: |
lib/cms/behaviors/rendering.rb
|
# File lib/cms/behaviors/rendering.rb, line 85 85: def perform_render(controller) 86: # Give this renderable a reference to the controller 87: @controller = controller 88: 89: copy_instance_variables_from_controller! 90: 91: # This gives the view a reference to this object 92: instance_variable_set(self.class.instance_variable_name_for_view, self) 93: 94: # This is like a controller action 95: # We will call it if you have defined a render method 96: # but if you haven't we won't 97: render if respond_to?(:render) 98: 99: # Create, Instantiate and Initialize the view 100: view_class = Class.new(ActionView::Base) 101: action_view = view_class.new(@controller.view_paths, {}, @controller) 102: 103: # Make helpers and instance vars available 104: view_class.send(:include, @controller.class.master_helper_module) 105: if $:.detect{|d| File.exists?(File.join(d, self.class.helper_path))} 106: view_class.send(:include, self.class.helper_class) 107: end 108: 109: # We want content_for to be called on the controller's view, not this inner view 110: def action_view.content_for(name, content=nil, &block) 111: controller.instance_variable_get("@template").content_for(name, content, &block) 112: end 113: 114: # Copy instance variables from this renderable object to it's view 115: action_view.assigns = assigns_for_view 116: 117: if respond_to?(:inline_options) 118: options = {:locals => {}}.merge(self.inline_options) 119: ActionView::InlineTemplate.new(options[:inline], options[:type]).render(action_view, options[:locals]) 120: else 121: action_view.render(:file => self.class.template_path) 122: end 123: end
# File lib/cms/behaviors/rendering.rb, line 135 135: def assigns_for_view 136: (instance_variables - self.class.ivars_to_ignore).inject({}) do |h,k| 137: h[k[1..-1]] = instance_variable_get(k) 138: h 139: end 140: end
# File lib/cms/behaviors/rendering.rb, line 126 126: def copy_instance_variables_from_controller!copy_instance_variables_from_controller! 127: if @controller.respond_to?(:instance_variables_for_rendering) 128: @controller.instance_variables_for_rendering.each do |iv| 129: #logger.info "Copying #{iv} => #{@controller.instance_variable_get(iv).inspect}" 130: instance_variable_set(iv, @controller.instance_variable_get(iv)) 131: end 132: end 133: end