import source from lvm2 2.02.79
[external/device-mapper.git] / report-generators / lib / report_templates.rb
1 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
2 #
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
6 #
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10
11 # Policy for the location of report templates
12 require 'string-store'
13
14 class TemplateStringStore < StringStore
15   def initialize()
16     super(['report-generators/templates'])
17   end
18 end
19
20 module ReportTemplates
21   def generate_report(report, bs, dest_path = nil)
22     include Reports
23     reports = ReportRegister.new
24     template_store = TemplateStringStore.new
25     report = reports.get_report(report)
26     erb = ERB.new(template_store.lookup(report.template))
27     body = erb.result(bs)
28     title = report.short_desc
29
30     erb = ERB.new(template_store.lookup("boiler_plate.rhtml"))
31     txt = erb.result(binding)
32
33     dest_path = dest_path.nil? ? report.path : dest_path
34     dest_path.open("w") do |out|
35       out.puts txt
36     end
37   end
38 end