lib/nanoc/cli/commands/compile.rb in nanoc-3.4.1 vs lib/nanoc/cli/commands/compile.rb in nanoc-3.4.2
- old
+ new
@@ -20,15 +20,16 @@
option :a, :all, '(ignored)'
option :f, :force, '(ignored)'
module Nanoc::CLI::Commands
+ # FIXME this command is horribly long and complicated and does way too much. plz cleanup thx.
class Compile < ::Nanoc::CLI::CommandRunner
def run
# Make sure we are in a nanoc site directory
- puts "Loading site data..."
+ puts "Loading site data…"
self.require_site
# Check presence of --all option
if options.has_key?(:all) || options.has_key?(:force)
$stderr.puts "Warning: the --force option (and its deprecated --all alias) are, as of nanoc 3.2, no longer supported and have no effect."
@@ -40,22 +41,18 @@
$stderr.puts 'Note: As of nanoc 3.2, it is no longer possible to compile a single item. When invoking the “compile” command, all items in the site will be compiled.'
$stderr.puts '-' * 80
end
# Give feedback
- puts "Compiling site..."
+ puts "Compiling site…"
# Initialize profiling stuff
time_before = Time.now
@rep_times = {}
@filter_times = {}
setup_notifications
- # Set up progress indicator threads
- @progress_locks = {}
- @progress_threads = {}
-
# Prepare for generating diffs
setup_diffs
# Set up GC control
@gc_lock = Mutex.new
@@ -79,11 +76,11 @@
# Stop diffing
teardown_diffs
# Prune
if self.site.config[:prune][:auto_prune]
- Nanoc::Extra::Pruner.new(self.site).run
+ Nanoc::Extra::Pruner.new(self.site, :exclude => self.prune_config_exclude).run
end
# Give general feedback
puts
puts "Site compiled in #{format('%.2f', Time.now - time_before)}s."
@@ -230,46 +227,44 @@
def start_filter_progress(rep, filter_name)
# Only show progress on terminals
return if !$stdout.tty?
- @progress_locks[rep.inspect + filter_name.inspect] = lock = Mutex.new
- lock.synchronize do
- @progress_threads[rep.inspect + filter_name.inspect] = Thread.new do
- delay = 1.0
- step = 0
+ @progress_thread = Thread.new do
+ delay = 1.0
+ step = 0
- text = "Running #{filter_name} filter… "
+ text = " running #{filter_name} filter… "
- while !Thread.current[:stopped]
- sleep 0.1
+ loop do
+ if Thread.current[:stopped]
+ # Clear
+ if delay < 0.1
+ $stdout.print ' ' * (text.length + 3) + "\r"
+ end
- # Wait for a while before showing text
- delay -= 0.1
- next if delay > 0.05
+ break
+ end
- # Print progress
+ # Show progress
+ if delay < 0.1
$stdout.print text + %w( | / - \\ )[step] + "\r"
step = (step + 1) % 4
end
- # Clear text
- if delay < 0.05
- $stdout.print ' ' * (text.length + 1 + 1) + "\r"
- end
+ sleep 0.1
+ delay -= 0.1
end
+
end
end
def stop_filter_progress(rep, filter_name)
# Only show progress on terminals
return if !$stdout.tty?
- lock = @progress_locks[rep.inspect + filter_name.inspect]
- lock.synchronize do
- @progress_threads[rep.inspect + filter_name.inspect][:stopped] = true
- end
+ @progress_thread[:stopped] = true
end
def print_profiling_feedback(reps)
# Get max filter length
max_filter_name_length = @filter_times.keys.map { |k| k.to_s.size }.max
@@ -307,9 +302,19 @@
# Output stats
filter_name = format("%#{max_filter_name_length}s", filter_name)
puts "#{filter_name} | #{count} #{min}s #{avg}s #{max}s #{tot}s"
end
+ end
+
+ protected
+
+ def prune_config
+ self.site.config[:prune] || {}
+ end
+
+ def prune_config_exclude
+ self.prune_config[:exclude] || {}
end
end
end