class Coverband::Utils::HTMLFormatter
Attributes
base_path[R]
notice[R]
Public Class Methods
new(report, options = {})
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 18 def initialize(report, options = {}) @notice = options.fetch(:notice) { nil } @base_path = options.fetch(:base_path) { "./" } @coverage_result = Coverband::Utils::Results.new(report) if report end
Public Instance Methods
format_dynamic_data!()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 28 def format_dynamic_data! format_data(@coverage_result) end
format_dynamic_html!()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 24 def format_dynamic_html! format_html(@coverage_result) end
format_settings!()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 32 def format_settings! format_settings end
format_source_file!(filename)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 40 def format_source_file!(filename) source_file = @coverage_result.file_from_path_with_type(filename) if source_file formatted_source_file(@coverage_result, source_file) else "File No Longer Available" end end
format_view_tracker!()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 36 def format_view_tracker! format_view_tracker end
Private Instance Methods
asset_output_path()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 87 def asset_output_path return @asset_output_path if defined?(@asset_output_path) && @asset_output_path @asset_output_path = File.join(output_path) FileUtils.mkdir_p(@asset_output_path) @asset_output_path end
assets_path(name)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 99 def assets_path(name) File.join(base_path, name) end
coverage_css_class(covered_percent)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 141 def coverage_css_class(covered_percent) if covered_percent.nil? "" elsif covered_percent > 90 "green" elsif covered_percent > 80 "yellow" else "red" end end
format(result)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 60 def format(result) Dir[File.join(File.dirname(__FILE__), "../../../public/*")].each do |path| FileUtils.cp_r(path, asset_output_path) end File.open(File.join(output_path, "index.html"), "wb") do |file| file.puts template("layout").result(binding) end end
format_data(result)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 74 def format_data(result) template("data").result(binding) end
format_html(result)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 70 def format_html(result) template("layout").result(binding) end
format_settings()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 52 def format_settings template("settings").result(binding) end
format_view_tracker()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 56 def format_view_tracker template("view_tracker").result(binding) end
formatted_file_list(title, result, source_files, options = {})
click to toggle source
Returns a table containing the given source files
# File lib/coverband/utils/html_formatter.rb, line 130 def formatted_file_list(title, result, source_files, options = {}) title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "") # Silence a warning by using the following variable to assign to itself: # "warning: possibly useless use of a variable in void context" # The variable is used by ERB via binding. title_id = title_id options = options template("file_list").result(binding) end
formatted_source_file(result, source_file)
click to toggle source
Returns the html for the given source_file
# File lib/coverband/utils/html_formatter.rb, line 116 def formatted_source_file(result, source_file) template("source_file").result(binding) rescue Encoding::CompatibilityError => e puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}." end
formatted_source_file_loader(result, source_file)
click to toggle source
Returns the html to ajax load a given source_file
# File lib/coverband/utils/html_formatter.rb, line 123 def formatted_source_file_loader(result, source_file) template("source_file_loader").result(binding) rescue Encoding::CompatibilityError => e puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}." end
id(source_file)
click to toggle source
Return a (kind of) unique id for the source file given. Uses SHA1 on path for the id
# File lib/coverband/utils/html_formatter.rb, line 164 def id(source_file) Digest::SHA1.hexdigest(source_file.filename) end
link_to_source_file(source_file)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 180 def link_to_source_file(source_file) %(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}">#{shortened_filename source_file}</a>) end
output_path()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 83 def output_path "#{File.expand_path(Coverband.configuration.root)}/coverage" end
served_html?()
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 95 def served_html? true end
shortened_filename(source_file)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 176 def shortened_filename(source_file) source_file.short_name end
strength_css_class(covered_strength)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 153 def strength_css_class(covered_strength) if covered_strength > 1 "green" elsif covered_strength == 1 "yellow" else "red" end end
template(name)
click to toggle source
Returns the an erb instance for the template of given name
# File lib/coverband/utils/html_formatter.rb, line 79 def template(name) ERB.new(File.read(File.join(File.dirname(__FILE__), "../../../views/", "#{name}.erb"))) end
timeago(time)
click to toggle source
# File lib/coverband/utils/html_formatter.rb, line 168 def timeago(time) if time "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>" else "Not Available" end end