simplecov-inline-html 0.0.1

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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,104 @@
1
+ require "erb"
2
+ require "cgi"
3
+ require "fileutils"
4
+ require "digest/sha1"
5
+ require "time"
6
+
7
+ # Ensure we are using a compatible version of SimpleCov
8
+ major, minor, patch = SimpleCov::VERSION.scan(/\d+/).first(3).map(&:to_i)
9
+ if major < 0 || minor < 9 || patch < 0
10
+ raise "The version of SimpleCov you are using is too old. "\
11
+ "Please update with `gem install simplecov` or `bundle update simplecov`"
12
+ end
13
+
14
+ module SimpleCov
15
+ module Formatter
16
+ class InlineHTMLFormatter
17
+ def format(result)
18
+ File.open(File.join(output_path, "index.html"), "wb") do |file|
19
+ file.puts template("layout").result(binding)
20
+ end
21
+ puts output_message(result)
22
+ end
23
+
24
+ def output_message(result)
25
+ "Coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
26
+ end
27
+
28
+ private
29
+
30
+ def file(name)
31
+ File.read(File.join(File.dirname(__FILE__), name))
32
+ end
33
+
34
+ # Returns the an erb instance for the template of given name
35
+ def template(name)
36
+ ERB.new(file("../views/#{name}.erb"))
37
+ end
38
+
39
+ def output_path
40
+ SimpleCov.coverage_path
41
+ end
42
+
43
+ # Returns the html for the given source_file
44
+ def formatted_source_file(source_file)
45
+ template("source_file").result(binding)
46
+ end
47
+
48
+ # Returns a table containing the given source files
49
+ def formatted_file_list(title, source_files)
50
+ title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
51
+ # Silence a warning by using the following variable to assign to itself:
52
+ # "warning: possibly useless use of a variable in void context"
53
+ # The variable is used by ERB via binding.
54
+ title_id = title_id
55
+ template("file_list").result(binding)
56
+ end
57
+
58
+ def data_image(filename)
59
+ _name, type = filename.split(".")
60
+ "data:image/#{type};base64,#{Base64.encode64(file("../assets/#{filename}"))}"
61
+ end
62
+
63
+ def coverage_css_class(covered_percent)
64
+ if covered_percent > 90
65
+ "green"
66
+ elsif covered_percent > 80
67
+ "yellow"
68
+ else
69
+ "red"
70
+ end
71
+ end
72
+
73
+ def strength_css_class(covered_strength)
74
+ if covered_strength > 1
75
+ "green"
76
+ elsif covered_strength == 1
77
+ "yellow"
78
+ else
79
+ "red"
80
+ end
81
+ end
82
+
83
+ # Return a (kind of) unique id for the source file given. Uses SHA1 on path for the id
84
+ def id(source_file)
85
+ Digest::SHA1.hexdigest(source_file.filename)
86
+ end
87
+
88
+ def timeago(time)
89
+ "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
90
+ end
91
+
92
+ def shortened_filename(source_file)
93
+ source_file.filename.sub(SimpleCov.root, ".").gsub(/^\.\//, "")
94
+ end
95
+
96
+ def link_to_source_file(source_file)
97
+ %(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}">#{shortened_filename source_file}</a>)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
104
+ require "simplecov-inline-html/version"
@@ -0,0 +1,7 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class InlineHTMLFormatter
4
+ VERSION = "0.0.1".freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "simplecov-inline-html/version"
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "simplecov-inline-html"
6
+ gem.version = SimpleCov::Formatter::InlineHTMLFormatter::VERSION
7
+ gem.platform = Gem::Platform::RUBY
8
+ gem.authors = ["Jon Rowe"]
9
+ gem.email = ["hello@jonrowe.co.uk"]
10
+ gem.homepage = "https://github.com/JonRowe/simplecov-inline-html"
11
+ gem.description = %(Inline HTML formatter for SimpleCov code coverage tool.)
12
+ gem.summary = gem.description
13
+ gem.license = "MIT"
14
+
15
+ gem.required_ruby_version = "~> 2.4"
16
+ gem.add_development_dependency "bundler", "~> 1.9"
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
20
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ gem.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,45 @@
1
+ <div class="file_list_container" id="<%= title_id %>">
2
+ <h2>
3
+ <span class="group_name"><%= title %></span>
4
+ (<span class="covered_percent"><span class="<%= coverage_css_class(source_files.covered_percent) %>"><%= source_files.covered_percent.round(2) %>%</span></span>
5
+ covered at
6
+ <span class="covered_strength">
7
+ <span class="<%= strength_css_class(source_files.covered_strength) %>">
8
+ <%= source_files.covered_strength.round(2) %>
9
+ </span>
10
+ </span> hits/line)
11
+ </h2>
12
+ <a name="<%= title_id %>"></a>
13
+ <div>
14
+ <b><%= source_files.length %></b> files in total.
15
+ <b><%= source_files.lines_of_code %></b> relevant lines.
16
+ <span class="green"><b><%= source_files.covered_lines %></b> lines covered</span> and
17
+ <span class="red"><b><%= source_files.missed_lines %></b> lines missed </span>
18
+ </div>
19
+ <table class="file_list">
20
+ <thead>
21
+ <tr>
22
+ <th>File</th>
23
+ <th>% covered</th>
24
+ <th>Lines</th>
25
+ <th>Relevant Lines</th>
26
+ <th>Lines covered</th>
27
+ <th>Lines missed</th>
28
+ <th>Avg. Hits / Line</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% source_files.each do |source_file| %>
33
+ <tr>
34
+ <td class="strong"><%= link_to_source_file(source_file) %></td>
35
+ <td class="<%= coverage_css_class(source_file.covered_percent) %> strong"><%= source_file.covered_percent.round(2).to_s %> %</td>
36
+ <td><%= source_file.lines.count %></td>
37
+ <td><%= source_file.covered_lines.count + source_file.missed_lines.count %></td>
38
+ <td><%= source_file.covered_lines.count %></td>
39
+ <td><%= source_file.missed_lines.count %></td>
40
+ <td><%= source_file.covered_strength %></td>
41
+ </tr>
42
+ <% end %>
43
+ </tbody>
44
+ </table>
45
+ </div>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns='http://www.w3.org/1999/xhtml'>
3
+ <head>
4
+ <title>Code coverage for <%= SimpleCov.project_name %></title>
5
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
+ <link rel="shortcut icon" type="image/png" href="<%= data_image("favicon_#{coverage_css_class(result.source_files.covered_percent)}.png") %>" />
7
+ <style>
8
+ <%= file("../assets/application.css") %>
9
+ </style>
10
+ <script type="text/javascript">
11
+ <%= file("../assets/application.js") %>
12
+ </script>
13
+ </head>
14
+
15
+ <body>
16
+ <div id="loading">
17
+ <img src="<%= data_image('loading.gif') %>" alt="loading"/>
18
+ </div>
19
+ <div id="wrapper" style="display: none;">
20
+ <div class="timestamp">Generated <%= timeago(Time.now) %></div>
21
+ <ul class="group_tabs"></ul>
22
+
23
+ <div id="content">
24
+ <%= formatted_file_list("All Files", result.source_files) %>
25
+
26
+ <% result.groups.each do |name, files| %>
27
+ <%= formatted_file_list(name, files) %>
28
+ <% end %>
29
+ </div>
30
+
31
+ <div id="footer">
32
+ Generated by <a href="http://github.com/colszowka/simplecov">simplecov</a> v<%= SimpleCov::VERSION %>
33
+ and simplecov-inlinehtml v<%= SimpleCov::Formatter::InlineHTMLFormatter::VERSION %><br/>
34
+ using <%= result.command_name %>
35
+ </div>
36
+
37
+ <div class="source_files">
38
+ <% result.source_files.each do |source_file| %>
39
+ <%= formatted_source_file(source_file) %>
40
+ <% end %>
41
+ </div>
42
+ </div>
43
+ </body>
44
+ </html>
@@ -0,0 +1,23 @@
1
+ <div class="source_table" id="<%= id source_file %>">
2
+ <div class="header">
3
+ <h3><%= shortened_filename source_file %></h3>
4
+ <h4><span class="<%= coverage_css_class(source_file.covered_percent) %>"><%= source_file.covered_percent.round(2).to_s %> %</span> covered</h4>
5
+ <div>
6
+ <b><%= source_file.lines_of_code %></b> relevant lines.
7
+ <span class="green"><b><%= source_file.covered_lines.count %></b> lines covered</span> and
8
+ <span class="red"><b><%= source_file.missed_lines.count %></b> lines missed.</span>
9
+ </div>
10
+ </div>
11
+
12
+ <pre>
13
+ <ol>
14
+ <% source_file.lines.each do |line| %>
15
+ <li class="<%= line.status %>" data-hits="<%= line.coverage ? line.coverage : '' %>" data-linenumber="<%= line.number %>">
16
+ <% if line.covered? %><span class="hits"><%= line.coverage %></span><% end %>
17
+ <% if line.skipped? %><span class="hits">skipped</span><% end %>
18
+ <code class="ruby"><%= CGI.escapeHTML(line.src.chomp) %></code>
19
+ </li>
20
+ <% end %>
21
+ </ol>
22
+ </pre>
23
+ </div>
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-inline-html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ description: Inline HTML formatter for SimpleCov code coverage tool.
28
+ email:
29
+ - hello@jonrowe.co.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".travis.yml"
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - assets/application.css
41
+ - assets/application.js
42
+ - assets/favicon_green.png
43
+ - assets/favicon_red.png
44
+ - assets/favicon_yellow.png
45
+ - assets/loading.gif
46
+ - assets/magnify.png
47
+ - lib/simplecov-inline-html.rb
48
+ - lib/simplecov-inline-html/version.rb
49
+ - simplecov-inline-html.gemspec
50
+ - views/file_list.erb
51
+ - views/layout.erb
52
+ - views/source_file.erb
53
+ homepage: https://github.com/JonRowe/simplecov-inline-html
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.4'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.5.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Inline HTML formatter for SimpleCov code coverage tool.
77
+ test_files: []