Added Canvas 1.1.0, originally not under SCM so no historical development records...
[canvas.git] / scripts / generator / base.rb
blob6ec4118c0a1764ad398a16b9123f33a42855cf69
1 class Generator
2   def initialize(arguments)
3     @args = arguments
4   end
5   
6   # generate and write template
7   def generate template, file
8     if file.kind_of? String then # one file
9       write_template(file, ERB.new(load_template(template)).result(binding))
10     else # multiple files
11       file.each do |f|
12         write_template(f, ERB.new(load_template(template)).result(binding))
13       end
14     end
15   end
16   
17   # load template
18   def load_template(template)
19     file = File.dirname(__FILE__) + '/templates/' + template + '.rhtml'
20     return IO.readlines(file).join if File.file? file
21   end
22   
23   # write template
24   def write_template(file, template)
25     f = File.new(file, File::CREAT|File::RDWR, 0755)
26     f << template
27     f.close
28   end
29 end