2010-10-10 05:03:18 -04:00
|
|
|
module ActionView
|
2013-04-18 14:39:04 -04:00
|
|
|
# This class defines the interface for a renderer. Each class that
|
|
|
|
# subclasses +AbstractRenderer+ is used by the base +Renderer+ class to
|
|
|
|
# render a specific type of object.
|
|
|
|
#
|
|
|
|
# The base +Renderer+ class uses its +render+ method to delegate to the
|
|
|
|
# renderers. These currently consist of
|
|
|
|
#
|
|
|
|
# PartialRenderer - Used for rendering partials
|
|
|
|
# TemplateRenderer - Used for rendering other types of templates
|
|
|
|
# StreamingTemplateRenderer - Used for streaming
|
|
|
|
#
|
|
|
|
# Whenever the +render+ method is called on the base +Renderer+ class, a new
|
|
|
|
# renderer object of the correct type is created, and the +render+ method on
|
|
|
|
# that new object is called in turn. This abstracts the setup and rendering
|
|
|
|
# into a separate classes for partials and templates.
|
2010-10-10 05:03:18 -04:00
|
|
|
class AbstractRenderer #:nodoc:
|
2016-08-06 13:36:34 -04:00
|
|
|
delegate :find_template, :find_file, :template_exists?, :any_templates?, :with_fallbacks, :with_layout_format, :formats, to: :@lookup_context
|
2010-10-10 05:03:18 -04:00
|
|
|
|
2011-05-03 18:12:11 -04:00
|
|
|
def initialize(lookup_context)
|
2011-05-01 04:33:30 -04:00
|
|
|
@lookup_context = lookup_context
|
2010-10-10 05:03:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def render
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2011-09-22 09:03:05 -04:00
|
|
|
protected
|
2012-01-05 15:59:25 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def extract_details(options)
|
|
|
|
@lookup_context.registered_details.each_with_object({}) do |key, details|
|
|
|
|
value = options[key]
|
2014-07-18 23:54:03 -04:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
details[key] = Array(value) if value
|
|
|
|
end
|
2011-09-22 17:51:44 -04:00
|
|
|
end
|
2012-01-05 15:59:25 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def instrument(name, **options)
|
|
|
|
options[:identifier] ||= (@template && @template.identifier) || @path
|
2016-02-18 15:55:42 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
ActiveSupport::Notifications.instrument("render_#{name}.action_view", options) do |payload|
|
|
|
|
yield payload
|
|
|
|
end
|
2016-02-18 15:55:42 -05:00
|
|
|
end
|
2012-07-11 04:18:52 -04:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def prepend_formats(formats)
|
|
|
|
formats = Array(formats)
|
|
|
|
return if formats.empty? || @lookup_context.html_fallback_for_js
|
2014-07-18 23:54:03 -04:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
@lookup_context.formats = formats | @lookup_context.formats
|
|
|
|
end
|
2010-10-10 05:03:18 -04:00
|
|
|
end
|
2010-10-16 11:39:11 -04:00
|
|
|
end
|