Class: Haml::I18n::Extractor::Prompter
- Inherits:
-
Object
- Object
- Haml::I18n::Extractor::Prompter
- Includes:
- Helpers::Highline
- Defined in:
- lib/haml-i18n-extractor/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
- #not_processing(haml_path) ⇒ Object
- #process(haml_path, type) ⇒ Object
- #process_file?(file, file_index) ⇒ Boolean
- #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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 11 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?')) do |q| q.echo = false q.character = true q.validate = /\A[ynt]\Z/ end Haml::I18n::Extractor::UserAction.new(answer) end |
#end_message ⇒ Object
41 42 43 44 45 46 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 41 def say("\n\n\n") say(highlight("Now run a git diff or such and see what changed!")) say(highlight("Check #{Haml::I18n::Extractor::TaggingTool::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 |
#not_processing(haml_path) ⇒ Object
52 53 54 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 52 def not_processing(haml_path) say(highlight("Not processing") + " file #{haml_path}.") end |
#process(haml_path, type) ⇒ Object
48 49 50 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 48 def process(haml_path, type) say(highlight("#{type}-d file") + " #{haml_path}\n\n") end |
#process_file?(file, file_index) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 62 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 |
#start_message(file_count, file_names) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 28 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
56 57 58 |
# File 'lib/haml-i18n-extractor/prompter.rb', line 56 def syntax_error(haml_path) say("Haml Syntax error fo #{haml_path}. Please inspect further.") end |