Module: AbstractController::Rendering

Extended by:
ActiveSupport::Concern
Includes:
ViewPaths
Included in:
Helpers, Layouts, ActionController::Rendering
Defined in:
lib/abstract_controller/rendering.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ViewPaths

#append_view_path, #details_for_lookup, #lookup_context, #prepend_view_path

Instance Attribute Details

#view_context_classObject



68
69
70
# File 'lib/abstract_controller/rendering.rb', line 68

def view_context_class
  @view_context_class || self.class.view_context_class
end

Instance Method Details

#_prefixObject

The prefix used in render “foo” shortcuts.



119
120
121
# File 'lib/abstract_controller/rendering.rb', line 119

def _prefix
  controller_path
end

#_render_template(options) ⇒ Object

Find and renders a template based on the options given. :api: private



114
115
116
# File 'lib/abstract_controller/rendering.rb', line 114

def _render_template(options) #:nodoc:
  view_context.render(options)
end

#initializeObject



72
73
74
75
# File 'lib/abstract_controller/rendering.rb', line 72

def initialize(*)
  @view_context_class = nil
  super
end

#processObject

Overwrite process to setup I18n proxy.



39
40
41
42
43
44
# File 'lib/abstract_controller/rendering.rb', line 39

def process(*) #:nodoc:
  old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
  super
ensure
  I18n.config = old_config
end

#render(*args, &block) ⇒ Object

Normalize arguments, options and then delegates render_to_body and sticks the result in self.response_body.



92
93
94
# File 'lib/abstract_controller/rendering.rb', line 92

def render(*args, &block)
  self.response_body = render_to_string(*args, &block)
end

#render_to_body(options = {}) ⇒ Object

Raw rendering of a template to a Rack-compatible body. :api: plugin



107
108
109
110
# File 'lib/abstract_controller/rendering.rb', line 107

def render_to_body(options = {})
  _process_options(options)
  _render_template(options)
end

#render_to_string(*args, &block) ⇒ Object

Raw rendering of a template to a string. Just convert the results of render_to_body into a String. :api: plugin



99
100
101
102
103
# File 'lib/abstract_controller/rendering.rb', line 99

def render_to_string(*args, &block)
  options = _normalize_args(*args, &block)
  _normalize_options(options)
  render_to_body(options)
end

#view_contextObject

An instance of a view class. The default view class is ActionView::Base

The view class must have the following methods: View.new[lookup_context, assigns, controller]

Create a new ActionView instance for a controller

View#render

Returns String with the rendered template

Override this method in a module to change the default behavior.



86
87
88
# File 'lib/abstract_controller/rendering.rb', line 86

def view_context
  view_context_class.new(lookup_context, view_assigns, self)
end