class Risu::Base::Templater

Templater class for generating a report from a ERB template

Attributes

findings[RW]
output_file[RW]
template[RW]
template_manager[RW]

Public Class Methods

new(template, findings, output, template_manager) click to toggle source

Setups of the Templater class initializing all of the variables

@return [Templater] New Instance

# File lib/risu/base/templater.rb, line 32
def initialize template, findings, output, template_manager
        @template = template
        @findings = findings
        @output_file = output
        @template_manager = template_manager
end

Public Instance Methods

generate() click to toggle source

Generates a report based on the ERB template

# File lib/risu/base/templater.rb, line 40
def generate
        begin
                template = @template
                template_manager = @template_manager

                t = template_manager.find_template_by_name(template)
                t = t.class.new

                if t.template_info[:renderer] == "CSV"
                        Risu::Renderers::CSVRenderer.generate(@output_file) do |output|
                                t = template_manager.find_template_by_name(template)
                                t = t.class.new
                                t.output = output
                                t.render(output) unless t == nil
                        end
                elsif t.template_info[:renderer] == "PDF"
                        Prawn::Document.generate(@output_file, :margin => [75, 50, 75, 50]) do |output|
                                output.font_size 10
                                t = template_manager.find_template_by_name(template)
                                t = t.class.new
                                t.output = output
                                t.render(output) unless t == nil
                        end
                end
        rescue => e
                raise unless Rails.env.production?
                puts "Templater Error: #{e.message} \n #{e.backtrace.join("\n\t")}\n"
        end
end