Class: I18n::Tasks::Scanners::ErbAstProcessor

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin
Defined in:
lib/i18n/tasks/scanners/erb_ast_processor.rb

Instance Method Summary collapse

Constructor Details

#initializeErbAstProcessor

Returns a new instance of ErbAstProcessor.



10
11
12
13
14
# File 'lib/i18n/tasks/scanners/erb_ast_processor.rb', line 10

def initialize
  super()
  @ruby_parser = LocalRubyParser.new
  @comments = []
end

Instance Method Details

#handler_missing(node) ⇒ Object



38
39
40
41
42
43
# File 'lib/i18n/tasks/scanners/erb_ast_processor.rb', line 38

def handler_missing(node)
  node.updated(
    nil,
    node.children.map { |child| node?(child) ? process(child) : child }
  )
end

#on_code(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/i18n/tasks/scanners/erb_ast_processor.rb', line 21

def on_code(node)
  parsed, comments = @ruby_parser.parse(
    node.children[0],
    location: node.location
  )
  @comments.concat(comments)

  unless parsed.nil?
    parsed = parsed.updated(
      nil,
      parsed.children.map { |child| node?(child) ? process(child) : child }
    )
    node = node.updated(:send, parsed)
  end
  node
end

#process_and_extract_comments(ast) ⇒ Object



16
17
18
19
# File 'lib/i18n/tasks/scanners/erb_ast_processor.rb', line 16

def process_and_extract_comments(ast)
  result = process(ast)
  [result, @comments]
end