snipgem 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +33 -0
- data/Rakefile +5 -4
- data/app/controllers/controller.rb +12 -2
- data/app/models/snippet.rb +6 -2
- data/app/models/utils/batchprocessing.rb +1 -1
- data/app/models/utils/codescanner.rb +1 -1
- data/app/models/utils/destinationfilewriter.rb +56 -4
- data/app/models/utils/searchfile.rb +42 -0
- data/app/views/viewformatter.rb +44 -8
- data/lib/snip/version.rb +1 -1
- data/lib/snip.rb +87 -4
- data/my_snips.rb +198 -0
- data/rspec/test_snip_files/subfolder/test3.rb +8 -8
- data/rspec/test_snip_files/subfolder/test_erb.erb +12 -0
- data/rspec/test_snip_files/subfolder/test_js.js +9 -0
- data/rspec/test_snip_files/test.rb +6 -6
- data/rspec/test_snip_files/test2.rb +6 -6
- data/snip.gemspec +1 -0
- metadata +28 -11
- data/pkg/snip-0.0.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ebbe6149737de3b96d4124db961aa30e4d25b01
|
4
|
+
data.tar.gz: 909bc2fabd8df5b7e23ab72b129c2b6043de6cc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 368b5bc4f2e2281c618f6c920cd2fc1bfce1d34dd5d0b2a7f5f50b324f1dbcffca3b7d60bd2933fae68d372ab244995383dbad4cd6df5c610d5f0bed0f88fa47
|
7
|
+
data.tar.gz: bd4892c06856e3c57403f10bbc3c7c66fcf14805cf2e9813d08606956e3ebe2fb9609a0bea057dd4a9a63f53c3a2ed889af23936fcc8bc4caa56a0641e24145f
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
snipgem (0.0.7)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
clipboard (1.0.5)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
rake (10.4.2)
|
12
|
+
rspec (3.1.0)
|
13
|
+
rspec-core (~> 3.1.0)
|
14
|
+
rspec-expectations (~> 3.1.0)
|
15
|
+
rspec-mocks (~> 3.1.0)
|
16
|
+
rspec-core (3.1.7)
|
17
|
+
rspec-support (~> 3.1.0)
|
18
|
+
rspec-expectations (3.1.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.1.0)
|
21
|
+
rspec-mocks (3.1.3)
|
22
|
+
rspec-support (~> 3.1.0)
|
23
|
+
rspec-support (3.1.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.7)
|
30
|
+
clipboard (~> 1.0)
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
snipgem!
|
data/Rakefile
CHANGED
@@ -11,15 +11,13 @@ task :seed do
|
|
11
11
|
test_str2 = "#<$> Title ggg\ndef method\n \"code\"\nend\n#</$>\n\n#<$> Title 2323\ndef method\n \"code\"\nend\n#</$>\n\n#<$> Title 4\ndef method\n \"code\"\nend\n#</$>"
|
12
12
|
test_str3 = "# <snip> Title of first snip\n desc \"create the database\"\n task :create do\n puts \"Creating file \#{DB_PATH} if it doesn't exist...\"\n touch DB_PATH\n end\n# </snip>\n\n# <snip> Title of this snip\n desc \"drop the database\"\n task :drop do\n puts \"Deleting \#{DB_PATH}...\"\n rm_f DB_PATH\n end\n# </snip>\n\n# <snip> Title of first snip\n desc \"create the database\"\n task :create do\n puts \"Creating file \#{DB_PATH} if it doesn't exist...\"\n touch DB_PATH\n end\n# </snip>\n\n# <snip> Title of this snip\n desc \"drop the database\"\n task :drop do\n puts \"Deleting \#{DB_PATH}...\"\n rm_f DB_PATH\n end\n# </snip>"
|
13
13
|
test_str_js = "//<$> Title ggg\nvar test1 = 44;\nvar test2 = 22;\n//</$>\n\n//<$>\nvar test4 = \"Hola\";\n//</$>\n\n"
|
14
|
+
test_str_erb = "<!-- <$> Title ggg -->\n <% @snips.each do |snip| %>\n <p><%= snip.title %></p> \n<% end %>\n<!-- </$> --> \n\n<!-- <$> Title ggg -->\n <% @snips.each do |snip| %>\n <p><%= snip.title %></p> \n<% end %>\n<!-- </$> --> \n\n"
|
15
|
+
|
14
16
|
|
15
17
|
FileUtils.rm_rf('rspec/test_snip_files')
|
16
18
|
Dir.mkdir("rspec/test_snip_files")
|
17
19
|
Dir.mkdir("rspec/test_snip_files/subfolder")
|
18
20
|
|
19
|
-
File.open("my_snips.rb", "w+") do |file|
|
20
|
-
file << ""
|
21
|
-
end
|
22
|
-
|
23
21
|
File.open("rspec/test_snip_files/test.rb", "w+") do |file|
|
24
22
|
file << test_str1
|
25
23
|
end
|
@@ -32,6 +30,9 @@ task :seed do
|
|
32
30
|
File.open("rspec/test_snip_files/subfolder/test_js.js", "w+") do |file|
|
33
31
|
file << test_str_js
|
34
32
|
end
|
33
|
+
File.open("rspec/test_snip_files/subfolder/test_erb.erb", "w+") do |file|
|
34
|
+
file << test_str_erb
|
35
|
+
end
|
35
36
|
end
|
36
37
|
|
37
38
|
desc "Run the specs"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative '../models/utils/sourcefilereader'
|
2
2
|
require_relative '../models/utils/codescanner'
|
3
3
|
require_relative '../models/utils/destinationfilewriter'
|
4
|
+
require_relative '../models/utils/searchfile'
|
4
5
|
|
5
6
|
module CommandLineController
|
6
7
|
|
@@ -10,11 +11,20 @@ module CommandLineController
|
|
10
11
|
file_read = SourceFileReaderWriter.new(file)
|
11
12
|
to_run = file_read.convert_to_array_of_lines
|
12
13
|
CodeScanner.run(to_run, SourceFileReaderWriter.file_to_open)
|
14
|
+
file_writing
|
15
|
+
file_read.overwrite_existing_snips
|
16
|
+
end
|
17
|
+
|
18
|
+
def file_writing
|
13
19
|
DestinationFileWriter.run(Snippet.snippet_array)
|
14
20
|
DestinationFileWriter.run(Snippet.rb_snippets, "rb") if Snippet.rb_snippets.any?
|
15
21
|
DestinationFileWriter.run(Snippet.js_snippets, "js") if Snippet.js_snippets.any?
|
16
|
-
|
17
|
-
|
22
|
+
DestinationFileWriter.run(Snippet.erb_snippets, "erb") if Snippet. erb_snippets.any?
|
18
23
|
Snippet.snippet_array = []
|
19
24
|
end
|
25
|
+
|
26
|
+
def display_search(text, ext)
|
27
|
+
SearchDisplay.run(DestinationFileWriter.return_display_file, text, ext)
|
28
|
+
end
|
29
|
+
|
20
30
|
end
|
data/app/models/snippet.rb
CHANGED
@@ -18,11 +18,15 @@ attr_accessor :snippet_array
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.rb_snippets
|
21
|
-
@@snippet_array.select {|snippet| snippet.filename.end_with?(".rb")}
|
21
|
+
@@snippet_array.select {|snippet| snippet.filename.end_with?(".rb") || snippet.filename.end_with?("(.rb)")}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.erb_snippets
|
25
|
+
@@snippet_array.select {|snippet| snippet.filename.end_with?(".erb") || snippet.filename.end_with?("(.erb)") }
|
22
26
|
end
|
23
27
|
|
24
28
|
def self.js_snippets
|
25
|
-
@@snippet_array.select {|snippet| snippet.filename.end_with?(".js")}
|
29
|
+
@@snippet_array.select {|snippet| snippet.filename.end_with?(".js") || snippet.filename.end_with?("(.js)") }
|
26
30
|
end
|
27
31
|
|
28
32
|
def initialize(args = {})
|
@@ -2,7 +2,7 @@ class BatchProcessing
|
|
2
2
|
|
3
3
|
def self.process(directory)
|
4
4
|
directory = directory.chomp('/')
|
5
|
-
Dir.glob(directory + "/**/*.{rb,js}") do |file|
|
5
|
+
Dir.glob(directory + "/**/*.{rb,js,erb}") do |file|
|
6
6
|
next if file == '.' or file == '..'
|
7
7
|
CommandLineController.run(file)
|
8
8
|
end
|
@@ -30,8 +30,23 @@ module DestinationFileWriter
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
def directory
|
34
|
+
check_if_file_still_exists
|
35
|
+
File.dirname(@snip_file_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def return_display_file
|
39
|
+
check_if_file_still_exists
|
40
|
+
@snip_file_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_all_snippet_files
|
44
|
+
snippet_files = []
|
45
|
+
Dir.glob(directory + "/my_snips.*").each { |file| snippet_files << file }
|
46
|
+
snippet_files
|
47
|
+
end
|
48
|
+
|
33
49
|
def run(snippet_array, type=nil)
|
34
|
-
directory = File.dirname(@snip_file_name)
|
35
50
|
case type
|
36
51
|
when "rb"
|
37
52
|
filename = directory + "/my_snips.rb"
|
@@ -39,6 +54,9 @@ module DestinationFileWriter
|
|
39
54
|
when "js"
|
40
55
|
filename = directory + "/my_snips.js"
|
41
56
|
File.new(filename, 'w') unless File.exist?(filename)
|
57
|
+
when "erb"
|
58
|
+
filename = directory + "/my_snips.erb"
|
59
|
+
File.new(filename, 'w') unless File.exist?(filename)
|
42
60
|
else
|
43
61
|
filename = @snip_file_name
|
44
62
|
end
|
@@ -66,21 +84,55 @@ module DestinationFileWriter
|
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
87
|
+
def reindexer(filename)
|
88
|
+
index = 1
|
89
|
+
file_array = []
|
90
|
+
File.open(filename, "r+").each do |line|
|
91
|
+
if line.match(/\*\*\*\* Snippet \d+:/)
|
92
|
+
line.sub!(/Snippet \d+:/, "Snippet #{index}:")
|
93
|
+
file_array << line
|
94
|
+
index += 1
|
95
|
+
else
|
96
|
+
file_array << line
|
97
|
+
end
|
98
|
+
line.gsub!("\t", " ")
|
99
|
+
end
|
100
|
+
rewrite_file(filename,file_array)
|
101
|
+
end
|
102
|
+
|
103
|
+
def reindex_all
|
104
|
+
find_all_snippet_files.each {|file| reindexer(file)}
|
105
|
+
end
|
106
|
+
|
107
|
+
def restore_whitespace(filename, array)
|
108
|
+
array.map! { |snippet| snippet.strip + "\n\n\n\n" }
|
109
|
+
rewrite_file(filename, array)
|
110
|
+
end
|
111
|
+
|
112
|
+
def rewrite_file(filename, array)
|
113
|
+
File.open(filename, "w") do |file|
|
114
|
+
array.each do |line|
|
115
|
+
file << line
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
69
120
|
def write_file(snippet_array, filename, type)
|
70
121
|
File.open(filename, "a") do |file|
|
71
122
|
snippet_array.each_with_index do |snip_object, index|
|
72
123
|
file << ViewFormatter.snippet_indexer(determine_next_index(filename)+index, snip_object.title, type)
|
73
|
-
file << ViewFormatter.status_line(snip_object.line, type)
|
124
|
+
file << ViewFormatter.status_line(snip_object.line, type, snip_object.filename)
|
74
125
|
file << "\n"
|
75
126
|
file << snip_object.code
|
76
|
-
file << "\n\n"
|
77
|
-
unless type
|
127
|
+
file << "\n\n\n"
|
128
|
+
unless type || snip_object.line == nil
|
78
129
|
log = ViewFormatter.snip_terminal_status(snip_object.filename, snip_object.line)
|
79
130
|
puts log
|
80
131
|
write_to_log_file(log)
|
81
132
|
end
|
82
133
|
end
|
83
134
|
end
|
135
|
+
reindexer(filename)
|
84
136
|
end
|
85
137
|
|
86
138
|
def write_to_log_file(log)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SearchDisplay
|
2
|
+
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def check_for_title(line)
|
6
|
+
line.match(/\*\*\*\* Snippet \d+:/)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(file,text="",ext="")
|
10
|
+
if !search_snips(divide_snips(file), text, ext).empty?
|
11
|
+
search_snips(divide_snips(file), text, ext)
|
12
|
+
else
|
13
|
+
ViewFormatter.no_results
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def divide_snips(file)
|
18
|
+
snip_array = []
|
19
|
+
snip_str = ""
|
20
|
+
File.open(file, "r").each do |line|
|
21
|
+
if check_for_title(line)
|
22
|
+
snip_array << snip_str
|
23
|
+
snip_str = line
|
24
|
+
else
|
25
|
+
snip_str << line
|
26
|
+
end
|
27
|
+
end
|
28
|
+
snip_array << snip_str
|
29
|
+
snip_array.shift
|
30
|
+
snip_array
|
31
|
+
end
|
32
|
+
|
33
|
+
def search_snips(array,text,ext)
|
34
|
+
array.select{ |snip| snip.include?(text) && snip.include?(ext)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(file, ids)
|
38
|
+
run(file).reject do |snip|
|
39
|
+
ids.include?(snip.match(/\*\*\*\* Snippet (\d+):/).captures[0])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/app/views/viewformatter.rb
CHANGED
@@ -8,6 +8,8 @@ module ViewFormatter
|
|
8
8
|
def snippet_indexer(index, title, type)
|
9
9
|
if type == "js"
|
10
10
|
"// **** Snippet " + (index).to_s + ": #{title} **** \n"
|
11
|
+
elsif type == "erb"
|
12
|
+
"<!-- **** Snippet " + (index).to_s + ": #{title} **** -->\n"
|
11
13
|
else
|
12
14
|
"# **** Snippet " + (index).to_s + ": #{title} **** \n"
|
13
15
|
end
|
@@ -18,7 +20,7 @@ module ViewFormatter
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def invalid_file
|
21
|
-
"File must be a .js or .
|
23
|
+
"File must be a .js, .rb or .erb file."
|
22
24
|
end
|
23
25
|
|
24
26
|
def success_message(filedir)
|
@@ -29,16 +31,26 @@ module ViewFormatter
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
def status_line(line, type)
|
34
|
+
def status_line(line, type, file)
|
33
35
|
if type == "js"
|
34
|
-
"// Snipped from #{
|
36
|
+
"// Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}"
|
37
|
+
elsif type == "erb"
|
38
|
+
"<!-- Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}-->"
|
35
39
|
else
|
36
|
-
"# Snipped from #{
|
40
|
+
"# Snipped from #{file}#{line_check(line)} on #{Time.now.strftime("%m-%d-%Y")}"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
def line_check(line)
|
45
|
+
line ? ':' + line.to_s : nil
|
46
|
+
end
|
47
|
+
|
40
48
|
def snip_terminal_status(filename, line)
|
41
|
-
|
49
|
+
if line
|
50
|
+
"#{filename}:#{line} snipped"
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
def specify_path
|
@@ -86,8 +98,13 @@ You can alternatively use <$> and </$>. Your tags will be replaced with <*snip*>
|
|
86
98
|
|
87
99
|
snip <filename> - process a single file
|
88
100
|
snip <directory> - process a directory recursively
|
101
|
+
snip -c - creates new snippet from clipboard contents
|
102
|
+
snip -d . - display all your snips in terminal
|
103
|
+
snip -d <type> '<string>' - searches your snips by type (js, rb, erb) or search string
|
104
|
+
snip -i - reindexes your snippet files (after deleting old snips, etc)
|
89
105
|
snip -l - view log history if you need to debug previous snips
|
90
|
-
snip
|
106
|
+
snip --delete <num> - deletes the specified snippet number(s) (comma-delimited) and reindexes
|
107
|
+
snip --help - displays this help menu
|
91
108
|
|
92
109
|
Visit https://github.com/jgerminario/snip for more information or to submit bug reports/feature requests.
|
93
110
|
|
@@ -102,8 +119,12 @@ Visit https://github.com/jgerminario/snip for more information or to submit bug
|
|
102
119
|
"Welcome to snip. Type 'snip --help' for help"
|
103
120
|
end
|
104
121
|
|
105
|
-
def specify_filename
|
106
|
-
|
122
|
+
def specify_filename(filename)
|
123
|
+
if filename
|
124
|
+
"Your file is located at #{filename}"
|
125
|
+
else
|
126
|
+
"No output file found, please specify a filename after '-f'"
|
127
|
+
end
|
107
128
|
end
|
108
129
|
|
109
130
|
def need_to_specify_directory
|
@@ -130,4 +151,19 @@ Visit https://github.com/jgerminario/snip for more information or to submit bug
|
|
130
151
|
end
|
131
152
|
end
|
132
153
|
|
154
|
+
def reindexed
|
155
|
+
"Your snippet files have been reindexed"
|
156
|
+
end
|
157
|
+
|
158
|
+
def clipboard_command
|
159
|
+
"Run 'snip -c' or specify code type (js, rb, erb, misc) and a title string with:
|
160
|
+
'snip -c rb \"Using string interpolation\"' "
|
161
|
+
end
|
162
|
+
|
163
|
+
def display_error
|
164
|
+
"Specify code type (js, rb, erb) and/or a search string, e.g. 'snip -d js \"event delegation\"', or snip -d .' for all snips"
|
165
|
+
end
|
166
|
+
def no_results
|
167
|
+
"No matching snippet files found"
|
168
|
+
end
|
133
169
|
end
|
data/lib/snip/version.rb
CHANGED
data/lib/snip.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
require "snip/version"
|
2
|
+
require "clipboard"
|
2
3
|
require_relative '../app/controllers/controller'
|
3
4
|
require_relative '../app/models/utils/batchprocessing'
|
4
5
|
|
5
6
|
module Snip
|
6
7
|
class Run
|
8
|
+
def argv_ext_check(pos)
|
9
|
+
if ARGV[pos]
|
10
|
+
(ARGV[pos] == "rb" || ARGV[pos] == "js" || ARGV[pos] == "erb")
|
11
|
+
else
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def display_file
|
17
|
+
DestinationFileWriter.return_display_file
|
18
|
+
end
|
19
|
+
|
7
20
|
def execute
|
8
21
|
unless ARGV[0]
|
9
22
|
abort(ViewFormatter.no_args_message)
|
@@ -22,26 +35,96 @@ module Snip
|
|
22
35
|
abort(ViewFormatter.need_to_specify_directory)
|
23
36
|
end
|
24
37
|
else
|
25
|
-
abort(ViewFormatter.specify_filename)
|
38
|
+
abort(ViewFormatter.specify_filename((DestinationFileWriter.snip_filepath)))
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
29
|
-
if ARGV[0] == "-l"
|
42
|
+
if ARGV[0] == "-l"
|
30
43
|
puts ViewFormatter.show_log(DestinationFileWriter.log_filepath)
|
31
44
|
abort
|
32
45
|
end
|
33
46
|
|
47
|
+
if ARGV[0] == "-i"
|
48
|
+
DestinationFileWriter.reindex_all
|
49
|
+
abort(ViewFormatter.reindexed)
|
50
|
+
end
|
51
|
+
|
52
|
+
if ARGV[0] == "-w"
|
53
|
+
DestinationFileWriter.restore_whitespace(DestinationFileWriter.return_display_file, SearchDisplay.run(DestinationFileWriter.return_display_file))
|
54
|
+
abort("Whitespace restored")
|
55
|
+
end
|
56
|
+
|
57
|
+
if ARGV[0] == "--delete"
|
58
|
+
unless ARGV[1]
|
59
|
+
abort("Please specify which snippets you wish to delete")
|
60
|
+
end
|
61
|
+
if ARGV[1].include?(",")
|
62
|
+
ids = ARGV[1].split(",")
|
63
|
+
else
|
64
|
+
ids = [ARGV[1]]
|
65
|
+
end
|
66
|
+
DestinationFileWriter.rewrite_file(display_file, SearchDisplay.delete(display_file, ids))
|
67
|
+
DestinationFileWriter.reindex_all
|
68
|
+
abort("Snips #{ARGV[1]} deleted from my_snips.txt (other files must be modified manually)")
|
69
|
+
end
|
70
|
+
|
34
71
|
if ARGV[0] == "-d"
|
35
|
-
|
72
|
+
if argv_ext_check(1)
|
73
|
+
if ARGV[2]
|
74
|
+
if !ARGV[3].nil?
|
75
|
+
abort(ViewFormatter.display_error)
|
76
|
+
else
|
77
|
+
puts CommandLineController.display_search(ARGV[2], "." + ARGV[1])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
puts CommandLineController.display_search("", "." + ARGV[1])
|
81
|
+
end
|
82
|
+
elsif ARGV[1] == "."
|
83
|
+
puts ViewFormatter.show_snips(DestinationFileWriter.snip_filepath)
|
84
|
+
elsif !ARGV[1].nil?
|
85
|
+
if !ARGV[2].nil?
|
86
|
+
abort(ViewFormatter.display_error)
|
87
|
+
else
|
88
|
+
puts CommandLineController.display_search(ARGV[1], "")
|
89
|
+
end
|
90
|
+
else
|
91
|
+
abort(ViewFormatter.display_error)
|
92
|
+
end
|
36
93
|
abort
|
37
94
|
end
|
38
95
|
|
39
96
|
DestinationFileWriter.check_config_file_for_snip_file
|
40
97
|
|
98
|
+
if ARGV[0] == "-c"
|
99
|
+
code = Clipboard.paste + "\n"
|
100
|
+
|
101
|
+
if !ARGV[2].nil? && (ARGV[1] == "rb" || ARGV[1] == "js" || ARGV[1] == "erb" || ARGV[1] == "misc")
|
102
|
+
type = ARGV[1]
|
103
|
+
title = ARGV[2]
|
104
|
+
elsif ARGV[1].nil?
|
105
|
+
puts "Type of code (e.g. rb, js, erb) or press enter for misc:"
|
106
|
+
type = $stdin.gets.chomp
|
107
|
+
puts "Title:"
|
108
|
+
title = $stdin.gets.chomp
|
109
|
+
else
|
110
|
+
abort(ViewFormatter.clipboard_command)
|
111
|
+
end
|
112
|
+
|
113
|
+
if type == "rb" || type == "js" || type == "erb"
|
114
|
+
origin = "clipboard (.#{type})"
|
115
|
+
else
|
116
|
+
origin = "clipboard"
|
117
|
+
end
|
118
|
+
|
119
|
+
Snippet.new(code: code, title: title, line: nil, filename: origin)
|
120
|
+
CommandLineController.file_writing
|
121
|
+
abort("Your code has been snipped:\n\n#{code}")
|
122
|
+
end
|
123
|
+
|
41
124
|
if File.directory?(ARGV[0])
|
42
125
|
BatchProcessing.process(ARGV[0])
|
43
126
|
elsif File.file?(ARGV[0])
|
44
|
-
if ARGV[0].end_with?(".rb") || ARGV[0].end_with?(".js")
|
127
|
+
if ARGV[0].end_with?(".rb") || ARGV[0].end_with?(".js") ||ARGV[0].end_with?(".erb")
|
45
128
|
CommandLineController.run(ARGV[0])
|
46
129
|
else
|
47
130
|
abort(ViewFormatter.invalid_file)
|
data/my_snips.rb
CHANGED
@@ -0,0 +1,198 @@
|
|
1
|
+
# **** Snippet 1: Title of first snip ****
|
2
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb:1 on 12-13-2014
|
3
|
+
desc "create the database"
|
4
|
+
task :create do
|
5
|
+
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
6
|
+
touch DB_PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# **** Snippet 2: Title of this snip ****
|
11
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb:9 on 12-13-2014
|
12
|
+
desc "drop the database"
|
13
|
+
task :drop do
|
14
|
+
puts "Deleting #{DB_PATH}..."
|
15
|
+
rm_f DB_PATH
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# **** Snippet 3: Title of first snip ****
|
20
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb:17 on 12-13-2014
|
21
|
+
desc "create the database"
|
22
|
+
task :create do
|
23
|
+
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
24
|
+
touch DB_PATH
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# **** Snippet 4: Title of this snip ****
|
29
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb:25 on 12-13-2014
|
30
|
+
desc "drop the database"
|
31
|
+
task :drop do
|
32
|
+
puts "Deleting #{DB_PATH}..."
|
33
|
+
rm_f DB_PATH
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# **** Snippet 5: Title of this snip ****
|
38
|
+
# Snipped from rspec/test_snip_files/test.rb:1 on 12-13-2014
|
39
|
+
class OrangeTree
|
40
|
+
attr_reader :age, :height
|
41
|
+
def initialize
|
42
|
+
@age = 0
|
43
|
+
@oranges = []
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# **** Snippet 6: TITLE ****
|
48
|
+
# Snipped from rspec/test_snip_files/test.rb:10 on 12-13-2014
|
49
|
+
def age!
|
50
|
+
@oranges += Array.new(rand(1..10)) { Orange.new } if @age > 5
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# **** Snippet 7: test ****
|
55
|
+
# Snipped from rspec/test_snip_files/test.rb:16 on 12-13-2014
|
56
|
+
def any_oranges?
|
57
|
+
!@oranges.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# **** Snippet 8: Title ggg ****
|
62
|
+
# Snipped from rspec/test_snip_files/test2.rb:1 on 12-13-2014
|
63
|
+
def method
|
64
|
+
"code"
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# **** Snippet 9: Title 2323 ****
|
69
|
+
# Snipped from rspec/test_snip_files/test2.rb:7 on 12-13-2014
|
70
|
+
def method
|
71
|
+
"code"
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# **** Snippet 10: Title 4 ****
|
76
|
+
# Snipped from rspec/test_snip_files/test2.rb:13 on 12-13-2014
|
77
|
+
def method
|
78
|
+
"code"
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# **** Snippet 11: sweet jesus ****
|
83
|
+
# Snipped from clipboard (.rb): on 12-13-2014
|
84
|
+
["line_check(line)"]
|
85
|
+
|
86
|
+
# **** Snippet 12: test ****
|
87
|
+
# Snipped from clipboard (.rb): on 12-13-2014
|
88
|
+
if File.directory?(ARGV[0])
|
89
|
+
BatchProcessing.process(ARGV[0])
|
90
|
+
elsif File.file?(ARGV[0])
|
91
|
+
if ARGV[0].end_with?(".rb") || ARGV[0].end_with?(".js") ||ARGV[0].end_with?(".erb")
|
92
|
+
CommandLineController.run(ARGV[0])
|
93
|
+
else
|
94
|
+
abort(ViewFormatter.invalid_file)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
abort(ViewFormatter.file_not_found)
|
98
|
+
end
|
99
|
+
|
100
|
+
puts ViewFormatter.success_message(DestinationFileWriter.full_file_directory)
|
101
|
+
|
102
|
+
# **** Snippet 13: cool catz ****
|
103
|
+
# Snipped from clipboard (.rb): on 12-14-2014
|
104
|
+
if File.directory?(ARGV[0])
|
105
|
+
BatchProcessing.process(ARGV[0])
|
106
|
+
elsif File.file?(ARGV[0])
|
107
|
+
if ARGV[0].end_with?(".rb") || ARGV[0].end_with?(".js") ||ARGV[0].end_with?(".erb")
|
108
|
+
CommandLineController.run(ARGV[0])
|
109
|
+
else
|
110
|
+
abort(ViewFormatter.invalid_file)
|
111
|
+
end
|
112
|
+
else
|
113
|
+
abort(ViewFormatter.file_not_found)
|
114
|
+
end
|
115
|
+
|
116
|
+
puts ViewFormatter.success_message(DestinationFileWriter.full_file_directory)
|
117
|
+
|
118
|
+
# **** Snippet 14: Title of first snip ****
|
119
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb::1 on 12-16-2014
|
120
|
+
desc "create the database"
|
121
|
+
task :create do
|
122
|
+
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
123
|
+
touch DB_PATH
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# **** Snippet 15: Title of this snip ****
|
128
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb::9 on 12-16-2014
|
129
|
+
desc "drop the database"
|
130
|
+
task :drop do
|
131
|
+
puts "Deleting #{DB_PATH}..."
|
132
|
+
rm_f DB_PATH
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
# **** Snippet 16: Title of first snip ****
|
137
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb::17 on 12-16-2014
|
138
|
+
desc "create the database"
|
139
|
+
task :create do
|
140
|
+
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
141
|
+
touch DB_PATH
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
# **** Snippet 17: Title of this snip ****
|
146
|
+
# Snipped from rspec/test_snip_files/subfolder/test3.rb::25 on 12-16-2014
|
147
|
+
desc "drop the database"
|
148
|
+
task :drop do
|
149
|
+
puts "Deleting #{DB_PATH}..."
|
150
|
+
rm_f DB_PATH
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
# **** Snippet 18: Title of this snip ****
|
155
|
+
# Snipped from rspec/test_snip_files/test.rb::1 on 12-16-2014
|
156
|
+
class OrangeTree
|
157
|
+
attr_reader :age, :height
|
158
|
+
def initialize
|
159
|
+
@age = 0
|
160
|
+
@oranges = []
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
# **** Snippet 19: TITLE ****
|
165
|
+
# Snipped from rspec/test_snip_files/test.rb::10 on 12-16-2014
|
166
|
+
def age!
|
167
|
+
@oranges += Array.new(rand(1..10)) { Orange.new } if @age > 5
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
# **** Snippet 20: test ****
|
172
|
+
# Snipped from rspec/test_snip_files/test.rb::16 on 12-16-2014
|
173
|
+
def any_oranges?
|
174
|
+
!@oranges.empty?
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# **** Snippet 21: Title ggg ****
|
179
|
+
# Snipped from rspec/test_snip_files/test2.rb::1 on 12-16-2014
|
180
|
+
def method
|
181
|
+
"code"
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
# **** Snippet 22: Title 2323 ****
|
186
|
+
# Snipped from rspec/test_snip_files/test2.rb::7 on 12-16-2014
|
187
|
+
def method
|
188
|
+
"code"
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
# **** Snippet 23: Title 4 ****
|
193
|
+
# Snipped from rspec/test_snip_files/test2.rb::13 on 12-16-2014
|
194
|
+
def method
|
195
|
+
"code"
|
196
|
+
end
|
197
|
+
|
198
|
+
|
@@ -1,31 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# <snip> Title of first snip
|
2
2
|
desc "create the database"
|
3
3
|
task :create do
|
4
4
|
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
5
5
|
touch DB_PATH
|
6
6
|
end
|
7
|
-
#
|
7
|
+
# </snip>
|
8
8
|
|
9
|
-
#
|
9
|
+
# <snip> Title of this snip
|
10
10
|
desc "drop the database"
|
11
11
|
task :drop do
|
12
12
|
puts "Deleting #{DB_PATH}..."
|
13
13
|
rm_f DB_PATH
|
14
14
|
end
|
15
|
-
#
|
15
|
+
# </snip>
|
16
16
|
|
17
|
-
#
|
17
|
+
# <snip> Title of first snip
|
18
18
|
desc "create the database"
|
19
19
|
task :create do
|
20
20
|
puts "Creating file #{DB_PATH} if it doesn't exist..."
|
21
21
|
touch DB_PATH
|
22
22
|
end
|
23
|
-
#
|
23
|
+
# </snip>
|
24
24
|
|
25
|
-
#
|
25
|
+
# <snip> Title of this snip
|
26
26
|
desc "drop the database"
|
27
27
|
task :drop do
|
28
28
|
puts "Deleting #{DB_PATH}..."
|
29
29
|
rm_f DB_PATH
|
30
30
|
end
|
31
|
-
#
|
31
|
+
# </snip>
|
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# <snip>
|
2
2
|
class OrangeTree
|
3
3
|
attr_reader :age, :height
|
4
4
|
def initialize
|
5
5
|
@age = 0
|
6
6
|
@oranges = []
|
7
7
|
end
|
8
|
-
|
8
|
+
#</snip>
|
9
9
|
|
10
|
-
# test
|
10
|
+
# test <snip> TITLE
|
11
11
|
def age!
|
12
12
|
@oranges += Array.new(rand(1..10)) { Orange.new } if @age > 5
|
13
13
|
end
|
14
|
-
|
14
|
+
#</snip>
|
15
15
|
|
16
|
-
# ewre w
|
16
|
+
# ewre w<snip> test
|
17
17
|
def any_oranges?
|
18
18
|
!@oranges.empty?
|
19
19
|
end
|
20
|
-
# test
|
20
|
+
# test </snip> test
|
21
21
|
|
22
22
|
def pick_an_orange!
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
#<$> Title ggg
|
2
2
|
def method
|
3
3
|
"code"
|
4
4
|
end
|
5
|
-
|
5
|
+
#</$>
|
6
6
|
|
7
|
-
|
7
|
+
#<$> Title 2323
|
8
8
|
def method
|
9
9
|
"code"
|
10
10
|
end
|
11
|
-
|
11
|
+
#</$>
|
12
12
|
|
13
|
-
|
13
|
+
#<$> Title 4
|
14
14
|
def method
|
15
15
|
"code"
|
16
16
|
end
|
17
|
-
|
17
|
+
#</$>
|
data/snip.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "clipboard", "~> 1.0"
|
25
26
|
# spec.add_development_dependency "sqlite3", "~> 1.3"
|
26
27
|
# spec.add_development_dependency "activerecord", "~>4.1"
|
27
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snipgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jgerminario
|
@@ -10,50 +10,64 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.7'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - ~>
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.7'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - ~>
|
33
|
+
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '10.0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - ~>
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '10.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rspec
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - ~>
|
47
|
+
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '3.0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ~>
|
54
|
+
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '3.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: clipboard
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.0'
|
57
71
|
description: Using simple tags, you can mark snips in your code without interrupting
|
58
72
|
your workflow. At the end of the day, run 'snip' to gather your snips from all your
|
59
73
|
code for easy review. Compatible with Ruby and JavaScript. Visit the GitHub homepage
|
@@ -66,6 +80,7 @@ extensions: []
|
|
66
80
|
extra_rdoc_files: []
|
67
81
|
files:
|
68
82
|
- Gemfile
|
83
|
+
- Gemfile.lock
|
69
84
|
- LICENSE.txt
|
70
85
|
- Rakefile
|
71
86
|
- app/controllers/controller.rb
|
@@ -73,6 +88,7 @@ files:
|
|
73
88
|
- app/models/utils/batchprocessing.rb
|
74
89
|
- app/models/utils/codescanner.rb
|
75
90
|
- app/models/utils/destinationfilewriter.rb
|
91
|
+
- app/models/utils/searchfile.rb
|
76
92
|
- app/models/utils/sourcefilereader.rb
|
77
93
|
- app/views/viewformatter.rb
|
78
94
|
- bin/snip
|
@@ -81,11 +97,12 @@ files:
|
|
81
97
|
- lib/snip/version.rb
|
82
98
|
- log/snip.log
|
83
99
|
- my_snips.rb
|
84
|
-
- pkg/snip-0.0.1.gem
|
85
100
|
- rspec/rspec.rb
|
86
101
|
- rspec/snip.sublime-project
|
87
102
|
- rspec/snip.sublime-workspace
|
88
103
|
- rspec/test_snip_files/subfolder/test3.rb
|
104
|
+
- rspec/test_snip_files/subfolder/test_erb.erb
|
105
|
+
- rspec/test_snip_files/subfolder/test_js.js
|
89
106
|
- rspec/test_snip_files/test.rb
|
90
107
|
- rspec/test_snip_files/test2.rb
|
91
108
|
- snip.gemspec
|
@@ -103,12 +120,12 @@ require_paths:
|
|
103
120
|
- log
|
104
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
122
|
requirements:
|
106
|
-
- -
|
123
|
+
- - ">="
|
107
124
|
- !ruby/object:Gem::Version
|
108
125
|
version: '0'
|
109
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
127
|
requirements:
|
111
|
-
- -
|
128
|
+
- - ">="
|
112
129
|
- !ruby/object:Gem::Version
|
113
130
|
version: '0'
|
114
131
|
requirements: []
|
data/pkg/snip-0.0.1.gem
DELETED
Binary file
|