def erb(params)
params_desc = {
:source => { :mandatory => false, :type => :string },
:src => { :mandatory => false, :type => :string },
:dest => { :mandatory => false, :type => :string },
:property => { :mandatory => false, :type => :string }
}
check_parameters(params, params_desc)
source = params[:source]
src = params[:src]
dest = params[:dest]
property = params[:property]
error "Must pass one of 'source' or 'src' parameters to erb task" if
not source and not src
error "Must pass one of 'dest' or 'property' parameters to erb task" if
not dest and not property
error "erb src file '#{src}' not found" if src and
(not File.exists?(src) or not File.file?(src) or
not File.readable?(src))
erb_source = source||File.read(src)
template = ERB.new(erb_source)
if src
puts "Processing ERB '#{src}'"
else
puts "Processing ERB"
end
begin
result = template.result(@build.context.context_binding)
rescue
error "Error processing ERB: #{$!}"
end
if dest
begin
File.open(dest, 'w') { |file| file.write(result) }
rescue
error "Error writing ERB processing result in file: #{$!}"
end
else
@build.context.set_property(property, result)
end
end