Class: Brakeman::Report::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/brakeman/report/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_file, hash = {}) ⇒ Renderer

Returns a new instance of Renderer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/brakeman/report/renderer.rb', line 5

def initialize(template_file, hash = {})
  hash[:locals] ||= {}
  singleton = class << self; self end

  hash[:locals].each do |attribute_name, attribute_value|
    singleton.send(:define_method, attribute_name) { attribute_value }
  end

  # There are last, so as to make overwriting these using locals impossible.
  singleton.send(:define_method, 'template_file') { template_file }
  singleton.send(:define_method, 'template') {
    File.read(File.expand_path("templates/#{template_file}.html.erb", File.dirname(__FILE__)))
  }
end

Instance Method Details

#renderObject



20
21
22
# File 'lib/brakeman/report/renderer.rb', line 20

def render
  ERB.new(template).result(binding)
end