lib/reality/generators/template.rb in reality-generators-1.18.0 vs lib/reality/generators/template.rb in reality-generators-1.19.0
- old
+ new
@@ -109,14 +109,16 @@
end
# Base class for templates that generate a single file
class SingleFileOutputTemplate < Template
attr_reader :output_filename_pattern
+ attr_reader :output_filter
def initialize(template_set, facets, target, template_key, output_filename_pattern, helpers = [], options = {})
super(template_set, facets, target, template_key, helpers, options)
@output_filename_pattern = output_filename_pattern
+ @output_filter = options[:output_filter]
end
def output_path
output_filename_pattern
end
@@ -130,9 +132,10 @@
begin
output_filename = eval("\"#{self.output_filename_pattern}\"", context_binding, "#{self.template_key}#Filename")
output_filename = File.join(target_basedir, output_filename)
unprocessed_files.delete(output_filename)
result = self.render_to_string(context_binding)
+ result = self.output_filter.call(result) unless self.output_filter.nil?
FileUtils.mkdir_p File.dirname(output_filename) unless File.directory?(File.dirname(output_filename))
if File.exist?(output_filename) && IO.read(output_filename) == result
Generators.debug "Skipped generation of #{self.name} for #{self.target} #{object_name} to #{output_filename} due to no changes"
else
File.open(output_filename, 'w') { |f| f.write(result) }