diff --git a/lib/rcov.rb b/lib/rcov.rb index 99b7be8..d726601 100644 --- a/lib/rcov.rb +++ b/lib/rcov.rb @@ -1006,6 +1006,4 @@ def compute_raw_data_difference(first, last) end -end # Rcov - -# vi: set sw=2: +end \ No newline at end of file diff --git a/lib/rcov/formatters.rb b/lib/rcov/formatters.rb index a67f974..55f969d 100644 --- a/lib/rcov/formatters.rb +++ b/lib/rcov/formatters.rb @@ -1,3 +1,4 @@ +require 'rcov/formatters/html_erb_template' require 'rcov/formatters/base_formatter' require 'rcov/formatters/text_summary' require 'rcov/formatters/text_report' diff --git a/lib/rcov/formatters/base_formatter.rb b/lib/rcov/formatters/base_formatter.rb index c5af1fb..3ed0677 100644 --- a/lib/rcov/formatters/base_formatter.rb +++ b/lib/rcov/formatters/base_formatter.rb @@ -1,127 +1,3 @@ -require "erb" - -class Document - - attr_accessor :local_variables - - def initialize(template_file, locals={}) - 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 - - def render - @template.result(get_binding) - end - - def relative_filename(path) - @path_relativizer[path] - end - - #def create_cross_refs(filename, lineno, linetext) - #form = formatter - #return linetext unless @callsite_analyzer && @do_callsites - - #ref_blocks = [] - #form.send(:_get_defsites, ref_blocks, filename, lineno, "Calls", linetext) do |ref| - #if ref.file - #where = "at #{formatter.normalize_filename(ref.file)}:#{ref.line}" - #else - #where = "(C extension/core)" - #end - #CGI.escapeHTML("%7d %s" % [ref.count, "#{ref.klass}##{ref.mid} " + where]) - #end - - #form.send(:_get_callsites, ref_blocks, filename, lineno, "Called by", linetext) do |ref| - #r = "%7d %s" % [ref.count, "#{formatter.normalize_filename(ref.file||'C code')}:#{ref.line} " + "in '#{ref.klass}##{ref.mid}'"] - #CGI.escapeHTML(r) - #end - - #create_cross_reference_block(linetext, ref_blocks) - #end - - #def create_cross_reference_block(linetext, ref_blocks) - #return linetext if ref_blocks.empty? - #ret = "" - #@cross_ref_idx ||= 0 - #@known_files ||= formatter.sorted_file_pairs.map{|fname, finfo| formatter.normalize_filename(fname)} - #ret << %[#{linetext}] - #ret << %[] - #ret << "\n" - #ref_blocks.each do |refs, toplabel, label_proc| - #unless !toplabel || toplabel.empty? - #ret << %!#{toplabel}\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 << %[#{label}] - #else - #ret << label - #end - #ret << "\n" - #end - #end - #ret << "" - #end - - def line_css(line_number) - case file.coverage[line_number] - when true - "marked" - when :inferred - "inferred" - else - "uncovered" - end - end - - - #def format_lines(file) - #result = "" - #last = nil - #end_of_span = "" - #format_line = "%#{file.num_lines.to_s.size}d" - #file.num_lines.times do |i| - #line = file.lines[i].chomp - #marked = file.coverage[i] - #count = file.counts[i] - #spanclass = span_class(file, marked, count) - #if spanclass != last - #result += end_of_span - #case spanclass - #when nil - #end_of_span = "" - #else - #result += %[] - #end_of_span = "" - #end - #end - #result += %[] + (format_line % (i+1)) + - #" " + create_cross_refs(file.name, i+1, CGI.escapeHTML(line)) + "\n" - #last = spanclass - #end - #result += end_of_span - #"
#{result}
" - #end - - - def method_missing(key, *args) - local_variables.has_key?(key) ? local_variables[key] : super - end - - def get_binding - binding - end - -end - module Rcov class BaseFormatter # :nodoc: diff --git a/lib/rcov/formatters/html_coverage.rb b/lib/rcov/formatters/html_coverage.rb index 2fe448b..66d938e 100644 --- a/lib/rcov/formatters/html_coverage.rb +++ b/lib/rcov/formatters/html_coverage.rb @@ -72,8 +72,7 @@ def name def create_index(destname) files = [SummaryFileInfo.new(self)] + each_file_pair_sorted.map{|k,v| v} - - doc = Document.new('index.html.erb', :title => 'C0 Coverage Information - RCov', + doc = Rcov::Formatters::HtmlErbTemplate.new('index.html.erb', :title => 'C0 Coverage Information - RCov', :generated_on => Time.now, :rcov => Rcov, :formatter => self, @@ -85,7 +84,7 @@ def create_index(destname) def create_file(destfile, fileinfo) - doc = Document.new('detail.html.erb', :title => fileinfo.name, + doc = Rcov::Formatters::HtmlErbTemplate.new('detail.html.erb', :title => fileinfo.name, :generated_on => Time.now, :rcov => Rcov, :formatter => self, diff --git a/lib/rcov/formatters/ruby_annotation.rb b/lib/rcov/formatters/ruby_annotation.rb index b59a42d..5bee444 100644 --- a/lib/rcov/formatters/ruby_annotation.rb +++ b/lib/rcov/formatters/ruby_annotation.rb @@ -10,7 +10,6 @@ def initialize(opts = {}) @dest = options[:destdir] @do_callsites = true @do_cross_references = true - @mangle_filename = Hash.new{|h,base| h[base] = Pathname.new(base).cleanpath.to_s.gsub(%r{^\w:[/\\]}, "").gsub(/\./, "_").gsub(/[\\\/]/, "-") + ".rb" } diff --git a/lib/rcov/report.rb b/lib/rcov/report.rb deleted file mode 100644 index 6c03f50..0000000 --- a/lib/rcov/report.rb +++ /dev/null @@ -1,8 +0,0 @@ -# rcov Copyright (c) 2004-2006 Mauricio Fernandez -# See LEGAL and LICENSE for additional licensing information. - -require 'pathname' - -module Rcov - -end diff --git a/lib/rcov/templates/detail.html.erb b/lib/rcov/templates/detail.html.erb index 6431f70..6f47961 100644 --- a/lib/rcov/templates/detail.html.erb +++ b/lib/rcov/templates/detail.html.erb @@ -3,31 +3,7 @@ <%= title %> - +

<%= title %>

diff --git a/lib/rcov/templates/index.html.erb b/lib/rcov/templates/index.html.erb index 331de0e..bd460bf 100644 --- a/lib/rcov/templates/index.html.erb +++ b/lib/rcov/templates/index.html.erb @@ -3,31 +3,7 @@ <%= title %> - +

<%= title %>

diff --git a/lib/rcov/templates/rcov.js b/lib/rcov/templates/rcov.js new file mode 100644 index 0000000..bff44fd --- /dev/null +++ b/lib/rcov/templates/rcov.js @@ -0,0 +1,21 @@ +function toggleCode( id ) { + if ( document.getElementById ) + elem = document.getElementById( id ); + else if ( document.all ) + elem = eval( "document.all." + id ); + else + return false; + + elemStyle = elem.style; + + if ( elemStyle.display != "block" ) { + elemStyle.display = "block" + } else { + elemStyle.display = "none" + } + + return true; +} + +// Make cross-references hidden by default +document.writeln( "" ) \ No newline at end of file