Class: CodeWeb::HtmlReport
- Inherits:
-
Object
- Object
- CodeWeb::HtmlReport
- Defined in:
- lib/code_web/html_report.rb
Constant Summary collapse
- TEMPLATE =
%{<html> <head><style> table {border-collapse:collapse;} table, td, th { border:1px solid black; } <%- @class_map.each_with_index do |(pattern, color), i| -%> .f<%=i%>, a.f<%=i%> { color: <%=color%>; } <%- end -%> </style> </head> <body> <%- methods_by_name.each do |methods| -%> <h2><%=methods.name%></h2> <%- methods.group_by(:hash_args?).each do |methods_with_hash| -%> <%- if methods_with_hash.hash_args? -%> <%- methods_with_hash.group_by(:method_types).each do |methods_with_type| -%> <%- display_yield_column = methods_with_type.detect(&:yields?) -%> <table> <thead><tr> <%- methods_with_type.arg_keys.each do |arg| -%> <td><%=arg%></td> <%- end -%> <%- if display_yield_column -%> <td>yield?</td> <%- end -%> <td>ref</td> <%- if base_url -%> <td>file ref</td> <%- end -%> </tr></thead> <tbody> <%- methods_with_type.group_by(:signature, arg_regex).each do |methods_by_signature| -%> <tr> <%- methods_with_type.arg_keys.each do |arg| -%> <td><%= maybe_simplified_argument(methods_by_signature.hash_arg, arg) %></td> <%- end -%> <%- if display_yield_column -%> <td><%= methods_by_signature.f.yields? %></td> <%- end -%> <td> <%- method_links(methods_by_signature).each do |link| -%> <%= link %> <%- end -%> </td> <%- if base_url -%> <td> <%- method_links(methods_by_signature, true).each do |link| -%> <%= link %> <%- end -%> </td> <%- end -%> </tr> <%- end -%> </tbody> </table> <%- end -%> <%- else -%> <table> <tbody> <%- methods_with_hash.group_by(:method_types).each do |methods_with_type| -%> <%- display_yield_column = methods_with_type.detect(&:yields?) -%> <%- methods_with_type.group_by(:signature, nil, :small_signature).each do |methods_by_signature| -%> <tr> <%- methods_by_signature.f.args.each do |arg| -%> <td><%= arg.inspect %></td> <%- end -%> <%- if display_yield_column -%> <td><%= methods_by_signature.f.yields? ? 'yields' : 'no yield'%></td> <%- end -%> <td> <%- method_links(methods_by_signature).each do |link| -%> <%= link %> <%- end -%> </td> <%- if base_url && url_and_file -%> <td> <%- method_links(methods_by_signature, true).each do |link| -%> <%= link %> <%- end -%> </td> <%- end -%> </tr> <%- end -%> <%- end -%> </tbody> </table> <%- end -%> <%- end -%> <%- end -%> </body> </html> }
Instance Attribute Summary collapse
-
#:class_map(: class_map) ⇒ Map<Regexp,color>
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).
-
#:method_calls(: method_calls) ⇒ Array<MethodCall>
readonly
list of all the method_Calls.
-
#arg_regex ⇒ Object
Returns the value of attribute arg_regex.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#class_map ⇒ Object
Returns the value of attribute class_map.
-
#method_calls ⇒ Object
Returns the value of attribute method_calls.
-
#url_and_file ⇒ Object
Returns the value of attribute url_and_file.
Instance Method Summary collapse
- #arg_regex? ⇒ Boolean
-
#initialize(method_calls, class_map = {}, arg_regex = nil, out = STDOUT, options = {}) ⇒ HtmlReport
constructor
A new instance of HtmlReport.
-
#methods_by_name ⇒ Object
helpers.
- #report ⇒ Object
Constructor Details
#initialize(method_calls, class_map = {}, arg_regex = nil, out = STDOUT, options = {}) ⇒ HtmlReport
Returns a new instance of HtmlReport.
22 23 24 25 26 27 28 29 |
# File 'lib/code_web/html_report.rb', line 22 def initialize(method_calls, class_map={}, arg_regex=nil, out=STDOUT, = {}) @method_calls = method_calls @class_map = class_map @arg_regex = arg_regex @base_url = [:base_url] @url_and_file = [:url_and_file] @out = out end |
Instance Attribute Details
#:class_map(: class_map) ⇒ Map<Regexp,color>
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)
20 |
# File 'lib/code_web/html_report.rb', line 20 attr_accessor :class_map |
#:method_calls(: method_calls) ⇒ Array<MethodCall> (readonly)
list of all the method_Calls
9 |
# File 'lib/code_web/html_report.rb', line 9 attr_accessor :method_calls |
#arg_regex ⇒ Object
Returns the value of attribute arg_regex.
10 11 12 |
# File 'lib/code_web/html_report.rb', line 10 def arg_regex @arg_regex end |
#base_url ⇒ Object
Returns the value of attribute base_url.
11 12 13 |
# File 'lib/code_web/html_report.rb', line 11 def base_url @base_url end |
#class_map ⇒ Object
Returns the value of attribute class_map.
20 21 22 |
# File 'lib/code_web/html_report.rb', line 20 def class_map @class_map end |
#method_calls ⇒ Object
Returns the value of attribute method_calls.
9 10 11 |
# File 'lib/code_web/html_report.rb', line 9 def method_calls @method_calls end |
#url_and_file ⇒ Object
Returns the value of attribute url_and_file.
12 13 14 |
# File 'lib/code_web/html_report.rb', line 12 def url_and_file @url_and_file end |
Instance Method Details
#arg_regex? ⇒ Boolean
13 |
# File 'lib/code_web/html_report.rb', line 13 def arg_regex? ; ! arg_regex.nil? ; end |
#methods_by_name ⇒ Object
helpers
136 137 138 |
# File 'lib/code_web/html_report.rb', line 136 def methods_by_name MethodList.group_by(method_calls, :short_method_name) end |
#report ⇒ Object
124 125 126 127 128 129 130 131 132 |
# 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 |