20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/blinkr/report.rb', line 20
def render
@context.total = 0
@context.severity = {}
@context.category = {}
@context.type = {}
@context.pages.each do |url, page|
page.url = url
page.max_severity = ::Blinkr::SEVERITY.first page.severities = []
page.categories = []
page.types = []
page.errors.each do |error|
raise "#{error.severity} not a valid severity. Must be one of #{::Blinkr::SEVERITY.join(',')}" unless ::Blinkr::SEVERITY.include? error.severity
raise "#{error.category} must be specified." if error.category.nil?
@context.total += 1
@context.severity[error.severity] ||= OpenStruct.new({:count => 0})
@context.severity[error.severity].count += 1
page.severities << error.severity
page.max_severity = error.severity if ::Blinkr::SEVERITY.index(error.severity) > ::Blinkr::SEVERITY.index(page.max_severity)
@context.category[error.category] ||= OpenStruct.new({:count => 0})
@context.category[error.category].count += 1
page.categories << error.category
@context.type[error.type] ||= OpenStruct.new({:count => 0})
@context.type[error.type].count += 1
page.types << error.type
end
page.severities.uniq!
page.categories.uniq!
page.types.uniq!
end
@context.pages = @context.pages.values
File.open(@config.report, 'w') do |file|
file.write(Slim::Template.new(TMPL).render(OpenStruct.new({:blinkr => @context, :engine => @engine,
:errors => @context.to_json})))
end
puts "Wrote report to #{@config.report}" if @config.verbose
end
|