class CodeWeb::HtmlReport

Constants

TEMPLATE

Attributes

arg_regex[RW]
base_url[RW]
class_map[RW]

@!attribute :class_map [rw]

map from regex to class name
if the filename that has the method matches the regex, the classname
  will get assigned to the link (to emphasize certain files/directories)
@return [Map<Regexp,color>] regex expressing name of main file
method_calls[RW]

@!attribute :method_calls [r]

list of all the method_Calls
@return [Array<MethodCall>]
url_and_file[RW]

Public Class Methods

new(method_calls, class_map={}, arg_regex=nil, out=STDOUT, options = {}) click to toggle source
# File lib/code_web/html_report.rb, line 22
def initialize(method_calls, class_map={}, arg_regex=nil, out=STDOUT, options = {})
  @method_calls = method_calls
  @class_map = class_map
  @arg_regex = arg_regex
  @base_url = options[:base_url]
  @url_and_file = options[:url_and_file]
  @out = out
end

Public Instance Methods

arg_regex?() click to toggle source
# File lib/code_web/html_report.rb, line 13
def arg_regex? ; ! arg_regex.nil? ; end
methods_by_name() click to toggle source

helpers

# File lib/code_web/html_report.rb, line 136
def methods_by_name
  MethodList.group_by(method_calls, :short_method_name)
end
report() click to toggle source
# File lib/code_web/html_report.rb, line 124
def report
  template = ERB.new(TEMPLATE, nil, "-")
  @out.puts template.result(binding)
rescue => e
  e.backtrace.detect { |l| l =~ /\(erb\):([0-9]+)/ }
  line_no=$1.to_i
  raise RuntimeError, "error in #{__FILE__}:#{line_no+28} #{e}\n\n #{TEMPLATE.split(/\n/)[line_no-1]}\n\n ",
    e.backtrace
end

Private Instance Methods

all_hash_names(collection) click to toggle source

@param collection [Array<Method>] methods (with a hash first argument) @return [Array<String>] list of all keys for all hashes

# File lib/code_web/html_report.rb, line 169
def all_hash_names(collection)
  collection.inject(Set.new) {|acc, m| m.arg_keys.each {|k| acc << k} ; acc}.sort_by {|n| n}
end
class_for_filename(filename) click to toggle source
# File lib/code_web/html_report.rb, line 191
def class_for_filename(filename)
  class_map.each_with_index do |(pattern, color), i|
    return "f#{i}" if filename =~ pattern
  end
  nil
end
html_safe(str) click to toggle source
# File lib/code_web/html_report.rb, line 163
def html_safe(str)
  str.to_s.gsub('"','&quot;')
end
maybe_simplified_argument(hash, arg) click to toggle source
# File lib/code_web/html_report.rb, line 142
def maybe_simplified_argument(hash, arg)
  simplified_argument(hash[arg]) if hash.key?(arg)
end
pwd() click to toggle source
# File lib/code_web/html_report.rb, line 206
def pwd
  @pwd ||= `pwd`.chomp
end
simplified_argument(arg) click to toggle source

shorten the argument

# File lib/code_web/html_report.rb, line 147
def simplified_argument(arg)
  short_arg = case arg
  when nil
    "nil"
  when String
    arg.split("::").last[0..12]
  else
    arg.to_s[0..12]
  end
  if short_arg == arg || short_arg == "nil"
    short_arg
  else
    %{<span title="#{html_safe(arg)}">#{short_arg}</span>}
  end
end
url_for_filename(filename, line, force_filename = false) click to toggle source
# File lib/code_web/html_report.rb, line 198
def url_for_filename(filename, line, force_filename = false)
  if !force_filename && base_url
    "#{filename.gsub(pwd, base_url)}#L#{line}"
  else
    "subl://open?url=file://#{filename}&amp;line=#{line}"
  end
end