Class: SimpleCov::Formatter::HTMLFormatter
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
ViewHelpers,
CoverageHelpers
|
|
| Inherits: | Object |
| Defined in: | lib/simplecov/formatter/html_formatter.rb, lib/simplecov/formatter/html_formatter/coverage_helpers.rb, lib/simplecov/formatter/html_formatter/view_helpers.rb |
Overview
Generates an HTML coverage report from ::SimpleCov results.
Constant Summary
-
CONTENT_TYPES =
# File 'lib/simplecov/formatter/html_formatter.rb', line 15
Only have a few content types, just hardcode them
{ ".js" => "text/javascript", ".png" => "image/png", ".gif" => "image/gif", ".css" => "text/css" }.freeze -
VERSION =
# File 'lib/simplecov/formatter/html_formatter.rb', line 12"0.13.2"
Class Method Summary
Instance Attribute Summary
- #branch_coverage? ⇒ Boolean readonly private
- #method_coverage? ⇒ Boolean readonly private
Instance Method Summary
- #format(result)
- #asset_inline(name) private
- #asset_output_path private
- #assets_path(name) private
- #formatted_file_list(title, source_files) private
- #formatted_source_file(source_file) private
- #output_message(result) private
- #output_path private
- #render_stats(result, criterion) private
- #template(name) private
ViewHelpers - Included
| #coverage_css_class, #covered_percent, #fmt, #id, #line_status?, #link_to_source_file, #missed_method_line_set, #missed_method_lines, #shortened_filename, #timeago, #to_id |
CoverageHelpers - Included
Constructor Details
.new(silent: false, inline_assets: false) ⇒ HTMLFormatter
# File 'lib/simplecov/formatter/html_formatter.rb', line 24
def initialize(silent: false, inline_assets: false) @branch_coverage = SimpleCov.branch_coverage? @method_coverage = SimpleCov.method_coverage? @templates = {} @inline_assets = inline_assets || ENV.key?("SIMPLECOV_INLINE_ASSETS") @public_assets_dir = File.join(__dir__, "html_formatter/public/") @silent = silent end
Instance Attribute Details
#branch_coverage? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/simplecov/formatter/html_formatter.rb', line 46
def branch_coverage? @branch_coverage end
#method_coverage? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/simplecov/formatter/html_formatter.rb', line 50
def method_coverage? @method_coverage end
Instance Method Details
#asset_inline(name) (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 82
def asset_inline(name) path = File.join(@public_assets_dir, name) base64_content = [File.read(path)].pack("m0") "data:#{CONTENT_TYPES.fetch(File.extname(name))};base64,#{base64_content}" end
#asset_output_path (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 70
def asset_output_path @asset_output_path ||= File.join(output_path, "assets", VERSION).tap do |path| FileUtils.mkdir_p(path) end end
#assets_path(name) (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 76
def assets_path(name) return asset_inline(name) if @inline_assets File.join("./assets", VERSION, name) end
#format(result)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 33
def format(result) unless @inline_assets Dir[File.join(@public_assets_dir, "*")].each do |path| FileUtils.cp_r(path, asset_output_path, remove_destination: true) end end File.write(File.join(output_path, "index.html"), template("layout").result(binding), mode: "wb") puts (result) unless @silent end
#formatted_file_list(title, source_files) (private)
[ GitHub ]#formatted_source_file(source_file) (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 88
def formatted_source_file(source_file) template("source_file").result(binding) rescue Encoding::CompatibilityError => e puts "Encoding problems with file #{source_file.filename}. Simplecov/ERB can't handle non ASCII characters in filenames. Error: #{e.}." %(<div class="source_table" id="#{id(source_file)}"><div class="header"><h2>Encoding Error</h2><p>#{ERB::Util.html_escape(e.)}</p></div></div>) end
#output_message(result) (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 54
def (result) lines = ["Coverage report generated for #{result.command_name} to #{output_path}"] lines << "Line coverage: #{render_stats(result, :line)}" lines << "Branch coverage: #{render_stats(result, :branch)}" if branch_coverage? lines << "Method coverage: #{render_stats(result, :method)}" if method_coverage? lines.join("\n") end
#output_path (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 66
def output_path SimpleCov.coverage_path end
#render_stats(result, criterion) (private)
[ GitHub ]#template(name) (private)
[ GitHub ]# File 'lib/simplecov/formatter/html_formatter.rb', line 62
def template(name) @templates[name] ||= ERB.new(File.read(File.join(__dir__, "html_formatter/views/", "#{name}.erb")), trim_mode: "-") end