commit
02da17b769
|
@ -133,12 +133,17 @@ module Jekyll
|
||||||
config_file = File.join(source, '_config.yml')
|
config_file = File.join(source, '_config.yml')
|
||||||
begin
|
begin
|
||||||
config = YAML.safe_load_file(config_file)
|
config = YAML.safe_load_file(config_file)
|
||||||
raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
|
raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
|
||||||
$stdout.puts "Configuration from #{config_file}"
|
$stdout.puts "Configuration file: #{config_file}"
|
||||||
|
rescue SystemCallError
|
||||||
|
# Errno:ENOENT = file not found
|
||||||
|
$stderr.puts "Configuration file: none"
|
||||||
|
config = {}
|
||||||
rescue => err
|
rescue => err
|
||||||
$stderr.puts "WARNING: Could not read configuration. " +
|
$stderr.puts " " +
|
||||||
|
"WARNING: Error reading configuration. " +
|
||||||
"Using defaults (and options)."
|
"Using defaults (and options)."
|
||||||
$stderr.puts "\t" + err.to_s
|
$stderr.puts "#{err}"
|
||||||
config = {}
|
config = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ module Jekyll
|
||||||
def self.build(site, options)
|
def self.build(site, options)
|
||||||
source = options['source']
|
source = options['source']
|
||||||
destination = options['destination']
|
destination = options['destination']
|
||||||
puts "Building site: #{source} -> #{destination}"
|
puts " Source: #{source}"
|
||||||
|
puts " Destination: #{destination}"
|
||||||
|
print " Generating... "
|
||||||
begin
|
begin
|
||||||
site.process
|
site.process
|
||||||
rescue Jekyll::FatalException => e
|
rescue Jekyll::FatalException => e
|
||||||
|
@ -33,7 +35,7 @@ module Jekyll
|
||||||
puts e.message
|
puts e.message
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
puts "Successfully generated site: #{source} -> #{destination}"
|
puts "done."
|
||||||
end
|
end
|
||||||
|
|
||||||
# Private: Watch for file changes and rebuild the site.
|
# Private: Watch for file changes and rebuild the site.
|
||||||
|
@ -48,7 +50,9 @@ module Jekyll
|
||||||
source = options['source']
|
source = options['source']
|
||||||
destination = options['destination']
|
destination = options['destination']
|
||||||
|
|
||||||
puts "Auto-Regenerating enabled: #{source} -> #{destination}"
|
puts " Source: #{source}"
|
||||||
|
puts " Destination: #{destination}"
|
||||||
|
puts " Auto-regeneration: enabled"
|
||||||
|
|
||||||
dw = DirectoryWatcher.new(source)
|
dw = DirectoryWatcher.new(source)
|
||||||
dw.interval = 1
|
dw.interval = 1
|
||||||
|
@ -56,15 +60,16 @@ module Jekyll
|
||||||
|
|
||||||
dw.add_observer do |*args|
|
dw.add_observer do |*args|
|
||||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
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
|
site.process
|
||||||
|
puts "...done."
|
||||||
end
|
end
|
||||||
|
|
||||||
dw.start
|
dw.start
|
||||||
|
|
||||||
unless options['serving']
|
unless options['serving']
|
||||||
trap("INT") do
|
trap("INT") do
|
||||||
puts "Stopping auto-regeneration..."
|
puts " Halting auto-regeneration."
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,22 +7,21 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning with no _config.yml" do
|
should "fire warning with no _config.yml" do
|
||||||
mock(YAML).safe_load_file(@path) { raise "No such file or directory - #{@path}" }
|
mock(YAML).safe_load_file(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
|
||||||
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
|
mock($stderr).puts("Configuration file: none")
|
||||||
mock($stderr).puts("\tNo such file or directory - #{@path}")
|
|
||||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load configuration as hash" do
|
should "load configuration as hash" do
|
||||||
mock(YAML).safe_load_file(@path) { Hash.new }
|
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({})
|
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning with bad config" do
|
should "fire warning with bad config" do
|
||||||
mock(YAML).safe_load_file(@path) { Array.new }
|
mock(YAML).safe_load_file(@path) { Array.new }
|
||||||
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
|
mock($stderr).puts(" WARNING: Error reading configuration. Using defaults (and options).")
|
||||||
mock($stderr).puts("\tInvalid configuration - #{@path}")
|
mock($stderr).puts("Configuration file: (INVALID) #{@path}")
|
||||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue