Class: Rcov::Formatters::HtmlErbTemplate

Inherits:
Object
  • Object
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.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rcov/formatters/html_erb_template.rb', line 7

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|
    # TODO: Waaaahhhhh?
    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



117
118
119
# File 'lib/rcov/formatters/html_erb_template.rb', line 117

def method_missing(key, *args)
  local_variables.has_key?(key) ? local_variables[key] : super
end

Instance Attribute Details

#local_variablesObject

Returns the value of attribute local_variables.



5
6
7
# File 'lib/rcov/formatters/html_erb_template.rb', line 5

def local_variables
  @local_variables
end

Instance Method Details

#get_bindingObject



121
122
123
# File 'lib/rcov/formatters/html_erb_template.rb', line 121

def get_binding
  binding 
end

#line_css(line_number) ⇒ Object

def create_cross_reference_block(linetext, ref_blocks) return linetext if ref_blocks.empty? ret = “” ret << %[<a class=“crossref-toggle” href=“#” onclick=“toggleCode(‘XREF-#@cross_ref_idx+=1’); return false;”>#linetext</a>] ret << %[<span class=“cross-ref” id=“XREF-#@cross_ref_idx”>] ret << “n” ref_blocks.each do |refs, toplabel, label_proc| unless !toplabel || toplabel.empty? ret << %!<span class=“cross-ref-title”>#toplabel</span>n! end refs.each do |dst| dstfile = formatter.normalize_filename(dst.file) if dst.file dstline = dst.line label = label_proc.call(dst) if dst.file && @known_files.include?(dstfile) ret << %[<a href=“#Rcov::Formatters::HtmlErbTemplate.formatterformatter.mangle_filename(dstfile)#line#dstline”>#label</a>] else ret << label end ret << “n” end end ret << “</span>” end



76
77
78
79
80
81
82
83
84
85
# File 'lib/rcov/formatters/html_erb_template.rb', line 76

def line_css(line_number)
  case fileinfo.coverage[line_number]
  when true
    "marked"
  when :inferred
    "inferred"
  else
    "uncovered"
  end
end

#relative_filename(path) ⇒ Object



23
24
25
# File 'lib/rcov/formatters/html_erb_template.rb', line 23

def relative_filename(path)
  @path_relativizer[path]
end

#renderObject



19
20
21
# File 'lib/rcov/formatters/html_erb_template.rb', line 19

def render
  @template.result(get_binding)
end