Method: Hen::CLI#render
- Defined in:
- lib/hen/cli.rb
#render(sample, target) ⇒ Object
Renders the contents of sample as an ERb template, storing the result in target. Returns the content.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hen/cli.rb', line 53 def render(sample, target) abort "Sample file not found: #{sample}" unless File.readable?(sample) if File.readable?(target) abort unless agree("Target file already exists: #{target}. Overwrite? ") File.rename(target, "#{target}.bak-#{Time.now.to_i}") end content = ERB.new(File.read(sample)).result(binding) File.open(target, 'w') { |f| f.puts content unless content.empty? } content end |