Module: Cms::Behaviors::InstanceMethods
- Defined in:
- lib/cms/behaviors/rendering.rb
Instance Method Summary collapse
- #perform_render(controller) ⇒ Object
- #prepare_to_render(controller) ⇒ Object
- #render_exception=(exception) ⇒ Object
Instance Method Details
#perform_render(controller) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cms/behaviors/rendering.rb', line 99 def perform_render(controller) return "Exception: #{@render_exception}" if @render_exception unless @controller # We haven't prepared to render. This should only happen when logged in, as we don't want # errors to bubble up and prevent the page being edited in that case. prepare_to_render(controller) end if self.respond_to?(:deleted) && self.deleted logger.error "Attempting to render deleted object: #{self.inspect}" msg = (@mode == 'edit' ? %Q[<div class="error">#{I18n.t("behaviors.rendering.deleted", :class_name => self.class.name)}</div>] : '') return msg end # Create, Instantiate and Initialize the view view_class = Class.new(ActionView::Base) action_view = view_class.new(@controller.view_paths, {}, @controller) # Make helpers and instance vars available view_class.send(:include, @controller.class.master_helper_module) if $:.detect{|d| File.exists?(File.join(d, self.class.helper_path))} view_class.send(:include, self.class.helper_class) end # We want content_for to be called on the controller's view, not this inner view def action_view.content_for(name, content=nil, &block) @controller.instance_variable_get("@template").content_for(name, content, &block) end # Copy instance variables from this renderable object to it's view action_view.assigns = assigns_for_view if respond_to?(:inline_options) && self. && self..has_key?(:inline) = {:locals => {}}.merge(self.) ActionView::InlineTemplate.new([:inline], [:type]).render(action_view, [:locals]) else action_view.render(:file => self.class.template_path) end end |
#prepare_to_render(controller) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cms/behaviors/rendering.rb', line 84 def prepare_to_render(controller) # Give this renderable a reference to the controller @controller = controller copy_instance_variables_from_controller! # This gives the view a reference to this object instance_variable_set(self.class.instance_variable_name_for_view, self) # This is like a controller action # We will call it if you have defined a render method # but if you haven't we won't render if respond_to?(:render) end |
#render_exception=(exception) ⇒ Object
141 142 143 |
# File 'lib/cms/behaviors/rendering.rb', line 141 def render_exception=(exception) @render_exception = exception end |