Module: ViewFormatter
Instance Method Summary collapse
- #file_not_found ⇒ Object
- #invalid_file ⇒ Object
- #need_to_specify_directory ⇒ Object
- #new_file(filename) ⇒ Object
- #new_file_path ⇒ Object
- #no_args_message ⇒ Object
- #output_file_not_found(file) ⇒ Object
- #show_log(log_file) ⇒ Object
- #show_snips(file) ⇒ Object
- #snip_terminal_status(filename, line) ⇒ Object
- #snippet_indexer(index, title, type) ⇒ Object
- #specify_filename ⇒ Object
- #specify_path ⇒ Object
- #status_line(line, type) ⇒ Object
- #success_message(filedir) ⇒ Object
- #terminal_help_message ⇒ Object
Instance Method Details
#file_not_found ⇒ Object
16 17 18 |
# File 'app/views/viewformatter.rb', line 16 def file_not_found "File not found, please try again." end |
#invalid_file ⇒ Object
20 21 22 |
# File 'app/views/viewformatter.rb', line 20 def invalid_file "File must be a .js or .rb file." end |
#need_to_specify_directory ⇒ Object
109 110 111 |
# File 'app/views/viewformatter.rb', line 109 def need_to_specify_directory "Please specify an existing directory to save your snippets to" end |
#new_file(filename) ⇒ Object
52 53 54 |
# File 'app/views/viewformatter.rb', line 52 def new_file(filename) "New snippet file created at #{File.absolute_path(filename)}" end |
#new_file_path ⇒ Object
97 98 99 |
# File 'app/views/viewformatter.rb', line 97 def new_file_path "Snippet file location saved as '#{File.absolute_path(ARGV[1])}/my_snips.txt'" end |
#no_args_message ⇒ Object
101 102 103 |
# File 'app/views/viewformatter.rb', line 101 def "Welcome to snip. Type 'snip --help' for help" end |
#output_file_not_found(file) ⇒ Object
48 49 50 |
# File 'app/views/viewformatter.rb', line 48 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 |
#show_log(log_file) ⇒ Object
113 114 115 116 117 118 119 |
# File 'app/views/viewformatter.rb', line 113 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) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/views/viewformatter.rb', line 121 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) ⇒ Object
40 41 42 |
# File 'app/views/viewformatter.rb', line 40 def snip_terminal_status(filename, line) "#{File.absolute_path(filename)}:#{line} snipped" end |
#snippet_indexer(index, title, type) ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/views/viewformatter.rb', line 8 def snippet_indexer(index, title, type) if type == "js" "// **** Snippet " + (index).to_s + ": #{title} **** \n" else "# **** Snippet " + (index).to_s + ": #{title} **** \n" end end |
#specify_filename ⇒ Object
105 106 107 |
# File 'app/views/viewformatter.rb', line 105 def specify_filename "Please specify a filename after '-f'" end |
#specify_path ⇒ Object
44 45 46 |
# File 'app/views/viewformatter.rb', line 44 def specify_path "Please specify where you would like to save your snippets by running 'snip -f <filepath>'" end |
#status_line(line, type) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/views/viewformatter.rb', line 32 def status_line(line, type) if type == "js" "// Snipped from #{SourceFileReaderWriter.file_to_open}:#{line} on #{Time.now.strftime("%m-%d-%Y")}" else "# Snipped from #{SourceFileReaderWriter.file_to_open}:#{line} on #{Time.now.strftime("%m-%d-%Y")}" end end |
#success_message(filedir) ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/views/viewformatter.rb', line 24 def (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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/views/viewformatter.rb', line 56 def " *** 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. Ruby and JavaScript 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 -l - view log history if you need to debug previous snips snip -d - display your snips in terminal Visit https://github.com/jgerminario/snip for more information or to submit bug reports/feature requests. " end |