helm/rake/lib/deploy.rb

27 lines
705 B
Ruby
Raw Normal View History

2014-08-30 23:50:03 -07:00
class Project
2014-08-30 23:50:03 -07:00
template_folder = "templates"
2014-08-30 23:50:03 -07:00
def dirs(dirs=[])
dirs.each do |d|
mkdir_p d unless Dir.exists? d
end
end
2014-08-30 23:50:03 -07:00
def template(template, dest="", vars={})
template_file = "#{template_folder}/#{template}.erb"
dest_file = "#{dest}/#{File.basename(template)}"
2014-08-30 23:50:03 -07:00
raise "Template file doesn't exist" unless File.exists? template_file
raise "Destination folder doesn't exist" unless Dir.exists? dest
raise "Destination file already exists" unless File.exists? dest_file
2014-08-30 23:50:03 -07:00
erb = ERB.new(File.read(template_file))
File.open(dest_file) do |f|
f.puts(erb.result(binding))
end
end
end