Generate only items which are not #fresh?.

master
Jakub Stastny aka botanicus 2011-03-13 14:53:25 +00:00
parent b6e582e7b0
commit 215d2fd42a
2 changed files with 22 additions and 6 deletions

View File

@ -71,6 +71,5 @@ end
puts
Ace::Item.all_instances.each do |item|
puts "~ Generating #{item.output_path}"
item.save!
end

View File

@ -143,12 +143,29 @@ module Ace
end
end
def save!
content = self.render # so filters can influence output_path
def compare_mtime(one, others)
File.exist?(one) && File.mtime(one) > others.map { |post| File.mtime(post) }.max
end
FileUtils.mkdir_p File.dirname(self.output_path)
File.open(self.output_path, "w") do |file|
file.puts(content)
def source_files
[self.original_path]
end
def fresh?
@fresh ||= compare_mtime(self.output_path, self.source_files)
end
def save!
if self.fresh?
puts "~ [IGNORE] #{self.output_path}"
else
puts "~ [UPDATE] #{self.output_path}"
content = self.render # so filters can influence output_path
FileUtils.mkdir_p File.dirname(self.output_path)
File.open(self.output_path, "w") do |file|
file.puts(content)
end
end
end
end