code_web 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/code_web/cli.rb +6 -1
- data/lib/code_web/html_report.rb +60 -29
- data/lib/code_web/text_report.rb +3 -2
- data/lib/code_web/version.rb +1 -1
- data/spec/code_parser_spec.rb +12 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6663f8fa280e0e501e377ba513d3c4db1be267
|
4
|
+
data.tar.gz: 2d9904670ee7c4b050c099683360d9d989340532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92eac121116f0d1037498d276b691b4f75aa98b894eabb0579d404bb05852953c0d83255f4455158417de4df70b3e7627690a404082f1abfbb996e6d7bba429
|
7
|
+
data.tar.gz: 1aa905da6a3a5e26a394c4cd6c82c4c391a387403c50c26fbf5a1d207b022294e7e6858ebbfac43af5482e0c7dc2534515e186b75e0a19fc2653a188543bd6e0
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.0.7] - 2017-06-13
|
10
|
+
- fix `-u` flag
|
11
|
+
- added `--both` to show both github and local filesystem links
|
12
|
+
|
9
13
|
## [0.0.6] - 2017-06-13
|
10
14
|
- filenames in output, but only show first one
|
11
15
|
- added flag `--url` to link to github instead of local filesystem
|
@@ -23,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
23
27
|
- added flags for byebug and pry to allow debugging of issues (sorry not more stable)
|
24
28
|
|
25
29
|
|
26
|
-
[Unreleased]: https://github.com/kbrock/code_web/compare/v0.0.
|
30
|
+
[Unreleased]: https://github.com/kbrock/code_web/compare/v0.0.7...HEAD
|
31
|
+
[0.0.7]: https://github.com/kbrock/code_web/compare/v0.0.6...v0.0.7
|
27
32
|
[0.0.6]: https://github.com/kbrock/code_web/compare/v0.0.5...v0.0.6
|
28
33
|
[0.0.5]: https://github.com/kbrock/code_web/compare/v0.0.4...v0.0.5
|
data/lib/code_web/cli.rb
CHANGED
@@ -21,6 +21,10 @@ module CodeWeb
|
|
21
21
|
# defaults to local filesystem
|
22
22
|
attr_accessor :base_url
|
23
23
|
|
24
|
+
# @attribute file_and_url [rw]
|
25
|
+
# @return true if both url and file are displayed
|
26
|
+
attr_accessor :file_and_url
|
27
|
+
|
24
28
|
# @attribute report_generator [rw]
|
25
29
|
# @return class that runs the report (i.e.: TextReport, HtmlReport)
|
26
30
|
attr_accessor :report_generator
|
@@ -61,7 +65,8 @@ module CodeWeb
|
|
61
65
|
opt.banner = "Usage: code_web regex [file_name ...]"
|
62
66
|
# opt.on('-n', '--requests=count', Integer, "Number of requests (default: #{requests})") { |v| options[:requests] = v }
|
63
67
|
opt.on('-t', '--text', 'Use text reports') { |v| self.report_generator = ::CodeWeb::TextReport }
|
64
|
-
opt.on('u',
|
68
|
+
opt.on('-u', '--url URL', 'Base url (e.g.: https://github.com/miq/miq/blob/master)') { |v| self.base_url = v }
|
69
|
+
opt.on('-b', '--both', 'Show file and url references') { |v| self.file_and_url = v }
|
65
70
|
opt.on('-a', '--arg ARG_REGEX', 'Only files with hash argument') { |v| self.arg_regex = Regexp.new(v) }
|
66
71
|
opt.on('-o', '--output FILENAME', 'Output filename') { |v| self.output = (v == '-') ? STDOUT : File.new(v,'w') }
|
67
72
|
opt.on('-e', '--error-out', 'exit on unknown tags') { |v| self.exit_on_error = true}
|
data/lib/code_web/html_report.rb
CHANGED
@@ -9,6 +9,7 @@ module CodeWeb
|
|
9
9
|
attr_accessor :method_calls
|
10
10
|
attr_accessor :arg_regex
|
11
11
|
attr_accessor :base_url
|
12
|
+
attr_accessor :url_and_file
|
12
13
|
def arg_regex? ; ! arg_regex.nil? ; end
|
13
14
|
|
14
15
|
# @!attribute :class_map [rw]
|
@@ -18,11 +19,12 @@ module CodeWeb
|
|
18
19
|
# @return [Map<Regexp,color>] regex expressing name of main file
|
19
20
|
attr_accessor :class_map
|
20
21
|
|
21
|
-
def initialize(method_calls, class_map={}, arg_regex=nil,
|
22
|
+
def initialize(method_calls, class_map={}, arg_regex=nil, out=STDOUT, options = {})
|
22
23
|
@method_calls = method_calls
|
23
24
|
@class_map = class_map
|
24
25
|
@arg_regex = arg_regex
|
25
|
-
@base_url = base_url
|
26
|
+
@base_url = options[:base_url]
|
27
|
+
@url_and_file = options[:url_and_file]
|
26
28
|
@out = out
|
27
29
|
end
|
28
30
|
|
@@ -44,30 +46,38 @@ table, td, th { border:1px solid black; }
|
|
44
46
|
<%- display_yield_column = methods_with_type.detect(&:yields?) -%>
|
45
47
|
<table>
|
46
48
|
<thead><tr>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
<%- methods_with_type.arg_keys.each do |arg| -%>
|
50
|
+
<td><%=arg%></td>
|
51
|
+
<%- end -%>
|
52
|
+
<%- if display_yield_column -%>
|
51
53
|
<td>yield?</td>
|
52
|
-
|
54
|
+
<%- end -%>
|
53
55
|
<td>ref</td>
|
56
|
+
<%- if base_url -%>
|
57
|
+
<td>file ref</td>
|
58
|
+
<%- end -%>
|
54
59
|
</tr></thead>
|
55
60
|
<tbody>
|
56
61
|
<%- methods_with_type.group_by(:signature, arg_regex).each do |methods_by_signature| -%>
|
57
62
|
<tr>
|
58
63
|
<%- methods_with_type.arg_keys.each do |arg| -%>
|
59
|
-
<td><%=
|
64
|
+
<td><%= maybe_simplified_argument(methods_by_signature.hash_arg, arg) %></td>
|
60
65
|
<%- end -%>
|
61
|
-
|
66
|
+
<%- if display_yield_column -%>
|
62
67
|
<td><%= methods_by_signature.f.yields? %></td>
|
63
|
-
|
68
|
+
<%- end -%>
|
64
69
|
<td>
|
65
|
-
<%- methods_by_signature
|
66
|
-
|
67
|
-
<%= method_link(method, i == 0 ? nil : i+1) %>
|
70
|
+
<%- method_links(methods_by_signature).each do |link| -%>
|
71
|
+
<%= link %>
|
68
72
|
<%- end -%>
|
73
|
+
</td>
|
74
|
+
<%- if base_url -%>
|
75
|
+
<td>
|
76
|
+
<%- method_links(methods_by_signature, true).each do |link| -%>
|
77
|
+
<%= link %>
|
69
78
|
<%- end -%>
|
70
79
|
</td>
|
80
|
+
<%- end -%>
|
71
81
|
</tr>
|
72
82
|
<%- end -%>
|
73
83
|
</tbody>
|
@@ -87,12 +97,17 @@ table, td, th { border:1px solid black; }
|
|
87
97
|
<td><%= methods_by_signature.f.yields? ? 'yields' : 'no yield'%></td>
|
88
98
|
<%- end -%>
|
89
99
|
<td>
|
90
|
-
<%- methods_by_signature
|
91
|
-
|
92
|
-
<%= method_link(method, i == 0 ? nil : i+1) %>
|
100
|
+
<%- method_links(methods_by_signature).each do |link| -%>
|
101
|
+
<%= link %>
|
93
102
|
<%- end -%>
|
103
|
+
</td>
|
104
|
+
<%- if base_url && url_and_file -%>
|
105
|
+
<td>
|
106
|
+
<%- method_links(methods_by_signature, true).each do |link| -%>
|
107
|
+
<%= link %>
|
94
108
|
<%- end -%>
|
95
109
|
</td>
|
110
|
+
<%- end -%>
|
96
111
|
</tr>
|
97
112
|
<%- end -%>
|
98
113
|
<%- end -%>
|
@@ -124,6 +139,10 @@ table, td, th { border:1px solid black; }
|
|
124
139
|
|
125
140
|
private
|
126
141
|
|
142
|
+
def maybe_simplified_argument(hash, arg)
|
143
|
+
simplified_argument(hash[arg]) if hash.key?(arg)
|
144
|
+
end
|
145
|
+
|
127
146
|
# shorten the argument
|
128
147
|
def simplified_argument(arg)
|
129
148
|
short_arg = case arg
|
@@ -151,25 +170,37 @@ table, td, th { border:1px solid black; }
|
|
151
170
|
collection.inject(Set.new) {|acc, m| m.arg_keys.each {|k| acc << k} ; acc}.sort_by {|n| n}
|
152
171
|
end
|
153
172
|
|
173
|
+
def method_links(methods_by_signature, force_filename = false)
|
174
|
+
methods_by_signature.group_by(:filename).flat_map do |methods_by_filename|
|
175
|
+
methods_by_filename.each_with_index.map do |method, i|
|
176
|
+
method_link(method, (i > 0 || force_filename) ? i+1 : nil, force_filename)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
154
181
|
# create a link to a method
|
155
182
|
# add a class if the method is in a particular file
|
156
183
|
|
157
|
-
def method_link(m, count=
|
184
|
+
def method_link(m, count, force_filename = false)
|
158
185
|
name = count ? "[#{count}]" : m.short_filename
|
159
|
-
class_name =
|
186
|
+
class_name = class_for_filename(m.filename)
|
187
|
+
url = url_for_filename(m.filename, m.line, force_filename)
|
188
|
+
%{<a href="#{url}" title="#{html_safe(m.signature)}"#{" class=\"#{class_name}\"" if class_name}>#{name}</a>}
|
189
|
+
end
|
190
|
+
|
191
|
+
def class_for_filename(filename)
|
160
192
|
class_map.each_with_index do |(pattern, color), i|
|
161
|
-
if
|
162
|
-
|
163
|
-
|
164
|
-
|
193
|
+
return "f#{i}" if filename =~ pattern
|
194
|
+
end
|
195
|
+
nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def url_for_filename(filename, line, force_filename = false)
|
199
|
+
if !force_filename && base_url
|
200
|
+
"#{filename.gsub(pwd, base_url)}#L#{line}"
|
201
|
+
else
|
202
|
+
"subl://open?url=file://#{filename}&line=#{line}"
|
165
203
|
end
|
166
|
-
url = if base_url
|
167
|
-
"#{m.filename.gsub(pwd, base_url)}#L#{m.line}"
|
168
|
-
else
|
169
|
-
#NOTE: may want to CGI::escape(m.filename)
|
170
|
-
"subl://open?url=file://#{m.filename}&line=#{m.line}"
|
171
|
-
end
|
172
|
-
%{<a href="#{url}" title="#{html_safe(m.signature)}"#{" class=\"#{class_name}\"" if class_name}>#{name}</a>}
|
173
204
|
end
|
174
205
|
|
175
206
|
def pwd
|
data/lib/code_web/text_report.rb
CHANGED
@@ -8,10 +8,11 @@ module CodeWeb
|
|
8
8
|
attr_accessor :base_url
|
9
9
|
def arg_regex? ; ! arg_regex.nil? ; end
|
10
10
|
|
11
|
-
def initialize(method_calls, class_map=
|
11
|
+
def initialize(method_calls, class_map={}, arg_regex=nil, out=STDOUT, options = {})
|
12
12
|
@method_calls = method_calls
|
13
13
|
@arg_regex = arg_regex
|
14
|
-
@base_url = base_url
|
14
|
+
@base_url = options[:base_url]
|
15
|
+
@url_and_file = options[:url_and_file]
|
15
16
|
@out = out
|
16
17
|
end
|
17
18
|
|
data/lib/code_web/version.rb
CHANGED
data/spec/code_parser_spec.rb
CHANGED
@@ -34,18 +34,18 @@ describe CodeWeb::CodeParser do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
#NOTE the chaining isn't perfect
|
37
|
-
it "should support method chaining" do
|
37
|
+
it "should support method chaining" do ##
|
38
38
|
parse "x(a:5).y().z(5)"
|
39
39
|
expect(method_calls('x')).to eq([
|
40
40
|
meth('x', [{a:5}])
|
41
41
|
])
|
42
42
|
|
43
43
|
expect(method_calls('x(...).y')).to eq([
|
44
|
-
meth('x(...)
|
44
|
+
meth(['x(...)', :y])
|
45
45
|
])
|
46
46
|
|
47
47
|
expect(method_calls('x(...).y.z')).to eq([
|
48
|
-
meth('x(...).y
|
48
|
+
meth(['x(...).y', :z],[5])
|
49
49
|
])
|
50
50
|
end
|
51
51
|
|
@@ -139,16 +139,20 @@ describe CodeWeb::CodeParser do
|
|
139
139
|
meth('puts')
|
140
140
|
])
|
141
141
|
end
|
142
|
-
it "should support constants" do
|
142
|
+
it "should support global constants" do
|
143
143
|
parse %{
|
144
144
|
ABC=puts
|
145
|
-
Class::ABC.runx
|
146
145
|
}
|
147
146
|
expect(method_calls('puts')).to eq([
|
148
147
|
meth('puts')
|
149
148
|
])
|
150
|
-
|
151
|
-
|
149
|
+
end
|
150
|
+
it "supports class constants" do
|
151
|
+
parse %{
|
152
|
+
Class::ABC.runx
|
153
|
+
}
|
154
|
+
expect(method_calls('Class::ABC.runx')).to eq([
|
155
|
+
meth(["Class::ABC",:runx])
|
152
156
|
])
|
153
157
|
end
|
154
158
|
end
|
@@ -226,7 +230,7 @@ describe CodeWeb::CodeParser do
|
|
226
230
|
|
227
231
|
def method_calls(method_name=nil)
|
228
232
|
if method_name
|
229
|
-
subject.method_calls.select { |mc| mc.full_method_name =~ /#{method_name}
|
233
|
+
subject.method_calls.select { |mc| mc.full_method_name =~ /#{Regexp.escape(method_name)}$/ }
|
230
234
|
else
|
231
235
|
subject.method_calls
|
232
236
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keenan Brock
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|