From b6e582e7b04e7cefb66d757f1fd3a1ca7c3b64eb Mon Sep 17 00:00:00 2001 From: Jakub Stastny aka botanicus Date: Mon, 7 Mar 2011 14:22:08 +0000 Subject: [PATCH 1/2] Refactoring, less warnings. --- lib/ace/filters/pygments.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ace/filters/pygments.rb b/lib/ace/filters/pygments.rb index 532720b..11ad792 100644 --- a/lib/ace/filters/pygments.rb +++ b/lib/ace/filters/pygments.rb @@ -7,15 +7,15 @@ require "albino" module Ace class PygmentsFilter < Filter def call(item, content) - puts 'PygmentsFilter ************************' doc = Nokogiri::HTML(content) - doc.css('pre').each do |pre| - puts "\nWARNING: '#{item.original_path}' - element
 not contains attribute 'lang'\n" if pre['lang'].nil?
-        puts "\nWARNING: '#{item.original_path}' - attribute 'lang' not contains any value\n" if  !pre['lang'].nil? && pre['lang'].empty?
-        puts "*** Syntax highlight using '#{pre['lang']}' lexer" unless pre['lang'].nil? || pre['lang'].empty?
-        pre.replace Albino.colorize(pre.content, pre['lang']) unless pre['lang'].nil? || pre['lang'].empty?
+      doc.css("pre[lang]").each do |pre|
+        unless pre['lang'].nil? || pre['lang'].empty?
+          # Set $VERBOSE to nil if you don't want to see this message.
+          warn "~ Syntax highlight in '#{item.original_path}' using '#{pre['lang']}' lexer."
+          pre.replace Albino.colorize(pre.content, pre['lang'])
+        end
       end
-      doc
+      doc.to_s
     end
   end
 end

From 215d2fd42a1dd2a8e8f8789b97f4a83063a3cecc Mon Sep 17 00:00:00 2001
From: Jakub Stastny aka botanicus 
Date: Sun, 13 Mar 2011 14:53:25 +0000
Subject: [PATCH 2/2] Generate only items which are not #fresh?.

---
 bin/ace    |  1 -
 lib/ace.rb | 27 ++++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/bin/ace b/bin/ace
index 691e64b..22396d2 100755
--- a/bin/ace
+++ b/bin/ace
@@ -71,6 +71,5 @@ end
 puts
 
 Ace::Item.all_instances.each do |item|
-  puts "~ Generating #{item.output_path}"
   item.save!
 end
diff --git a/lib/ace.rb b/lib/ace.rb
index 2c79a55..e60205b 100644
--- a/lib/ace.rb
+++ b/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