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 'jekyll'
|
||||
|
||||
Jekyll::Deprecator.process(ARGV)
|
||||
|
||||
program :name, 'jekyll'
|
||||
program :version, Jekyll::VERSION
|
||||
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('commander', "~> 4.1.3")
|
||||
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('rdoc', "~> 3.11")
|
||||
|
|
|
@ -25,9 +25,12 @@ require 'English'
|
|||
require 'liquid'
|
||||
require 'maruku'
|
||||
require 'pygments'
|
||||
require 'colorator'
|
||||
|
||||
# internal requires
|
||||
require 'jekyll/core_ext'
|
||||
require 'jekyll/logger'
|
||||
require 'jekyll/deprecator'
|
||||
require 'jekyll/configuration'
|
||||
require 'jekyll/site'
|
||||
require 'jekyll/convertible'
|
||||
|
|
|
@ -18,9 +18,9 @@ module Jekyll
|
|||
site.process
|
||||
rescue Jekyll::FatalException => e
|
||||
puts
|
||||
puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
|
||||
puts "------------------------------------"
|
||||
puts e.message
|
||||
Jekyll::Logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
||||
Jekyll::Logger.error "", "------------------------------------"
|
||||
Jekyll::Logger.error "", e.message
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,9 +17,9 @@ module Jekyll
|
|||
def self.build(site, options)
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
puts " Source: #{source}"
|
||||
puts " Destination: #{destination}"
|
||||
print " Generating... "
|
||||
Jekyll::Logger.info "Source:", source
|
||||
Jekyll::Logger.info "Destination:", destination
|
||||
print Jekyll::Logger.formatted_topic "Generating..."
|
||||
self.process_site(site)
|
||||
puts "done."
|
||||
end
|
||||
|
@ -36,14 +36,14 @@ module Jekyll
|
|||
source = options['source']
|
||||
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.interval = 1
|
||||
|
||||
dw.add_observer do |*args|
|
||||
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)
|
||||
puts "...done."
|
||||
end
|
||||
|
|
|
@ -108,8 +108,8 @@ module Jekyll
|
|||
def read_config_file(file)
|
||||
configuration = dup
|
||||
next_config = YAML.safe_load_file(file)
|
||||
raise "Configuration file: (INVALID) #{file}" if !next_config.is_a?(Hash)
|
||||
$stdout.puts "Configuration file: #{file}"
|
||||
raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash)
|
||||
Jekyll::Logger.info "Configuration file:", file
|
||||
configuration.deep_merge(next_config)
|
||||
end
|
||||
|
||||
|
@ -128,10 +128,9 @@ module Jekyll
|
|||
end
|
||||
rescue SystemCallError
|
||||
# Errno:ENOENT = file not found
|
||||
$stderr.puts "Configuration file: none"
|
||||
Jekyll::Logger.warn "Configuration file:", "none"
|
||||
rescue => err
|
||||
$stderr.puts " " +
|
||||
"WARNING: Error reading configuration. " +
|
||||
Jekyll::Logger.warn "WARNING:", "Error reading configuration. " +
|
||||
"Using defaults (and options)."
|
||||
$stderr.puts "#{err}"
|
||||
end
|
||||
|
@ -146,8 +145,8 @@ module Jekyll
|
|||
def backwards_compatibilize
|
||||
config = dup
|
||||
# Provide backwards-compatibility
|
||||
if config['auto']
|
||||
$stderr.puts "Deprecation: ".rjust(20) + "'auto' has been changed to " +
|
||||
if config.has_key? 'auto'
|
||||
Jekyll::Logger.warn "Deprecation:", "'auto' has been changed to " +
|
||||
"'watch'. Please update your configuration to use 'watch'."
|
||||
config['watch'] = config['auto']
|
||||
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
|
||||
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({})
|
||||
end
|
||||
|
||||
|
@ -76,8 +76,8 @@ class TestConfiguration < Test::Unit::TestCase
|
|||
|
||||
should "fire warning with bad config" do
|
||||
mock(YAML).safe_load_file(@path) { Array.new }
|
||||
mock($stderr).puts(" WARNING: Error reading configuration. Using defaults (and options).")
|
||||
mock($stderr).puts("Configuration file: (INVALID) #{@path}")
|
||||
mock($stderr).puts(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
|
||||
mock($stderr).puts("Configuration file: (INVALID) #{@path}".yellow)
|
||||
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue