class Nanoc::CLI::CompileListeners::DiffGenerator
Public Class Methods
enable_for?(command_runner, site)
click to toggle source
@see Listener#enable_for?
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 51 def self.enable_for?(command_runner, site) site.config[:enable_output_diff] || command_runner.options[:diff] end
Public Instance Methods
start()
click to toggle source
@see Listener#start
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 56 def start setup_diffs on(:rep_ready_for_diff) do |raw_path, old_content, new_content| generate_diff_for(raw_path, old_content, new_content) end end
stop()
click to toggle source
@see Listener#stop
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 65 def stop teardown_diffs end
Protected Instance Methods
generate_diff_for(path, old_content, new_content)
click to toggle source
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 81 def generate_diff_for(path, old_content, new_content) return if old_content == new_content @diff_threads << Thread.new do # Simplify path # FIXME: do not depend on working directory if path.start_with?(Dir.getwd) path = path[(Dir.getwd.size + 1)..path.size] end # Generate diff diff = Differ.new(path, old_content, new_content).call # Write diff @diff_lock.synchronize do File.open('output.diff', 'a') { |io| io.write(diff) } end end end
setup_diffs()
click to toggle source
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 71 def setup_diffs @diff_lock = Mutex.new @diff_threads = [] FileUtils.rm('output.diff') if File.file?('output.diff') end
teardown_diffs()
click to toggle source
# File lib/nanoc/cli/compile_listeners/diff_generator.rb, line 77 def teardown_diffs @diff_threads.each(&:join) end