Class: ActionView::RenderParser::RipperRenderParser
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
ActionView::RenderParser::Base
|
Defined in: | actionview/lib/action_view/render_parser/ripper_render_parser.rb |
Class Method Summary
Instance Method Summary
- #render_calls
-
#normalize_args(string, options_hash)
private
Convert.
- #parse_hash(node) private
- #parse_hash_to_symbols(node) private
- #parse_render(node) private
- #parse_render_from_options(options_hash) private
- #parse_str(node) private
- #parse_sym(node) private
- #render_template_with_layout?(render_type, options_hash) ⇒ Boolean private
- #render_template_with_spacer?(options_hash) ⇒ Boolean private
- #resolve_path_directory(path) private
Base
- Inherited
Constructor Details
This class inherits a constructor from ActionView::RenderParser::Base
Instance Method Details
#normalize_args(string, options_hash) (private)
Convert
render("foo", ...)
into either
render(template: "foo", ...)
or
render(partial: "foo", ...)
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 219
def normalize_args(string, ) if { partial: string, locals: } else { partial: string } end end
#parse_hash(node) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 251
def parse_hash(node) node.hash? && node.to_hash end
#parse_hash_to_symbols(node) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 255
def parse_hash_to_symbols(node) hash = parse_hash(node) return unless hash hash.transform_keys do |key_node| key = parse_sym(key_node) return unless key key end end
#parse_render(node) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 227
def parse_render(node) node = node.argument_nodes if (node.length == 1 || node.length == 2) && !node[0].hash? if node.length == 1 = normalize_args(node[0], nil) elsif node.length == 2 = normalize_args(node[0], node[1]) end return nil unless ( ) elsif node.length == 1 && node[0].hash? = parse_hash_to_symbols(node[0]) return nil unless ( ) else nil end end
#parse_render_from_options(options_hash) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 269
def ( ) renders = [] keys = .keys if (keys & RENDER_TYPE_KEYS).size < 1 # Must have at least one of render keys return nil end if (keys - ALL_KNOWN_KEYS).any? # de-opt in case of unknown option return nil end render_type = (keys & RENDER_TYPE_KEYS)[0] node = [render_type] if node.string? template = resolve_path_directory(node.to_string) else if node.variable_reference? dependency = node.variable_name.sub(/\A(?:\$|@{1,2})/, "") elsif node.vcall? dependency = node.variable_name elsif node.call? dependency = node.call_method_name else return end object_template = true template = "#{dependency.pluralize}/#{dependency.singularize}" end return unless template if spacer_template = render_template_with_spacer?( ) virtual_path = partial_to_virtual_path(:partial, spacer_template) renders << virtual_path end if .key?(:object) || .key?(:collection) || object_template return nil if .key?(:object) && .key?(:collection) return nil unless .key?(:partial) end virtual_path = partial_to_virtual_path(render_type, template) renders << virtual_path # Support for rendering multiple templates (i.e. a partial with a layout) if layout_template = render_template_with_layout?(render_type, ) virtual_path = partial_to_virtual_path(:layout, layout_template) renders << virtual_path end renders end
#parse_str(node) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 329
def parse_str(node) node.string? && node.to_string end
#parse_sym(node) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 333
def parse_sym(node) node.symbol? && node.to_symbol end
#render_calls
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 193
def render_calls parser = RenderCallExtractor.new(@code) parser.parse parser.render_calls.group_by(&:first).to_h do |method, nodes| [ method.to_sym, nodes.collect { |v| v[1] } ] end.map do |method, nodes| nodes.map { |n| parse_render(n) } end.flatten.compact end
#render_template_with_layout?(render_type, options_hash) ⇒ Boolean
(private)
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 337
def render_template_with_layout?(render_type, ) if render_type != :layout && .key?(:layout) parse_str( [:layout]) end end
#render_template_with_spacer?(options_hash) ⇒ Boolean
(private)
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 343
def render_template_with_spacer?( ) if .key?(:spacer_template) parse_str( [:spacer_template]) end end
#resolve_path_directory(path) (private)
[ GitHub ]# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 205
def resolve_path_directory(path) if path.include?("/") path else "#{directory}/#{path}" end end