Class: Nanoc::CLI::Commands::Compile::DiffGenerator
- Inherits:
-
Listener
- Object
- Listener
- Nanoc::CLI::Commands::Compile::DiffGenerator
show all
- Defined in:
- lib/nanoc/cli/commands/compile.rb
Overview
Generates diffs for every output file written
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods inherited from Listener
#initialize
Class Method Details
+ (Boolean) enable_for?(command_runner)
64
65
66
|
# File 'lib/nanoc/cli/commands/compile.rb', line 64
def self.enable_for?(command_runner)
command_runner.site.config[:enable_output_diff]
end
|
Instance Method Details
- (Object) start
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/nanoc/cli/commands/compile.rb', line 69
def start
require 'tempfile'
setup_diffs
old_contents = {}
Nanoc::NotificationCenter.on(:will_write_rep) do |rep, snapshot|
path = rep.raw_path(snapshot: snapshot)
old_contents[rep] = File.file?(path) ? File.read(path) : nil
end
Nanoc::NotificationCenter.on(:rep_written) do |rep, path, _is_created, _is_modified|
unless rep.binary?
new_contents = File.file?(path) ? File.read(path) : nil
if old_contents[rep] && new_contents
generate_diff_for(rep, old_contents[rep], new_contents)
end
old_contents.delete(rep)
end
end
end
|
- (Object) stop
89
90
91
92
|
# File 'lib/nanoc/cli/commands/compile.rb', line 89
def stop
super
teardown_diffs
end
|