Class: ExtractI18::HTMLExtractor::Runner
- Inherits:
-
Object
- Object
- ExtractI18::HTMLExtractor::Runner
- Includes:
- Cli
- Defined in:
- lib/extract_i18n/html_extractor/runner.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
- #run_interactive ⇒ Object
- #test_run ⇒ Object
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
#run ⇒ Object
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_interactive ⇒ Object
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_run ⇒ Object
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 |