Module: ViewFormatter
Instance Method Summary collapse
- #clipboard_command ⇒ Object
- #display_error ⇒ Object
- #file_not_found ⇒ Object
- #invalid_file ⇒ Object
- #line_check(line) ⇒ Object
- #need_to_specify_directory ⇒ Object
- #new_file(filename) ⇒ Object
- #new_file_path ⇒ Object
- #no_args_message ⇒ Object
- #no_results ⇒ Object
- #output_file_not_found(file) ⇒ Object
- #reindexed ⇒ Object
- #show_log(log_file) ⇒ Object
- #show_snips(file) ⇒ Object
- #snip_terminal_status(filename, line) ⇒ Object
- #snippet_indexer(index, title, type) ⇒ Object
- #specify_filename(filename) ⇒ Object
- #specify_path ⇒ Object
- #status_line(line, type, file) ⇒ Object
- #success_message(filedir) ⇒ Object
- #terminal_help_message ⇒ Object
Instance Method Details
#clipboard_command ⇒ Object
158 159 160 161 |
# File 'app/views/viewformatter.rb', line 158 def clipboard_command "Run 'snip -c' or specify code type (js, rb, erb, misc) and a title string with: 'snip -c rb \"Using string interpolation\"' " end |
#display_error ⇒ Object
163 164 165 |
# File 'app/views/viewformatter.rb', line 163 def display_error "Specify code type (js, rb, erb) and/or a search string, e.g. 'snip -d js \"event delegation\"', or snip -d .' for all snips" end |
#file_not_found ⇒ Object
18 19 20 |
# File 'app/views/viewformatter.rb', line 18 def file_not_found "File not found, please try again." end |
#invalid_file ⇒ Object
22 23 24 |
# File 'app/views/viewformatter.rb', line 22 def invalid_file "File must be a .js, .rb or .erb file." end |
#line_check(line) ⇒ Object
44 45 46 |
# File 'app/views/viewformatter.rb', line 44 def line_check(line) line ? ':' + line.to_s : nil end |
#need_to_specify_directory ⇒ Object
130 131 132 |
# File 'app/views/viewformatter.rb', line 130 def need_to_specify_directory "Please specify an existing directory to save your snippets to" end |
#new_file(filename) ⇒ Object
64 65 66 |
# File 'app/views/viewformatter.rb', line 64 def new_file(filename) "New snippet file created at #{File.absolute_path(filename)}" end |
#new_file_path ⇒ Object
114 115 116 |
# File 'app/views/viewformatter.rb', line 114 def new_file_path "Snippet file location saved as '#{File.absolute_path(ARGV[1])}/my_snips.txt'" end |
#no_args_message ⇒ Object
118 119 120 |
# File 'app/views/viewformatter.rb', line 118 def "Welcome to snip. Type 'snip --help' for help" end |
#no_results ⇒ Object
166 167 168 |
# File 'app/views/viewformatter.rb', line 166 def no_results "No matching snippet files found" end |
#output_file_not_found(file) ⇒ Object
60 61 62 |
# File 'app/views/viewformatter.rb', line 60 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 ⇒ Object
154 155 156 |
# File 'app/views/viewformatter.rb', line 154 def reindexed "Your snippet files have been reindexed" end |
#show_log(log_file) ⇒ Object
134 135 136 137 138 139 140 |
# File 'app/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) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/views/viewformatter.rb', line 142 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
48 49 50 51 52 53 54 |
# File 'app/views/viewformatter.rb', line 48 def snip_terminal_status(filename, line) if line "#{filename}:#{line} snipped" else nil end end |
#snippet_indexer(index, title, type) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/views/viewformatter.rb', line 8 def snippet_indexer(index, title, type) if type == "js" "// **** Snippet " + (index).to_s + ": #{title} **** \n" elsif type == "erb" "<!-- **** Snippet " + (index).to_s + ": #{title} **** -->\n" else "# **** Snippet " + (index).to_s + ": #{title} **** \n" end end |
#specify_filename(filename) ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/views/viewformatter.rb', line 122 def specify_filename(filename) if filename "Your file is located at #{filename}" else "No output file found, please specify a filename after '-f'" end end |
#specify_path ⇒ Object
56 57 58 |
# File 'app/views/viewformatter.rb', line 56 def specify_path "Please specify where you would like to save your snippets by running 'snip -f <filepath>'" end |
#status_line(line, type, file) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/views/viewformatter.rb', line 34 def status_line(line, type, file) if type == "js" "// Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}" elsif type == "erb" "<!-- Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}-->" else "# Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}" end end |
#success_message(filedir) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/views/viewformatter.rb', line 26 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
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/views/viewformatter.rb', line 68 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 -c - creates new snippet from clipboard contents snip -d . - display all your snips in terminal snip -d <type> '<string>' - searches your snips by type (js, rb, erb) 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 |