Class: ActionView::RenderParser

Inherits:
Object
  • Object
show all
Defined in:
actionview/lib/action_view/render_parser.rb

Overview

:nodoc:

Constant Summary collapse

ALL_KNOWN_KEYS =
[:partial, :template, :layout, :formats, :locals, :object, :collection, :as, :status, :content_type, :location, :spacer_template]
RENDER_TYPE_KEYS =
[:partial, :template, :layout]

Instance Method Summary collapse

Constructor Details

#initialize(name, code) ⇒ RenderParser

Returns a new instance of RenderParser.



10
11
12
13
# File 'actionview/lib/action_view/render_parser.rb', line 10

def initialize(name, code)
  @name = name
  @code = code
end

Instance Method Details

#render_callsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'actionview/lib/action_view/render_parser.rb', line 15

def render_calls
  queue = [Prism.parse(@code).value]
  templates = []

  while (node = queue.shift)
    queue.concat(node.compact_child_nodes)
    next unless node.is_a?(Prism::CallNode)

    options = render_call_options(node)
    next unless options

    render_type = (options.keys & RENDER_TYPE_KEYS)[0]
    template, object_template = render_call_template(options[render_type])
    next unless template

    if options.key?(:object) || options.key?(:collection) || object_template
      next if options.key?(:object) && options.key?(:collection)
      next unless options.key?(:partial)
    end

    if options[:spacer_template].is_a?(Prism::StringNode)
      templates << partial_to_virtual_path(:partial, options[:spacer_template].unescaped)
    end

    templates << partial_to_virtual_path(render_type, template)

    if render_type != :layout && options[:layout].is_a?(Prism::StringNode)
      templates << partial_to_virtual_path(:layout, options[:layout].unescaped)
    end
  end

  templates
end