class RoutesCoverage::Formatters::Html
Public Instance Methods
format()
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 10 def format routes_filename = "routes.html" File.open(File.join(output_path, routes_filename), "wb") do |file| file.puts template("layout").result(binding) end "Routes coverage is #{result.coverage}% Report generated to #{output_path}/#{routes_filename}" end
Private Instance Methods
all_result_groups()
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 95 def all_result_groups return @all_result_groups if @all_result_groups @all_result_groups = [ { id: 'all_routes', name: 'All Routes', result: result, } ] @all_result_groups += groups.map do |group_name, group_result| { id: group_name.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, ""), name: group_name, result: group_result, } end @all_result_groups end
asset_content(name)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 54 def asset_content name File.read(File.expand_path("../../../compiled_assets/#{name}", File.dirname(__FILE__))) end
coverage_css_class(covered_percent)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 66 def coverage_css_class(covered_percent) if covered_percent > 90 "green" elsif covered_percent > 80 "yellow" else "red" end end
coverage_dir(dir = nil)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 34 def coverage_dir(dir = nil) #TODO: config for this return SimpleCov.coverage_dir if defined? SimpleCov return @coverage_dir if defined?(@coverage_dir) && dir.nil? @coverage_path = nil # invalidate cache @coverage_dir = (dir || "coverage") end
hits_css_class(hits)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 86 def hits_css_class hits hits > 0 ? 'cov' : 'uncov' end
output_path()
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 42 def output_path @coverage_path ||= File.expand_path(coverage_dir, root).tap do |path| FileUtils.mkdir_p path end end
project_name()
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 48 def project_name return SimpleCov.project_name if defined? SimpleCov @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ") end
root(root = nil)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 27 def root(root = nil) #TODO: config for this return SimpleCov.root if defined? SimpleCov return @root if defined?(@root) && root.nil? @root = File.expand_path(root || Dir.getwd) end
route_group_result(title_id, title, result)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 62 def route_group_result(title_id, title, result) template("route_group").result(binding) end
strength_css_class(covered_strength)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 76 def strength_css_class(covered_strength) if covered_strength > 1 "green" elsif covered_strength == 1 "yellow" else "red" end end
style_asset_link()
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 58 def style_asset_link "<style>\n#{asset_content 'routes.css'}</style>" end
template(name)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 22 def template(name) ERB.new(File.read(File.join(File.dirname(__FILE__), "html_views", "#{name}.erb"))) end
timeago(time)
click to toggle source
# File lib/routes_coverage/formatters/html.rb, line 90 def timeago(time) "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>" end