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
|
puts
|
||||||
|
|
||||||
Ace::Item.all_instances.each do |item|
|
Ace::Item.all_instances.each do |item|
|
||||||
puts "~ Generating #{item.output_path}"
|
|
||||||
item.save!
|
item.save!
|
||||||
end
|
end
|
||||||
|
|
27
lib/ace.rb
27
lib/ace.rb
|
@ -143,12 +143,29 @@ module Ace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save!
|
def compare_mtime(one, others)
|
||||||
content = self.render # so filters can influence output_path
|
File.exist?(one) && File.mtime(one) > others.map { |post| File.mtime(post) }.max
|
||||||
|
end
|
||||||
|
|
||||||
FileUtils.mkdir_p File.dirname(self.output_path)
|
def source_files
|
||||||
File.open(self.output_path, "w") do |file|
|
[self.original_path]
|
||||||
file.puts(content)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue