Class: ActionviewPrecompiler::PrismASTParser::RenderVisitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- ActionviewPrecompiler::PrismASTParser::RenderVisitor
- Defined in:
- lib/actionview_precompiler/ast_parser/prism.rb
Overview
This visitor is responsible for visiting the parsed tree and extracting out the render calls. After visiting the tree, the #render_calls method will return the hash expected by the #parse_render_nodes method.
Constant Summary collapse
- MESSAGE =
/\A(render|render_to_string|layout)\z/
Instance Attribute Summary collapse
-
#render_calls ⇒ Object
readonly
Returns the value of attribute render_calls.
Instance Method Summary collapse
-
#initialize ⇒ RenderVisitor
constructor
A new instance of RenderVisitor.
- #visit_call_node(node) ⇒ Object
Constructor Details
#initialize ⇒ RenderVisitor
Returns a new instance of RenderVisitor.
118 119 120 |
# File 'lib/actionview_precompiler/ast_parser/prism.rb', line 118 def initialize @render_calls = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#render_calls ⇒ Object (readonly)
Returns the value of attribute render_calls.
116 117 118 |
# File 'lib/actionview_precompiler/ast_parser/prism.rb', line 116 def render_calls @render_calls end |
Instance Method Details
#visit_call_node(node) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/actionview_precompiler/ast_parser/prism.rb', line 122 def visit_call_node(node) if node.name.match?(MESSAGE) && !node.receiver && node.arguments args = node.arguments.arguments.map do |arg| if arg.is_a?(Prism::ParenthesesNode) && arg.body && arg.body.body.length == 1 RenderNode.new(arg.body.body.first) else RenderNode.new(arg) end end render_calls[node.name.to_sym] << RenderCall.new(args) end super end |