Module: ActionviewPrecompiler::JRubyASTParser

Extended by:
JRubyASTParser
Included in:
JRubyASTParser
Defined in:
lib/actionview_precompiler/ast_parser/jruby.rb

Defined Under Namespace

Classes: Node

Constant Summary collapse

METHODS_TO_PARSE =
%i(render render_to_string layout)

Instance Method Summary collapse

Instance Method Details

#extract_render_nodes(node) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 108

def extract_render_nodes(node)
  return [] unless node?(node)
  renders = node.children.flat_map { |c| extract_render_nodes(c) }

  method_name = render_call?(node)
  renders << [method_name, node] if method_name

  renders
end

#fcall?(node, name) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 104

def fcall?(node, name)
  node.fcall_named?(name)
end

#node?(node) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 100

def node?(node)
  Node === node
end

#parse_render_nodes(code) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 91

def parse_render_nodes(code)
  node = Node.wrap(JRuby.parse(code))

  renders = extract_render_nodes(node)
  renders.group_by(&:first).collect do |method, nodes|
    [ method, nodes.collect { |v| v[1] } ]
  end.to_h
end

#render_call?(node) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 118

def render_call?(node)
  METHODS_TO_PARSE.detect { |m| fcall?(node, m) }
end