Class: Haml::I18n::Extractor::Prompter
- Inherits:
-
Object
- Object
- Haml::I18n::Extractor::Prompter
- Includes:
- Helpers::Highline
- Defined in:
- lib/haml-i18n-extractor/flow/prompter.rb
Constant Summary collapse
- CHOICES =
{O: :overwrite, D: :dump, N: :next}
Instance Method Summary collapse
- #ask_user(orig_line, replaced_line) ⇒ Object
- #end_message ⇒ Object
- #moving_to_next_file ⇒ Object
- #not_processing(haml_path) ⇒ Object
- #process(haml_path, type) ⇒ Object
- #process_file?(file, file_index) ⇒ Boolean
- #puts(txt) ⇒ Object
- #start_message(file_count, file_names) ⇒ Object
- #syntax_error(haml_path) ⇒ Object
Methods included from Helpers::Highline
Instance Method Details
#ask_user(orig_line, replaced_line) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 15 def ask_user(orig_line, replaced_line) say(highlight("Replace this line:")) say("\n") say(orig_line.inspect) say("\n") say(highlight("With this line?")) say("\n") say(replaced_line.inspect) say("\n") answer = ask(highlight('[y]es/[n]o/[t]ag/[N]ext?')) do |q| q.echo = false q.character = true q.validate = /\A[yntN]\Z/ end Haml::I18n::Extractor::UserAction.new(answer) end |
#end_message ⇒ Object
45 46 47 48 49 50 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 45 def say("\n\n\n") say(highlight("Now run a git diff or such and see what changed!")) say(highlight("Check #{Haml::I18n::Extractor::TaggingWriter::DB} if you have tagged any lines.")) say("PS: If you have any feedback or ideas how this would be better, feel free to open an issue on github. See README for more info.") end |
#moving_to_next_file ⇒ Object
85 86 87 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 85 def moving_to_next_file say("Next received! Saved changes done so far, moving to the next file.\n") end |
#not_processing(haml_path) ⇒ Object
56 57 58 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 56 def not_processing(haml_path) say(highlight("Not processing") + " file #{haml_path}.") end |
#process(haml_path, type) ⇒ Object
52 53 54 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 52 def process(haml_path, type) say(highlight("#{type}-d file") + " #{haml_path}\n\n") end |
#process_file?(file, file_index) ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 66 def process_file?(file, file_index) o = %{[#{highlight(:O)}]verwrite} d = %{[#{highlight(:D)}]ump} n = %{[#{highlight(:N)}]ext} say("#{o} OR #{d} OR #{n}\n") say("Choose the right option for") say("#{highlight(file_index)} #{highlight(file)}") choices = CHOICES.keys.map(&:to_s) prompt = "Your choice #{highlight(choices)}?" answer = ask(prompt) do |q| q.echo = false q.character = true q.validate = /\A[#{choices}r]\Z/ end return :overwrite if answer == 'O' return :overwrite if answer == 'R' # cheat 'replace' return :dump if answer == 'D' end |
#puts(txt) ⇒ Object
11 12 13 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 11 def puts(txt) say(txt) end |
#start_message(file_count, file_names) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 32 def (file_count, file_names) say("Hello there kind sir! Read this if its your first time:") say("(1) overwrite a file") say("(2) dump the file to a temp file") say("(3) Skip processing it") say("Once you are processing a file, you should be able to:") say("(1) replace the line with what it's found. this will add yaml info as well.") say("(2) skip - don't replace the line and put yaml info.") say("(3) tag - keep a reminder of this place in the code and put it in a file for later review.") say(highlight("Okay then! Found #{file_count} haml files!\n\n", :red)) say("#{file_names}\n\n") end |
#syntax_error(haml_path) ⇒ Object
60 61 62 |
# File 'lib/haml-i18n-extractor/flow/prompter.rb', line 60 def syntax_error(haml_path) say("Haml Syntax error fo #{haml_path}. Please inspect further.") end |