Merge pull request #959 from mojombo/deprecator
Refactor Logging and Deprecation Messaging
This commit is contained in:
commit
398cd633b6
|
@ -6,6 +6,8 @@ $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
|
||||||
require 'commander/import'
|
require 'commander/import'
|
||||||
require 'jekyll'
|
require 'jekyll'
|
||||||
|
|
||||||
|
Jekyll::Deprecator.process(ARGV)
|
||||||
|
|
||||||
program :name, 'jekyll'
|
program :name, 'jekyll'
|
||||||
program :version, Jekyll::VERSION
|
program :version, Jekyll::VERSION
|
||||||
program :description, 'Jekyll is a blog-aware, static site generator in Ruby'
|
program :description, 'Jekyll is a blog-aware, static site generator in Ruby'
|
||||||
|
|
|
@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_runtime_dependency('pygments.rb', "~> 0.4.2")
|
s.add_runtime_dependency('pygments.rb', "~> 0.4.2")
|
||||||
s.add_runtime_dependency('commander', "~> 4.1.3")
|
s.add_runtime_dependency('commander', "~> 4.1.3")
|
||||||
s.add_runtime_dependency('safe_yaml', "~> 0.7.0")
|
s.add_runtime_dependency('safe_yaml', "~> 0.7.0")
|
||||||
|
s.add_runtime_dependency('colorator', "~> 0.1")
|
||||||
|
|
||||||
s.add_development_dependency('rake', "~> 10.0.3")
|
s.add_development_dependency('rake', "~> 10.0.3")
|
||||||
s.add_development_dependency('rdoc', "~> 3.11")
|
s.add_development_dependency('rdoc', "~> 3.11")
|
||||||
|
|
|
@ -25,9 +25,12 @@ require 'English'
|
||||||
require 'liquid'
|
require 'liquid'
|
||||||
require 'maruku'
|
require 'maruku'
|
||||||
require 'pygments'
|
require 'pygments'
|
||||||
|
require 'colorator'
|
||||||
|
|
||||||
# internal requires
|
# internal requires
|
||||||
require 'jekyll/core_ext'
|
require 'jekyll/core_ext'
|
||||||
|
require 'jekyll/logger'
|
||||||
|
require 'jekyll/deprecator'
|
||||||
require 'jekyll/configuration'
|
require 'jekyll/configuration'
|
||||||
require 'jekyll/site'
|
require 'jekyll/site'
|
||||||
require 'jekyll/convertible'
|
require 'jekyll/convertible'
|
||||||
|
|
|
@ -18,9 +18,9 @@ module Jekyll
|
||||||
site.process
|
site.process
|
||||||
rescue Jekyll::FatalException => e
|
rescue Jekyll::FatalException => e
|
||||||
puts
|
puts
|
||||||
puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
|
Jekyll::Logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
||||||
puts "------------------------------------"
|
Jekyll::Logger.error "", "------------------------------------"
|
||||||
puts e.message
|
Jekyll::Logger.error "", e.message
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,9 +17,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 " Source: #{source}"
|
Jekyll::Logger.info "Source:", source
|
||||||
puts " Destination: #{destination}"
|
Jekyll::Logger.info "Destination:", destination
|
||||||
print " Generating... "
|
print Jekyll::Logger.formatted_topic "Generating..."
|
||||||
self.process_site(site)
|
self.process_site(site)
|
||||||
puts "done."
|
puts "done."
|
||||||
end
|
end
|
||||||
|
@ -36,14 +36,14 @@ module Jekyll
|
||||||
source = options['source']
|
source = options['source']
|
||||||
destination = options['destination']
|
destination = options['destination']
|
||||||
|
|
||||||
puts " Auto-regeneration: enabled"
|
Jekyll::Logger.info "Auto-regeneration:", "enabled"
|
||||||
|
|
||||||
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
||||||
dw.interval = 1
|
dw.interval = 1
|
||||||
|
|
||||||
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")
|
||||||
print " Regenerating: #{args.size} files at #{t} "
|
print Jekyll.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
|
||||||
self.process_site(site)
|
self.process_site(site)
|
||||||
puts "...done."
|
puts "...done."
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,8 +108,8 @@ module Jekyll
|
||||||
def read_config_file(file)
|
def read_config_file(file)
|
||||||
configuration = dup
|
configuration = dup
|
||||||
next_config = YAML.safe_load_file(file)
|
next_config = YAML.safe_load_file(file)
|
||||||
raise "Configuration file: (INVALID) #{file}" if !next_config.is_a?(Hash)
|
raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash)
|
||||||
$stdout.puts "Configuration file: #{file}"
|
Jekyll::Logger.info "Configuration file:", file
|
||||||
configuration.deep_merge(next_config)
|
configuration.deep_merge(next_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,10 +128,9 @@ module Jekyll
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
# Errno:ENOENT = file not found
|
# Errno:ENOENT = file not found
|
||||||
$stderr.puts "Configuration file: none"
|
Jekyll::Logger.warn "Configuration file:", "none"
|
||||||
rescue => err
|
rescue => err
|
||||||
$stderr.puts " " +
|
Jekyll::Logger.warn "WARNING:", "Error reading configuration. " +
|
||||||
"WARNING: Error reading configuration. " +
|
|
||||||
"Using defaults (and options)."
|
"Using defaults (and options)."
|
||||||
$stderr.puts "#{err}"
|
$stderr.puts "#{err}"
|
||||||
end
|
end
|
||||||
|
@ -146,8 +145,8 @@ module Jekyll
|
||||||
def backwards_compatibilize
|
def backwards_compatibilize
|
||||||
config = dup
|
config = dup
|
||||||
# Provide backwards-compatibility
|
# Provide backwards-compatibility
|
||||||
if config['auto']
|
if config.has_key? 'auto'
|
||||||
$stderr.puts "Deprecation: ".rjust(20) + "'auto' has been changed to " +
|
Jekyll::Logger.warn "Deprecation:", "'auto' has been changed to " +
|
||||||
"'watch'. Please update your configuration to use 'watch'."
|
"'watch'. Please update your configuration to use 'watch'."
|
||||||
config['watch'] = config['auto']
|
config['watch'] = config['auto']
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
module Jekyll
|
||||||
|
class Deprecator
|
||||||
|
def self.process(args)
|
||||||
|
deprecation_message args, "--server", "The --server command has been replaced by the \
|
||||||
|
'serve' subcommand."
|
||||||
|
deprecation_message args, "--no-server", "To build Jekyll without launching a server, \
|
||||||
|
use the 'build' subcommand."
|
||||||
|
deprecation_message args, "--auto", "The switch '--auto' has been replaced with '--watch'."
|
||||||
|
deprecation_message args, "--no-auto", "To disable auto-replication, simply leave off \
|
||||||
|
the '--watch' switch."
|
||||||
|
deprecation_message args, "--pygments", "The 'pygments' setting can only be set in \
|
||||||
|
your config files."
|
||||||
|
deprecation_message args, "--paginate", "The 'paginate' setting can only be set in your \
|
||||||
|
config files."
|
||||||
|
deprecation_message args, "--url", "The 'url' setting can only be set in your config files."
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.deprecation_message(args, deprecated_argument, message)
|
||||||
|
if args.include?(deprecated_argument)
|
||||||
|
Jekyll::Logger.error "Deprecation:", message
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,52 @@
|
||||||
|
module Jekyll
|
||||||
|
module Logger
|
||||||
|
# Public: Print a jekyll message to stdout
|
||||||
|
#
|
||||||
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
# message - the message detail
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def self.info(topic, message)
|
||||||
|
$stdout.puts message(topic, message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Print a jekyll message to stderr
|
||||||
|
#
|
||||||
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
# message - the message detail
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def self.warn(topic, message)
|
||||||
|
$stderr.puts message(topic, message).yellow
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Print a jekyll error message to stderr
|
||||||
|
#
|
||||||
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
# message - the message detail
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def self.error(topic, message)
|
||||||
|
$stderr.puts message(topic, message).red
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Build a Jekyll topic method
|
||||||
|
#
|
||||||
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
# message - the message detail
|
||||||
|
#
|
||||||
|
# Returns the formatted message
|
||||||
|
def self.message(topic, message)
|
||||||
|
formatted_topic(topic) + message.gsub(/\s+/, ' ')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Format the topic
|
||||||
|
#
|
||||||
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
#
|
||||||
|
# Returns the formatted topic statement
|
||||||
|
def self.formatted_topic(topic)
|
||||||
|
"#{topic} ".rjust(20)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -64,7 +64,7 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
|
|
||||||
should "fire warning with no _config.yml" do
|
should "fire warning with no _config.yml" do
|
||||||
mock(YAML).safe_load_file(@path) { raise SystemCallError, "No 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")
|
mock($stderr).puts("Configuration file: none".yellow)
|
||||||
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
|
|
||||||
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: Error reading configuration. Using defaults (and options).")
|
mock($stderr).puts(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
|
||||||
mock($stderr).puts("Configuration file: (INVALID) #{@path}")
|
mock($stderr).puts("Configuration file: (INVALID) #{@path}".yellow)
|
||||||
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue