Class: InertiaI18n::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_i18n/scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = InertiaI18n.configuration) ⇒ Scanner

Returns a new instance of Scanner.



5
6
7
# File 'lib/inertia_i18n/scanner.rb', line 5

def initialize(config = InertiaI18n.configuration)
  @config = config
end

Instance Method Details

#parser_for_file(file) ⇒ Object



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

def parser_for_file(file)
  ext = File.extname(file).downcase

  case ext
  when ".svelte"
    Parsers::SvelteParser.new
  when ".vue"
    Parsers::VueParser.new
  when ".jsx", ".tsx"
    Parsers::ReactParser.new
  when ".js", ".ts"
    Parsers::JavaScriptParser.new
  else
    Parsers::BaseParser.new
  end
end

#scanObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/inertia_i18n/scanner.rb', line 9

def scan
  results = ScanResults.new

  frontend_files.each do |file|
    parser = parser_for_file(file)
    keys = parser.extract_keys(file)
    results.add_file(file, keys)
  end

  results
end