diff --git a/bin/ace b/bin/ace index 4afc9ed..d8e4508 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 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