Class: ExtractI18::HTMLExtractor::Runner

Inherits:
Object
  • Object
show all
Includes:
Cli
Defined in:
lib/extract_i18n/html_extractor/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
# File 'lib/extract_i18n/html_extractor/runner.rb', line 6

def initialize(args = {})
  @files = file_list_from_pattern(args[:file_pattern])
  @locale = args[:locale].presence
  @verbose = args[:verbose]
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
# File 'lib/extract_i18n/html_extractor/runner.rb', line 27

def run
  each_translation do |file, document, node|
    puts "Found \"#{node.text}\" in #{file}:#{node.text}".green
    node.replace_text!
    document.save!(file)

    add_translation! I18n.default_locale, node.key, node.text
  end
end

#run_interactiveObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/extract_i18n/html_extractor/runner.rb', line 12

def run_interactive
  each_translation do |file, document, node|
    puts "Found \"#{node.text}\" in #{file}:#{node.text}".green
    next unless confirm 'Create a translation?', 'Yes', 'No', default: 'Yes'

    node.key = prompt 'Choose i18n key', default: node.key
    node.replace_text!

    document.save!(file)

    add_translations! node.key, node.text, default_locale: @locale
    puts
  end
end

#test_runObject



37
38
39
40
41
# File 'lib/extract_i18n/html_extractor/runner.rb', line 37

def test_run
  each_translation do |file, _, node|
    puts "Found \"#{node.text}\" in #{file}:#{node.text}".green
  end
end