Class: ActionView::TemplateRenderer
- Inherits:
-
AbstractRenderer
- Object
- AbstractRenderer
- ActionView::TemplateRenderer
- Defined in:
- lib/action_view/renderer/template_renderer.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
-
#determine_template(options) ⇒ Object
Determine the template to be rendered using the given options.
-
#find_layout(layout, keys) ⇒ Object
This is the method which actually finds the layout using details in the lookup context object.
- #render(context, options) ⇒ Object
-
#render_template(template, layout_name = nil, locals = {}) ⇒ Object
Renders the given template.
-
#render_with_layout(path, locals) ⇒ Object
:nodoc:.
Methods inherited from AbstractRenderer
#formats_regexp, #initialize, #wrap_formats
Constructor Details
This class inherits a constructor from ActionView::AbstractRenderer
Instance Method Details
#determine_template(options) ⇒ Object
Determine the template to be rendered using the given options.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/action_view/renderer/template_renderer.rb', line 17 def determine_template() #:nodoc: keys = [:locals].try(:keys) || [] if .key?(:text) Template::Text.new([:text], formats.try(:first)) elsif .key?(:file) with_fallbacks { find_template([:file], nil, false, keys) } elsif .key?(:inline) handler = Template.handler_for_extension([:type] || "erb") Template.new([:inline], "inline template", handler, :locals => keys) elsif .key?(:template) [:template].respond_to?(:render) ? [:template] : find_template([:template], [:prefixes], false, keys) end end |
#find_layout(layout, keys) ⇒ Object
This is the method which actually finds the layout using details in the lookup context object. If no layout is found, it checks if at least a layout with the given name exists across all details before raising the error.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/action_view/renderer/template_renderer.rb', line 61 def find_layout(layout, keys) begin with_layout_format do layout =~ /^\// ? with_fallbacks { find_template(layout, nil, false, keys) } : find_template(layout, nil, false, keys) end rescue ActionView::MissingTemplate => e update_details(:formats => nil) do raise unless template_exists?(layout) end end end |
#render(context, options) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/action_view/renderer/template_renderer.rb', line 6 def render(context, ) @view = context wrap_formats([:template] || [:file]) do template = determine_template() freeze_formats(template.formats, true) render_template(template, [:layout], [:locals]) end end |
#render_template(template, layout_name = nil, locals = {}) ⇒ Object
Renders the given template. An string representing the layout can be supplied as well.
35 36 37 38 39 40 41 42 43 |
# File 'lib/action_view/renderer/template_renderer.rb', line 35 def render_template(template, layout_name = nil, locals = {}) #:nodoc: view, locals = @view, locals || {} render_with_layout(layout_name, locals) do |layout| instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do template.render(view, locals) { |*name| view._layout_for(*name) } end end end |
#render_with_layout(path, locals) ⇒ Object
:nodoc:
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/action_view/renderer/template_renderer.rb', line 45 def render_with_layout(path, locals) #:nodoc: layout = path && find_layout(path, locals.keys) content = yield(layout) if layout view = @view view.view_flow.set(:layout, content) layout.render(view, locals){ |*name| view._layout_for(*name) } else content end end |