Module: Cms::Behaviors::InstanceMethods

Defined in:
lib/cms/behaviors/rendering.rb

Instance Method Summary collapse

Instance Method Details

#editor_info(method) ⇒ Hash

Returns the Mercury editor type for a given attribute

Parameters:

  • method (Symbol)

    (i.e. :name, :content, etc)

Returns:

  • (Hash)


98
99
100
101
102
103
104
105
# File 'lib/cms/behaviors/rendering.rb', line 98

def editor_info(method)
  column = self.class.columns_hash[method.to_s]
  if column.type == :text
    {:element => 'div', :region => 'full'}
  else
    {:element => 'span', :region => 'simple'}
  end
end

#perform_render(controller) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/cms/behaviors/rendering.rb', line 122

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 = (edit_mode? ? %Q[<div class="error">This #{self.class.name} has been deleted.  Please remove this container from the page</div>] : '')
    return msg
  end

  # Create, Instantiate and Initialize the view
  action_view = Cms::ViewContext.new(@controller, assigns_for_view)

  add_content_helpers_if_defined(action_view)

  # Determine if this content should render from a file system template or inline (i.e. database based template)
  if respond_to?(:inline_options) && self.inline_options && self.inline_options.has_key?(:inline)
    options = self.inline_options
    locals = {}
    action_view.render(options, locals)
  else
    action_view.render(:file => self.class.template_path)
  end
end

#prepare_to_render(controller) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cms/behaviors/rendering.rb', line 107

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 should_render_self?
end

#render_exception=(exception) ⇒ Object



153
154
155
# File 'lib/cms/behaviors/rendering.rb', line 153

def render_exception=(exception)
  @render_exception = exception
end

#should_render_self?Boolean

Determines if a block should have its ‘render’ method called when it’s rendered within a page.

Returns:

  • (Boolean)


158
159
160
161
162
# File 'lib/cms/behaviors/rendering.rb', line 158

def should_render_self?
  # Reason to exist: This was added to work around the fact that Rails 3 AbstractController::Helpers defines its own
  # render method, which was conflicted with block's render methods.
  public_methods(false).include?(:render)
end