class Railroader::Report::Renderer

Public Class Methods

new(template_file, hash = {}) click to toggle source
# File lib/railroader/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

Public Instance Methods

render() click to toggle source
# File lib/railroader/report/renderer.rb, line 20
def render
  ERB.new(template).result(binding)
end