fukuzatsu 0.9.16 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +1 -1
- data/fukuzatsu.gemspec +1 -0
- data/lib/fukuzatsu.rb +1 -0
- data/lib/fukuzatsu/cli.rb +3 -3
- data/lib/fukuzatsu/formatters/base.rb +7 -8
- data/lib/fukuzatsu/formatters/html.rb +15 -1
- data/lib/fukuzatsu/formatters/templates/output.html.haml +39 -4
- data/lib/fukuzatsu/line_of_code.rb +19 -0
- data/lib/fukuzatsu/parsed_file.rb +14 -0
- data/lib/fukuzatsu/version.rb +1 -1
- data/spec/analyzer_spec.rb +22 -0
- data/spec/fixtures/module_with_class.rb +9 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98e183078ac1f80b93a9f0c432ff70a5a75fb156
|
4
|
+
data.tar.gz: 9ff83590fd2e21f4dab4100db0bb32dc51d09468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361c28387778b0fa9211c4401dc9d6ebfd1ad491a0a1c6857a0c57ccc32b052d3b4ec81fefbd30ca02a0304800120b89ff6781ae3188c5de8e553cb834fbcc8b
|
7
|
+
data.tar.gz: e8d4b595508e6fd5db7d3f057dc2325d3d1c7c694729f6caf8b09fcf6c29f8cbc79d5ab5513df4a57f6daf5944a42d15295af2c8cfb00ec8e8db4c6fb6eeec39
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
ODE
|
2
2
|
## Version 0.4
|
3
3
|
|
4
4
|
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
data/fukuzatsu.gemspec
CHANGED
data/lib/fukuzatsu.rb
CHANGED
@@ -10,6 +10,7 @@ require_relative "fukuzatsu/formatters/csv"
|
|
10
10
|
require_relative "fukuzatsu/formatters/html"
|
11
11
|
require_relative "fukuzatsu/formatters/html_index"
|
12
12
|
require_relative "fukuzatsu/formatters/text"
|
13
|
+
require_relative "fukuzatsu/line_of_code"
|
13
14
|
require_relative "fukuzatsu/parsed_file"
|
14
15
|
require_relative "fukuzatsu/parsed_method"
|
15
16
|
require_relative "fukuzatsu/version"
|
data/lib/fukuzatsu/cli.rb
CHANGED
@@ -30,7 +30,7 @@ module Fukuzatsu
|
|
30
30
|
|
31
31
|
def file_list(start_file)
|
32
32
|
if File.directory?(start_file)
|
33
|
-
return Dir.glob(File.join(start_file, "**", "
|
33
|
+
return Dir.glob(File.join(start_file, "**", "*.rb"))
|
34
34
|
else
|
35
35
|
return [start_file]
|
36
36
|
end
|
@@ -50,13 +50,13 @@ module Fukuzatsu
|
|
50
50
|
def handle_index(file_summary)
|
51
51
|
return unless options['format'] == 'html'
|
52
52
|
index = Formatters::HtmlIndex.new(file_summary)
|
53
|
-
self.last_file =
|
53
|
+
self.last_file = File.join(index.output_path, index.filename)
|
54
54
|
index.export
|
55
55
|
end
|
56
56
|
|
57
57
|
def parse(path_to_file, options={})
|
58
58
|
file = ParsedFile.new(path_to_file: path_to_file)
|
59
|
-
parser = formatter.new(file)
|
59
|
+
parser = formatter.new(file, file.source)
|
60
60
|
parser.export
|
61
61
|
self.summaries ||= []
|
62
62
|
self.summaries << file.summary.merge(results_file: parser.path_to_results)
|
@@ -4,10 +4,12 @@ module Formatters
|
|
4
4
|
|
5
5
|
def self.included(klass)
|
6
6
|
klass.send(:attr_accessor, :file)
|
7
|
+
klass.send(:attr_accessor, :source)
|
7
8
|
end
|
8
9
|
|
9
|
-
def initialize(file)
|
10
|
+
def initialize(file, source="")
|
10
11
|
self.file = file
|
12
|
+
self.source = source
|
11
13
|
end
|
12
14
|
|
13
15
|
def content
|
@@ -23,17 +25,17 @@ module Formatters
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def output_path
|
26
|
-
output_path =
|
28
|
+
output_path = File.dirname(File.join(root_path, self.file.path_to_file))
|
27
29
|
FileUtils.mkpath(output_path)
|
28
30
|
output_path
|
29
31
|
end
|
30
32
|
|
31
33
|
def path_to_results
|
32
|
-
|
34
|
+
File.join(output_path, filename)
|
33
35
|
end
|
34
36
|
|
35
37
|
def filename
|
36
|
-
self.file.path_to_file
|
38
|
+
File.basename(self.file.path_to_file) + file_extension
|
37
39
|
end
|
38
40
|
|
39
41
|
def file_extension
|
@@ -42,12 +44,9 @@ module Formatters
|
|
42
44
|
|
43
45
|
def export
|
44
46
|
begin
|
45
|
-
|
46
|
-
outfile.write(content)
|
47
|
+
File.open(path_to_results, 'w') {|outfile| outfile.write(content)}
|
47
48
|
rescue Exception => e
|
48
49
|
puts "Unable to write output: #{e} #{e.backtrace}"
|
49
|
-
ensure
|
50
|
-
outfile && outfile.close
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rouge'
|
2
|
+
|
1
3
|
module Formatters
|
2
4
|
|
3
5
|
class Html
|
@@ -13,6 +15,7 @@ module Formatters
|
|
13
15
|
Object.new, {
|
14
16
|
header: header,
|
15
17
|
rows: rows,
|
18
|
+
source_lines: preprocessed,
|
16
19
|
class_name: file.class_name,
|
17
20
|
complexity: file.complexity,
|
18
21
|
path_to_file: file.path_to_file,
|
@@ -22,10 +25,22 @@ module Formatters
|
|
22
25
|
)
|
23
26
|
end
|
24
27
|
|
28
|
+
def formatter
|
29
|
+
Rouge::Formatters::HTML.new(line_numbers: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def lexer
|
33
|
+
lexer = Rouge::Lexers::Ruby.new
|
34
|
+
end
|
35
|
+
|
25
36
|
def output_template
|
26
37
|
File.read(File.dirname(__FILE__) + "/templates/output.html.haml")
|
27
38
|
end
|
28
39
|
|
40
|
+
def preprocessed
|
41
|
+
formatter.format(lexer.lex(source))
|
42
|
+
end
|
43
|
+
|
29
44
|
def rows
|
30
45
|
i = 0
|
31
46
|
file.methods.inject([]) do |a, method|
|
@@ -46,7 +61,6 @@ module Formatters
|
|
46
61
|
".htm"
|
47
62
|
end
|
48
63
|
|
49
|
-
|
50
64
|
end
|
51
65
|
|
52
66
|
end
|
@@ -8,9 +8,38 @@
|
|
8
8
|
%script{language: "javascript", src: "http://code.jquery.com/jquery-1.11.0.min.js", type: "text/javascript"}
|
9
9
|
%script{language: "javascript", src: "http://code.jquery.com/jquery-migrate-1.2.1.min.js", type: "text/javascript"}
|
10
10
|
%script{language: "javascript", src: "http://cdn.datatables.net/1.10.0/js/jquery.dataTables.js", type: "text/javascript"}
|
11
|
-
|
12
|
-
|
11
|
+
%script{language: "javascript", src: "http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.0/highlight.min.js", type: "text/javascript"}
|
12
|
+
:css
|
13
|
+
#{Rouge::Theme.find('thankful_eyes').render(scope: '.highlight')}
|
13
14
|
body { background: #593232; color: #fff; font-family: arial, sans-serif; padding: 2em; }
|
15
|
+
div.column { float: left; width: 45%; margin-left: 4%; }
|
16
|
+
div.file_listing { padding: .1em; border-radius: 5px; background: #000; width: 100%; border: 1px solid #000;}
|
17
|
+
div.file_meta { float: left; height: 3em; width: 30%; }
|
18
|
+
h1 { color:#fff; font-size: 1.25em; margin-top: .25em; }
|
19
|
+
h2 { color:#fff; font-size: .75em; margin-top: -1em; }
|
20
|
+
h3 { color:#fff; font-size: 1.1em;margin-top: 1em; }
|
21
|
+
h3.highlighted { background: rgba(170, 161, 57, .6); border-radius: 100px; padding: .25em; padding-left: 1em; color: #000;}
|
22
|
+
h3.highlighted-method { background: rgba(153, 51, 80, .6); border-radius: 100px; padding-left: 1em; }
|
23
|
+
li { margin-bottom: 1em;}
|
24
|
+
pre { line-height: 1.75em;}
|
25
|
+
pre.lineno { margin-top: -1.4em !important;}
|
26
|
+
span.highlighted { padding-left: 1em; display: inline-block; position: absolute; left: 0px; padding-right: 90%}
|
27
|
+
a:link, a:visited { color: #aaa }
|
28
|
+
|
29
|
+
.file_listing table { width: 100%; box-shadow: 0 5px 0 rgba(0,0,0,.8); border-spacing: 0; border: 5px solid #000; border-radius: 5px; border-collapse: collapse; min-width: 50%; }
|
30
|
+
.file_listing td { text-align: left; padding: .5em; padding-left: 1.25em !important;}
|
31
|
+
.file_listing td.gutter { background-color: rgb(109, 109, 109) !important; }
|
32
|
+
.file_listing tfoot { background: #000; border-top: 10px solid #000; font-family: courier; margin-top: 4em; font-size: .75em; }
|
33
|
+
.file_listing th { background: #000; text-align: left; padding: .5em; }
|
34
|
+
.file_listing tr.faint td { opacity: 0.5; font-style: italic; }
|
35
|
+
.file_listing tr.header { background-color: #222; }
|
36
|
+
.file_listing tr { background: rgba(0, 0, 0, 0.25) !important; border-bottom: 1px solid #000;}
|
37
|
+
.file_listing th { background: #000; text-align: left; padding: .5em;}
|
38
|
+
.file_listing td { text-align: left; padding: .5em; padding-left: 1.25em !important;}
|
39
|
+
.file_listing td.center { text-align: center; }
|
40
|
+
.file_listing td.sorting_1 { background: none !important; padding-left: 1.25em !important; }
|
41
|
+
.file_listing tfoot { background: #000; font-family: courier; margin-top: 4em; font-size: .75em; }
|
42
|
+
|
14
43
|
table { box-shadow: 0 5px 0 rgba(0,0,0,.8); background: #444; border-spacing: 0; border: 5px solid #000; border-radius: 25px; border-collapse: collapse; min-width: 50%; }
|
15
44
|
th.sorting_asc, th.sorting_desc { text-transform: uppercase !important; font-size: .8em !important; background-image: none !important; background: rgba(64, 41, 41, .5) !important;}
|
16
45
|
th.sorting { background-position: left !important; border-right: 1px solid #222; text-transform: uppercase !important; font-size: .8em !important}
|
@@ -27,15 +56,16 @@
|
|
27
56
|
td.center { text-align: center; }
|
28
57
|
td.sorting_1 { background: none !important; padding-left: 1.25em !important; }
|
29
58
|
tfoot { background: #000; font-family: courier; margin-top: 4em; font-size: .75em; }
|
30
|
-
|
31
|
-
div.file_meta { float: left; height: 3em; width: 30%; }
|
59
|
+
|
32
60
|
h1 { color:#fff; font-size: 1.25em; margin-top: .25em; }
|
33
61
|
h2 { color:#fff; font-size: .75em; margin-top: -1em; }
|
34
62
|
h3 { color:#fff; font-size: 1em; float: right; margin-top: 1em; }
|
63
|
+
|
35
64
|
div.dataTables_filter { display: none !important; }
|
36
65
|
div.dataTables_paginate { display: none !important; }
|
37
66
|
div.dataTables_info { display: none !important; }
|
38
67
|
|
68
|
+
|
39
69
|
%body
|
40
70
|
.container
|
41
71
|
%table{class: "output-table"}
|
@@ -68,6 +98,11 @@
|
|
68
98
|
%br
|
69
99
|
%input{onclick: "history.back(-1)", type: "button", value: "Back"}
|
70
100
|
|
101
|
+
%br
|
102
|
+
|
103
|
+
.file_listing
|
104
|
+
= source_lines
|
105
|
+
|
71
106
|
:javascript
|
72
107
|
$(document).ready(function(){
|
73
108
|
$('.output-table').dataTable({
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class LineOfCode
|
2
|
+
|
3
|
+
include PoroPlus
|
4
|
+
include Ephemeral::Base
|
5
|
+
|
6
|
+
attr_accessor :line_number, :range, :content
|
7
|
+
|
8
|
+
def self.containing(locs, start_index, end_index)
|
9
|
+
locs.inject([]) do |a, loc|
|
10
|
+
a << loc if loc.in_range?(start_index) || loc.in_range?(end_index)
|
11
|
+
a
|
12
|
+
end.compact
|
13
|
+
end
|
14
|
+
|
15
|
+
def in_range?(index)
|
16
|
+
self.range.include?(index)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -4,6 +4,7 @@ class ParsedFile
|
|
4
4
|
include Ephemeral::Base
|
5
5
|
|
6
6
|
attr_accessor :complexity, :path_to_file, :class_name, :path_to_results
|
7
|
+
attr_accessor :lines_of_code, :source
|
7
8
|
|
8
9
|
def class_name
|
9
10
|
@class_name ||= analyzer.extract_class_name
|
@@ -25,10 +26,23 @@ class ParsedFile
|
|
25
26
|
@methods ||= analyzer.extract_methods
|
26
27
|
end
|
27
28
|
|
29
|
+
def source
|
30
|
+
return @source if @source
|
31
|
+
end_pos = 0
|
32
|
+
self.lines_of_code = []
|
33
|
+
@source = File.readlines(self.path_to_file).each_with_index do |line, index|
|
34
|
+
start_pos = end_pos + 1
|
35
|
+
end_pos += line.size
|
36
|
+
self.lines_of_code << LineOfCode.new(line_number: index + 1, range: (start_pos..end_pos))
|
37
|
+
line
|
38
|
+
end.join
|
39
|
+
end
|
40
|
+
|
28
41
|
def summary
|
29
42
|
{
|
30
43
|
results_file: self.path_to_results,
|
31
44
|
path_to_file: self.path_to_file,
|
45
|
+
source: source,
|
32
46
|
class_name: self.class_name,
|
33
47
|
complexity: complexity
|
34
48
|
}
|
data/lib/fukuzatsu/version.rb
CHANGED
data/spec/analyzer_spec.rb
CHANGED
@@ -58,6 +58,28 @@ describe Analyzer do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
describe "extract_class_name" do
|
62
|
+
context "from a file with a class in it" do
|
63
|
+
let(:analyzer) { Analyzer.new(File.read("spec/fixtures/single_class.rb")) }
|
64
|
+
it "should return the name of the class" do
|
65
|
+
expect(analyzer.extract_class_name).to eq "Gown"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context "from a file with a class inside a module" do
|
69
|
+
let(:analyzer) { Analyzer.new(File.read("spec/fixtures/module_with_class.rb")) }
|
70
|
+
it "should return the name of the class" do
|
71
|
+
expect(analyzer.extract_class_name).to eq "Bee"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
context "from a file with no class in it" do
|
75
|
+
let(:analyzer) { Analyzer.new(File.read("spec/fixtures/single_method.rb")) }
|
76
|
+
it "should return '?'" do
|
77
|
+
expect(analyzer.extract_class_name).to eq "?"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
61
83
|
describe "extract_methods" do
|
62
84
|
# Note: should implicitly trust private method #methods_from
|
63
85
|
context "from a file with a single method" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fukuzatsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bantik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ephemeral
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rouge
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: thor
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +180,7 @@ files:
|
|
166
180
|
- lib/fukuzatsu/formatters/templates/index.html.haml
|
167
181
|
- lib/fukuzatsu/formatters/templates/output.html.haml
|
168
182
|
- lib/fukuzatsu/formatters/text.rb
|
183
|
+
- lib/fukuzatsu/line_of_code.rb
|
169
184
|
- lib/fukuzatsu/parsed_file.rb
|
170
185
|
- lib/fukuzatsu/parsed_method.rb
|
171
186
|
- lib/fukuzatsu/version.rb
|
@@ -175,6 +190,7 @@ files:
|
|
175
190
|
- spec/fixtures/eg_mod_class.rb
|
176
191
|
- spec/fixtures/eg_mod_class_2.rb
|
177
192
|
- spec/fixtures/eg_module.rb
|
193
|
+
- spec/fixtures/module_with_class.rb
|
178
194
|
- spec/fixtures/multiple_methods.rb
|
179
195
|
- spec/fixtures/nested_methods.rb
|
180
196
|
- spec/fixtures/program_1.rb
|
@@ -223,6 +239,7 @@ test_files:
|
|
223
239
|
- spec/fixtures/eg_mod_class.rb
|
224
240
|
- spec/fixtures/eg_mod_class_2.rb
|
225
241
|
- spec/fixtures/eg_module.rb
|
242
|
+
- spec/fixtures/module_with_class.rb
|
226
243
|
- spec/fixtures/multiple_methods.rb
|
227
244
|
- spec/fixtures/nested_methods.rb
|
228
245
|
- spec/fixtures/program_1.rb
|