module ViewFormatter
Public Instance Methods
check_for_file(filename)
click to toggle source
# File lib/views/viewformatter.rb, line 95 def check_for_file(filename) if filename "Your file is located at #{filename}" else "No output file found, please specify a filename after '-f'" end end
clipboard_instructions()
click to toggle source
clipboard (-c)
# File lib/views/viewformatter.rb, line 157 def clipboard_instructions "Run 'snip -c' or specify code type (#{Language.languages.keys.join(", ") + " or misc"}) and a title string with: 'snip -c rb \"Using string interpolation\"' " end
clipboard_origin(type)
click to toggle source
# File lib/views/viewformatter.rb, line 166 def clipboard_origin(type) type != "misc" ? type_str = " (.#{type})" : type_str = "" "clipboard#{type_str}" end
clipboard_prompts()
click to toggle source
# File lib/views/viewformatter.rb, line 162 def clipboard_prompts ["Type of code (e.g. #{conjunctionator}) or press enter for misc:", "Title:"] end
clipboard_success(code)
click to toggle source
# File lib/views/viewformatter.rb, line 172 def clipboard_success(code) "Your code has been snipped:\n\n#{code}" end
conjunctionator(list = Language.languages, conj="or")
click to toggle source
utility
# File lib/views/viewformatter.rb, line 10 def conjunctionator(list = Language.languages, conj="or") if list.class.name == "Hash" list = list.keys end str = "#{list[0..-2].join(", ")} #{conj} #{list[-1]}" end
delete_error()
click to toggle source
delete (–delete)
# File lib/views/viewformatter.rb, line 148 def delete_error "Please specify which snippets you wish to delete" end
delete_success()
click to toggle source
# File lib/views/viewformatter.rb, line 152 def delete_success "Snips #{ARGV[1]} deleted from my_snips.txt (other files must be modified manually)" end
display_error()
click to toggle source
# File lib/views/viewformatter.rb, line 120 def display_error "Specify code type (#{conjunctionator}) and/or a search string, e.g. 'snip -d js \"event delegation\"', or snip -d .' for all snips" end
input_file_not_found()
click to toggle source
default snip functionality reporting messages (based on files/directories)
# File lib/views/viewformatter.rb, line 55 def input_file_not_found "File not found, please try again." end
invalid_input_file()
click to toggle source
# File lib/views/viewformatter.rb, line 59 def invalid_input_file "File must be a #{conjunctionator} file." end
line_check(line)
click to toggle source
# File lib/views/viewformatter.rb, line 17 def line_check(line) line ? ':' + line.to_s : nil end
need_to_specify_a_directory()
click to toggle source
# File lib/views/viewformatter.rb, line 103 def need_to_specify_a_directory "Please specify an existing directory to save your snippets to" end
new_file(filename)
click to toggle source
# File lib/views/viewformatter.rb, line 49 def new_file(filename) "New snippet file created at #{File.absolute_path(filename)}" end
new_file_path()
click to toggle source
filename set (-f)
# File lib/views/viewformatter.rb, line 91 def new_file_path "Snippet file location saved as '#{File.absolute_path(ARGV[1])}/my_snips.txt'" end
no_args_message()
click to toggle source
no args
# File lib/views/viewformatter.rb, line 86 def no_args_message "Welcome to snip. Type 'snip --help' for help" end
no_results()
click to toggle source
# File lib/views/viewformatter.rb, line 124 def no_results "No matching snippet files found" end
output_file_not_found(file)
click to toggle source
# File lib/views/viewformatter.rb, line 45 def output_file_not_found(file) "Output file '#{file}' not found, please specify existing file location or desired location for new file by running 'snip -f <filepath>'" end
reindexed()
click to toggle source
reindex (-i)
# File lib/views/viewformatter.rb, line 129 def reindexed "Your snippet files have been reindexed" end
show_log(log_file)
click to toggle source
log (-l)
# File lib/views/viewformatter.rb, line 134 def show_log(log_file) if File.readlines(log_file)[0] File.readlines(log_file) else "Log file is empty" end end
show_snips(file)
click to toggle source
Search (-d)
# File lib/views/viewformatter.rb, line 108 def show_snips(file) if file if File.readlines(file)[0] File.readlines(file) else "Snippet file is empty" end else "Snippet file doesn't exist. Specify where you would like to save your snippets by running 'snip -f <filepath>" end end
snip_terminal_status(filename, line)
click to toggle source
# File lib/views/viewformatter.rb, line 75 def snip_terminal_status(filename, line) if line "#{filename}:#{line} snipped" else nil end end
snippet_indexer(index, title, type)
click to toggle source
file output formatting
# File lib/views/viewformatter.rb, line 22 def snippet_indexer(index, title, type) languages = Language.languages if languages.key?(type) "#{languages[type][0]} **** Snippet " + (index).to_s + ": #{title} **** #{languages[type][1]} \n" else "# **** Snippet " + (index).to_s + ": #{title} **** \n" end end
specify_path()
click to toggle source
file management (based on check)config_file function in DestinationFileWriter
)
# File lib/views/viewformatter.rb, line 41 def specify_path "Please specify where you would like to save your snippets by running 'snip -f <filepath>'" end
status_line(line, type, file)
click to toggle source
# File lib/views/viewformatter.rb, line 31 def status_line(line, type, file) languages = Language.languages if languages.key?(type) "#{languages[type][0]} Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")} #{languages[type][1]}" else "# Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}" end end
success_message(filedir)
click to toggle source
# File lib/views/viewformatter.rb, line 67 def success_message(filedir) if Snippet.snippet_counter > 0 "Your snippet file has been successfully updated with #{Snippet.snippet_counter} new snips at: '#{filedir}'" else "No snips found in the specified files or directories." end end
terminal_help_message()
click to toggle source
help (–help)
# File lib/views/viewformatter.rb, line 177 def terminal_help_message " *** First time setup: *** snip -f <directory> This specifies the directory where you would like to save your snippets. 'my_snips.txt' will be automatically created if it doesn't already exist. If you move your my_snips.txt file, you will need to run 'snip -f' again. Language-specific (e.g. .js, .rb) snippet files will be automatically created in the same directory as the .txt file. *** To add snip tags into your code: *** Ruby: # <snip> Title goes here 5.times do {|x| puts x} # </snip> JS: // <snip> Title goes here var test = 1234; // </snip> You can alternatively use <$> and </$>. Your tags will be replaced with <*snip*> and/or <*$*> after running 'snip'. *** Ongoing usage: *** snip <filename> - process a single file snip <directory> - process a directory recursively snip -a - display all your snips in terminal snip -c - creates new snippet from clipboard contents snip -s <type> '<string>' - searches your snips with type #{conjunctionator} and/or search string snip -i - reindexes your snippet files (after deleting old snips, etc) snip -l - view log history if you need to debug previous snips snip --delete <num> - deletes the specified snippet number(s) (comma-delimited) and reindexes snip --help - displays this help menu Visit https://github.com/jgerminario/snip for more information or to submit bug reports/feature requests. " end
whitespace_success()
click to toggle source
whitespace (-w)
# File lib/views/viewformatter.rb, line 143 def whitespace_success "Whitespace restored" end