提交 7624be20 编写于 作者: B Bart ten Brinke

Moved report stuff to the report directory

上级 15b23741
if CSV.const_defined? :Reader
# Ruby 1.8 compatible
require 'fastercsv'
Object.send(:remove_const, :CSV)
CSV = FasterCSV
else
# CSV is now FasterCSV in ruby 1.9
end
#This is so OkJson will work with symbol values
if mj_engine == :ok_json
class Symbol
def to_json
self.to_s.inspect
end
end
end
class Brakeman::Renderer
def initialize(template_file, hash = {})
hash[:locals] ||= {}
hash[:locals].each do |key, value|
singleton_class.send(:define_method, key) { value }
end
singleton_class.send(:define_method, 'template_file') { template_file }
singleton_class.send(:define_method, 'template') {
File.read(File.expand_path("templates/#{template_file}.html.erb", File.dirname(__FILE__)))
}
end
def render
ERB.new(template).result(binding)
end
end
......@@ -7,8 +7,8 @@ require 'highline/system_extensions'
require "csv"
require 'multi_json'
require 'brakeman/version'
require 'brakeman/renderer'
Dir[File.dirname(__FILE__) + 'initializers/*.rb'].each {|file| require file}
require 'brakeman/report/renderer'
Dir[File.dirname(__FILE__) + 'report/initializers/*.rb'].each {|file| require file}
#Generates a report based on the Tracker and the results of
#Tracker#run_checks. Be sure to +run_checks+ before generating
......@@ -18,6 +18,13 @@ class Brakeman::Report
attr_reader :tracker, :checks
# Ruby 1.8 compatible
if CSV.const_defined? :Reader
require 'fastercsv'
Object.send(:remove_const, :CSV)
CSV = FasterCSV
end
TEXT_CONFIDENCE = [ "High", "Medium", "Weak" ]
HTML_CONFIDENCE = [ "<span class='high-confidence'>High</span>",
"<span class='med-confidence'>Medium</span>",
......@@ -44,7 +51,7 @@ class Brakeman::Report
:number_of_templates => number_of_templates(@tracker),
}
Brakeman::Renderer.new('overview', :locals => locals).render
Brakeman::Report::Renderer.new('overview', :locals => locals).render
else
Terminal::Table.new(:headings => ['Scanned/Reported', 'Total']) do |t|
t.add_row ['Controllers', tracker.controllers.length]
......@@ -75,7 +82,7 @@ class Brakeman::Report
def render_array(template, headings, value_array, locals, html = false)
return if value_array.empty?
if html
Brakeman::Renderer.new(template, :locals => locals).render
Brakeman::Report::Renderer.new(template, :locals => locals).render
else
Terminal::Table.new(:headings => headings) do |t|
value_array.each { |value_row| t.add_row value_row }
......@@ -264,7 +271,7 @@ class Brakeman::Report
template_rows = template_rows.sort_by{|name, value| name.to_s}
if html
Brakeman::Renderer.new('template_overview', :locals => {:template_rows => template_rows}).render
Brakeman::Report::Renderer.new('template_overview', :locals => {:template_rows => template_rows}).render
else
output = ''
template_rows.each do |template|
......@@ -413,7 +420,7 @@ class Brakeman::Report
:brakeman_version => Brakeman::Version
}
Brakeman::Renderer.new('header', :locals => locals).render
Brakeman::Report::Renderer.new('header', :locals => locals).render
end
#Generate header for text output
......
#MultiJson interface changed in 1.3.0, but need
#to support older MultiJson for Rails 3.1.
mj_engine = nil
if MultiJson.respond_to? :default_adapter
mj_engine = MultiJson.default_adapter
else
......@@ -16,3 +18,12 @@ else
end
end
#This is so OkJson will work with symbol values
if mj_engine == :ok_json
class Symbol
def to_json
self.to_s.inspect
end
end
end
class Brakeman::Report
class Renderer
def initialize(template_file, hash = {})
hash[:locals] ||= {}
hash[:locals].each do |key, value|
singleton_class.send(:define_method, key) { value }
end
singleton_class.send(:define_method, 'template_file') { template_file }
singleton_class.send(:define_method, 'template') {
File.read(File.expand_path("templates/#{template_file}.html.erb", File.dirname(__FILE__)))
}
end
def render
ERB.new(template).result(binding)
end
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册