Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ $(document).ready(function () {
paging: false
});

// Syntax highlight all files up front - deactivated
// $('.source_table pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
// Materialize a source file from its <template> tag into the .source_files container.
// Returns the materialized element, or the existing one if already materialized.
function materializeSourceFile(sourceFileId) {
var existing = document.getElementById(sourceFileId);
if (existing) return $(existing);

var tmpl = document.getElementById('tmpl-' + sourceFileId);
if (!tmpl) return null;

var clone = document.importNode(tmpl.content, true);
$('.source_files').append(clone);

var el = $('#' + sourceFileId);

// Apply syntax highlighting on first materialization
el.find('pre code').each(function (i, e) { hljs.highlightBlock(e, ' ') });
el.addClass('highlighted');

return el;
}

// Syntax highlight source files on first toggle of the file view popup
$("a.src_link").click(function () {
// Get the source file element that corresponds to the clicked element
var source_table = $($(this).attr('href'));

// If not highlighted yet, do it!
if (!source_table.hasClass('highlighted')) {
source_table.find('pre code').each(function (i, e) { hljs.highlightBlock(e, ' ') });
source_table.addClass('highlighted');
};
var sourceFileId = $(this).attr('href').substring(1);
materializeSourceFile(sourceFileId);
});

var prev_anchor;
Expand All @@ -36,6 +48,10 @@ $(document).ready(function () {
onLoad: function () {
prev_anchor = curr_anchor ? curr_anchor : window.location.hash.substring(1);
curr_anchor = this.href.split('#')[1];

// Ensure the source file is materialized before colorbox tries to inline it
materializeSourceFile(curr_anchor.replace(/-L.*/, ''));

window.location.hash = curr_anchor;

$('.file_list_container').hide();
Expand All @@ -56,8 +72,8 @@ $(document).ready(function () {
}
});

// Set-up of anchor of linenumber
$('.source_table li[data-linenumber]').click(function () {
// Event delegation for line number clicks (works with template-materialized elements)
$(document).on('click', '.source_table li[data-linenumber]', function () {
$('#cboxLoadedContent').scrollTop(this.offsetTop);
var new_anchor = curr_anchor.replace(/-.*/, '') + '-L' + $(this).data('linenumber');
window.location.replace(window.location.href.replace(/#.*/, '#' + new_anchor));
Expand All @@ -75,6 +91,10 @@ $(document).ready(function () {
var ary = anchor.split('-L');
var source_file_id = ary[0];
var linenumber = ary[1];

// Materialize before opening colorbox
materializeSourceFile(source_file_id);

$('a.src_link[href="#' + source_file_id + '"]').colorbox({ open: true });
if (linenumber !== undefined) {
$('#cboxLoadedContent').scrollTop($('#cboxLoadedContent .source_table li[data-linenumber="' + linenumber + '"]')[0].offsetTop);
Expand Down Expand Up @@ -123,11 +143,17 @@ $(document).ready(function () {
if (window.location.hash) {
var anchor = window.location.hash.substring(1);
if (anchor.length === 40) {
// Materialize before clicking
materializeSourceFile(anchor);
$('a.src_link[href="#' + anchor + '"]').click();
} else if (anchor.length > 40) {
var ary = anchor.split('-L');
var source_file_id = ary[0];
var linenumber = ary[1];

// Materialize before opening colorbox
materializeSourceFile(source_file_id);

$('a.src_link[href="#' + source_file_id + '"]').colorbox({ open: true });
// Scroll to anchor of linenumber
$('#' + source_file_id + ' li[data-linenumber="' + linenumber + '"]').click();
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov-html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def output_message(result)

# Returns the an erb instance for the template of given name
def template(name)
@templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__), "../views/", "#{name}.erb")))
@templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__), "../views/", "#{name}.erb")), trim_mode: "-")
end

def output_path
Expand Down
2 changes: 1 addition & 1 deletion public/application.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions views/covered_percent.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<span class="<%= coverage_css_class(percent) %>">
<%= percent.round(2) %>%
</span>
<span class="<%= coverage_css_class(percent) %>"><%= percent.round(2) %>%</span>
64 changes: 31 additions & 33 deletions views/file_list.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
<span class="red"><b><%= source_files.missed_lines %></b> lines missed. </span>
(<%= covered_percent(source_files.covered_percent) %>)
</div>

<% if branchable_result? %>
<div class="t-branch-summary">
<span><b><%= source_files.total_branches %></b> total branches, </span>
<span class="green"><b><%= source_files.covered_branches %></b> branches covered</span> and
<span class="red"><b><%= source_files.missed_branches %></b> branches missed.</span>
(<%= covered_percent(source_files.branch_covered_percent) %>)
</div>
<% end %>

<%- if branchable_result? -%>
<div class="t-branch-summary">
<span><b><%= source_files.total_branches %></b> total branches, </span>
<span class="green"><b><%= source_files.covered_branches %></b> branches covered</span> and
<span class="red"><b><%= source_files.missed_branches %></b> branches missed.</span>
(<%= covered_percent(source_files.branch_covered_percent) %>)
</div>
<%- end -%>
<div class="file_list--responsive">
<table class="file_list">
<thead>
Expand All @@ -46,32 +44,32 @@
<th class="cell--number">Lines covered</th>
<th class="cell--number">Lines missed</th>
<th class="cell--number">Avg. Hits / Line</th>
<% if branchable_result? %>
<th class="cell--number">Branch Coverage</th>
<th class="cell--number">Branches</th>
<th class="cell--number">Covered branches</th>
<th class="cell--number">Missed branches </th>
<% end %>
<%- if branchable_result? -%>
<th class="cell--number">Branch Coverage</th>
<th class="cell--number">Branches</th>
<th class="cell--number">Covered branches</th>
<th class="cell--number">Missed branches </th>
<%- end -%>
</tr>
</thead>
<tbody>
<% source_files.each do |source_file| %>
<tr class="t-file">
<td class="strong t-file__name"><%= link_to_source_file(source_file) %></td>
<td class="<%= coverage_css_class(source_file.covered_percent) %> strong cell--number t-file__coverage"><%= sprintf("%.2f", source_file.covered_percent.round(2)) %> %</td>
<td class="cell--number"><%= source_file.lines.count %></td>
<td class="cell--number"><%= source_file.covered_lines.count + source_file.missed_lines.count %></td>
<td class="cell--number"><%= source_file.covered_lines.count %></td>
<td class="cell--number"><%= source_file.missed_lines.count %></td>
<td class="cell--number"><%= sprintf("%.2f", source_file.covered_strength.round(2)) %></td>
<% if branchable_result? %>
<td class="<%= coverage_css_class(source_file.branches_coverage_percent) %> strong cell--number t-file__branch-coverage"><%= sprintf("%.2f", source_file.branches_coverage_percent.round(2)) %> %</td>
<td class="cell--number"><%= source_file.total_branches.count %></td>
<td class="cell--number"><%= source_file.covered_branches.count %></td>
<td class="cell--number"><%= source_file.missed_branches.count %></td>
<% end %>
</tr>
<% end %>
<%- source_files.each do |source_file| -%>
<tr class="t-file">
<td class="strong t-file__name"><%= link_to_source_file(source_file) %></td>
<td class="<%= coverage_css_class(source_file.covered_percent) %> strong cell--number t-file__coverage"><%= sprintf("%.2f", source_file.covered_percent.round(2)) %> %</td>
<td class="cell--number"><%= source_file.lines.count %></td>
<td class="cell--number"><%= source_file.covered_lines.count + source_file.missed_lines.count %></td>
<td class="cell--number"><%= source_file.covered_lines.count %></td>
<td class="cell--number"><%= source_file.missed_lines.count %></td>
<td class="cell--number"><%= sprintf("%.2f", source_file.covered_strength.round(2)) %></td>
<%- if branchable_result? -%>
<td class="<%= coverage_css_class(source_file.branches_coverage_percent) %> strong cell--number t-file__branch-coverage"><%= sprintf("%.2f", source_file.branches_coverage_percent.round(2)) %> %</td>
<td class="cell--number"><%= source_file.total_branches.count %></td>
<td class="cell--number"><%= source_file.covered_branches.count %></td>
<td class="cell--number"><%= source_file.missed_branches.count %></td>
<%- end -%>
</tr>
<%- end -%>
</tbody>
</table>
</div>
Expand Down
15 changes: 8 additions & 7 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

<div id="content">
<%= formatted_file_list("All Files", result.source_files) %>

<% result.groups.each do |name, files| %>
<%= formatted_file_list(name, files) %>
<% end %>
<%- result.groups.each do |name, files| -%>
<%= formatted_file_list(name, files) %>
<%- end -%>
</div>

<div id="footer">
Expand All @@ -31,9 +30,11 @@
</div>

<div class="source_files">
<% result.source_files.each do |source_file| %>
<%= formatted_source_file(source_file) %>
<% end %>
<%- result.source_files.each do |source_file| -%>
<template id="tmpl-<%= id(source_file) %>">
<%= formatted_source_file(source_file) %>
</template>
<%- end -%>
</div>
</div>
</body>
Expand Down
67 changes: 28 additions & 39 deletions views/source_file.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,42 @@
<%= covered_percent(source_file.covered_percent) %>
lines covered
</h4>

<% if branchable_result? %>
<h4>
<%= covered_percent(source_file.branches_coverage_percent) %>
branches covered
</h4>
<% end %>

<%- if branchable_result? -%>
<h4>
<%= covered_percent(source_file.branches_coverage_percent) %>
branches covered
</h4>
<%- end -%>
<div class="t-line-summary">
<b><%= source_file.lines_of_code %></b> relevant lines.
<span class="green"><b><%= source_file.covered_lines.count %></b> lines covered</span> and
<span class="red"><b><%= source_file.missed_lines.count %></b> lines missed.</span>
</div>

<% if branchable_result? %>
<div class="t-branch-summary">
<span><b><%= source_file.total_branches.count %></b> total branches, </span>
<span class="green"><b><%= source_file.covered_branches.count %></b> branches covered</span> and
<span class="red"><b><%= source_file.missed_branches.count %></b> branches missed.</span>
</div>
<% end %>

<%- if branchable_result? -%>
<div class="t-branch-summary">
<span><b><%= source_file.total_branches.count %></b> total branches, </span>
<span class="green"><b><%= source_file.covered_branches.count %></b> branches covered</span> and
<span class="red"><b><%= source_file.missed_branches.count %></b> branches missed.</span>
</div>
<%- end -%>
</div>

<pre>
<ol>
<% source_file.lines.each do |line| %>
<div>
<li class="<%= line_status?(source_file, line) %>" data-hits="<%= line.coverage ? line.coverage : '' %>" data-linenumber="<%= line.number %>">
<% if line.covered? %>
<span class="hits"><%= line.coverage %></span>
<% elsif line.skipped? %>
<span class="hits">skipped</span>
<% end %>

<% if branchable_result? %>
<% source_file.branches_for_line(line.number).each do |branch_type, hit_count| %>
<span class="hits" title="<%= branch_type%> branch hit <%= hit_count %> times">
<%= branch_type %>: <%= hit_count %>
</span>
<% end %>
<% end %>

<code class="ruby"><%= ERB::Util.html_escape(line.src.chomp) %></code>
</li>
</div>
<% end %>
<%- source_file.lines.each do |line| -%>
<li class="<%= line_status?(source_file, line) %>"<%= " data-hits=\"#{line.coverage}\"" if line.coverage %> data-linenumber="<%= line.number %>">
<%- if line.covered? -%>
<span class="hits"><%= line.coverage %></span>
<%- elsif line.skipped? -%>
<span class="hits">skipped</span>
<%- end -%>
<%- if branchable_result? -%>
<%- source_file.branches_for_line(line.number).each do |branch_type, hit_count| -%>
<span class="hits" title="<%= branch_type%> branch hit <%= hit_count %> times"><%= branch_type %>: <%= hit_count %></span>
<%- end -%>
<%- end -%>
<code class="ruby"><%= ERB::Util.html_escape(line.src.chomp) %></code>
</li>
<%- end -%>
</ol>
</pre>
</div>