Merge pull request #795 from mojombo/new-log-format

New log format
This commit is contained in:
Parker Moore 2013-02-20 14:15:36 -08:00
commit 02da17b769
3 changed files with 24 additions and 15 deletions

View File

@ -133,12 +133,17 @@ module Jekyll
config_file = File.join(source, '_config.yml')
begin
config = YAML.safe_load_file(config_file)
raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
$stdout.puts "Configuration from #{config_file}"
raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
$stdout.puts "Configuration file: #{config_file}"
rescue SystemCallError
# Errno:ENOENT = file not found
$stderr.puts "Configuration file: none"
config = {}
rescue => err
$stderr.puts "WARNING: Could not read configuration. " +
$stderr.puts " " +
"WARNING: Error reading configuration. " +
"Using defaults (and options)."
$stderr.puts "\t" + err.to_s
$stderr.puts "#{err}"
config = {}
end

View File

@ -23,7 +23,9 @@ module Jekyll
def self.build(site, options)
source = options['source']
destination = options['destination']
puts "Building site: #{source} -> #{destination}"
puts " Source: #{source}"
puts " Destination: #{destination}"
print " Generating... "
begin
site.process
rescue Jekyll::FatalException => e
@ -33,7 +35,7 @@ module Jekyll
puts e.message
exit(1)
end
puts "Successfully generated site: #{source} -> #{destination}"
puts "done."
end
# Private: Watch for file changes and rebuild the site.
@ -48,7 +50,9 @@ module Jekyll
source = options['source']
destination = options['destination']
puts "Auto-Regenerating enabled: #{source} -> #{destination}"
puts " Source: #{source}"
puts " Destination: #{destination}"
puts " Auto-regeneration: enabled"
dw = DirectoryWatcher.new(source)
dw.interval = 1
@ -56,15 +60,16 @@ module Jekyll
dw.add_observer do |*args|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
puts "[#{t}] regeneration: #{args.size} files changed"
print " Regenerating: #{args.size} files at #{t} "
site.process
puts "...done."
end
dw.start
unless options['serving']
trap("INT") do
puts "Stopping auto-regeneration..."
puts " Halting auto-regeneration."
exit 0
end

View File

@ -7,22 +7,21 @@ class TestConfiguration < Test::Unit::TestCase
end
should "fire warning with no _config.yml" do
mock(YAML).safe_load_file(@path) { raise "No such file or directory - #{@path}" }
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock($stderr).puts("\tNo such file or directory - #{@path}")
mock(YAML).safe_load_file(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
mock($stderr).puts("Configuration file: none")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
should "load configuration as hash" do
mock(YAML).safe_load_file(@path) { Hash.new }
mock($stdout).puts("Configuration from #{@path}")
mock($stdout).puts("Configuration file: #{@path}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
should "fire warning with bad config" do
mock(YAML).safe_load_file(@path) { Array.new }
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock($stderr).puts("\tInvalid configuration - #{@path}")
mock($stderr).puts(" WARNING: Error reading configuration. Using defaults (and options).")
mock($stderr).puts("Configuration file: (INVALID) #{@path}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
end