Class: Rcov::Formatters::HtmlErbTemplate
- Inherits:
-
Object
- Object
- Rcov::Formatters::HtmlErbTemplate
show all
- Defined in:
- lib/rcov/formatters/html_erb_template.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(template_file, locals = {}) ⇒ HtmlErbTemplate
Returns a new instance of HtmlErbTemplate.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 6
def initialize(template_file, locals={})
require "erb"
template_path = File.expand_path("#{File.dirname(__FILE__)}/../templates/#{template_file}")
@template = ERB.new(File.read(template_path))
@local_variables = locals
@path_relativizer = Hash.new{|h,base|
h[base] = Pathname.new(base).cleanpath.to_s.gsub(%r{^\w:[/\\]}, "").gsub(/\./, "_").gsub(/[\\\/]/, "-") + ".html"
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args) ⇒ Object
53
54
55
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 53
def method_missing(key, *args)
local_variables.has_key?(key) ? local_variables[key] : super
end
|
Instance Attribute Details
#local_variables ⇒ Object
Returns the value of attribute local_variables.
4
5
6
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 4
def local_variables
@local_variables
end
|
Instance Method Details
#code_coverage_html(code_coverage_percentage, is_total = false) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 26
def code_coverage_html(code_coverage_percentage, is_total=false)
%{<div class="percent_graph_legend"><tt class='#{ is_total ? 'coverage_total' : ''}'>#{ "%3.2f" % code_coverage_percentage }%</tt></div>
<div class="percent_graph">
<div class="covered" style="width:#{ code_coverage_percentage.round }px"></div>
<div class="uncovered" style="width:#{ 100 - code_coverage_percentage.round }px"></div>
</div>}
end
|
#coverage_threshold_classes(percentage) ⇒ Object
21
22
23
24
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 21
def coverage_threshold_classes(percentage)
return 110 if percentage == 100
return (1..10).find_all{|i| i * 10 > percentage}.map{|i| i.to_i * 10} * " "
end
|
#file_filter_classes(file_path) ⇒ Object
34
35
36
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 34
def file_filter_classes(file_path)
file_path.split('/')[0..-2] * " "
end
|
#get_binding ⇒ Object
57
58
59
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 57
def get_binding
binding
end
|
#line_css(line_number) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 42
def line_css(line_number)
case fileinfo.coverage[line_number]
when true
"marked"
when :inferred
"inferred"
else
"uncovered"
end
end
|
#relative_filename(path) ⇒ Object
38
39
40
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 38
def relative_filename(path)
@path_relativizer[path]
end
|
#render ⇒ Object
17
18
19
|
# File 'lib/rcov/formatters/html_erb_template.rb', line 17
def render
@template.result(get_binding)
end
|