Generate only items which are not #fresh?.
This commit is contained in:
parent
b6e582e7b0
commit
215d2fd42a
2 changed files with 22 additions and 6 deletions
1
bin/ace
1
bin/ace
|
@ -71,6 +71,5 @@ end
|
|||
puts
|
||||
|
||||
Ace::Item.all_instances.each do |item|
|
||||
puts "~ Generating #{item.output_path}"
|
||||
item.save!
|
||||
end
|
||||
|
|
27
lib/ace.rb
27
lib/ace.rb
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue