From 61465053eb367dadf117230d4ae0e7f236570c45 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 18:02:16 +0200 Subject: [PATCH 01/10] Add Jekyll::Logger --- lib/jekyll/logger.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/jekyll/logger.rb diff --git a/lib/jekyll/logger.rb b/lib/jekyll/logger.rb new file mode 100644 index 00000000..fe598a14 --- /dev/null +++ b/lib/jekyll/logger.rb @@ -0,0 +1,42 @@ +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 info(topic, message) + $stdout.puts Jekyll.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 warn(topic, message) + $stderr.puts Jekyll.message(topic, message) + 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 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 formatted_topic(topic) + "#{topic} ".rjust(20) + end + end +end From bc6748f1399d150440190d4fe0ef351498e587af Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 18:03:38 +0200 Subject: [PATCH 02/10] Add Jekyll::Deprecator --- lib/jekyll/deprecator.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/jekyll/deprecator.rb diff --git a/lib/jekyll/deprecator.rb b/lib/jekyll/deprecator.rb new file mode 100644 index 00000000..02f00d15 --- /dev/null +++ b/lib/jekyll/deprecator.rb @@ -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.warn "Deprecation:", message + exit(1) + end + end + end +end From a355762190c2d4e656d5fc492a9ce798d063232b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 18:04:37 +0200 Subject: [PATCH 03/10] Run Jekyll::Deprecator.process upon invocation of Jekyll --- bin/jekyll | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/jekyll b/bin/jekyll index 79c368d8..7556a317 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -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' From c5f6e527b5017a92cac5319079a095190ba449da Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 18:05:03 +0200 Subject: [PATCH 04/10] Bring Logger and Deprecator into the fold --- lib/jekyll.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 78572491..1941a794 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -28,6 +28,8 @@ require 'pygments' # internal requires require 'jekyll/core_ext' +require 'jekyll/logger' +require 'jekyll/deprecator' require 'jekyll/configuration' require 'jekyll/site' require 'jekyll/convertible' @@ -55,6 +57,8 @@ SafeYAML::OPTIONS[:suppress_warnings] = true module Jekyll VERSION = '1.0.0.beta4' + extend Logger + # Public: Generate a Jekyll configuration Hash by merging the default # options with anything in _config.yml, and adding the given options on top. # From 17f97cdbab1067844c32f52eb626a3862b24be13 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 18:22:34 +0200 Subject: [PATCH 05/10] Move manual printing to Jekyll.info and Jekyll.warn --- lib/jekyll/command.rb | 6 +++--- lib/jekyll/commands/build.rb | 10 +++++----- lib/jekyll/configuration.rb | 13 ++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index 1f305a3c..a7678c30 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -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.warn "ERROR:", "YOUR SITE COULD NOT BE BUILT:" + Jekyll.warn "", "------------------------------------" + Jekyll.warn "", e.message exit(1) end end diff --git a/lib/jekyll/commands/build.rb b/lib/jekyll/commands/build.rb index 2ee78d22..a40d261f 100644 --- a/lib/jekyll/commands/build.rb +++ b/lib/jekyll/commands/build.rb @@ -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.info "Source:", source + Jekyll.info "Destination:", destination + print Jekyll.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.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 diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index f0617744..19deaf32 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -104,7 +104,7 @@ module Jekyll 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}" + Jekyll.info "Configuration file:", file configuration.deep_merge(next_config) end @@ -123,12 +123,11 @@ module Jekyll end rescue SystemCallError # Errno:ENOENT = file not found - $stderr.puts "Configuration file: none" + Jekyll.warn "Configuration file:", "none" rescue => err - $stderr.puts " " + - "WARNING: Error reading configuration. " + + Jekyll.warn "WARNING", "Error reading configuration. " + "Using defaults (and options)." - $stderr.puts "#{err}" + Jekyll.warn "", "#{err}" end configuration.backwards_compatibilize @@ -141,8 +140,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.warn "Deprecation:", "'auto' has been changed to " + "'watch'. Please update your configuration to use 'watch'." config['watch'] = config['auto'] end From 97dbadb5dd90cf65861dd6586c30cff085e64711 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 19:46:25 +0200 Subject: [PATCH 06/10] Add colorator gem --- jekyll.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/jekyll.gemspec b/jekyll.gemspec index 4bff92df..21977b6e 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -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") From b99baeae27135c1978d6c1e867ef9b5ebca2bcc4 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 19:58:41 +0200 Subject: [PATCH 07/10] Colorize warns as yellow --- lib/jekyll.rb | 1 + lib/jekyll/logger.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 1941a794..4b385fb2 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -25,6 +25,7 @@ require 'English' require 'liquid' require 'maruku' require 'pygments' +require 'colorator' # internal requires require 'jekyll/core_ext' diff --git a/lib/jekyll/logger.rb b/lib/jekyll/logger.rb index fe598a14..e7af4563 100644 --- a/lib/jekyll/logger.rb +++ b/lib/jekyll/logger.rb @@ -17,7 +17,7 @@ module Jekyll # # Returns nothing def warn(topic, message) - $stderr.puts Jekyll.message(topic, message) + $stderr.puts (Jekyll.message(topic, message)).yellow end # Public: Build a Jekyll topic method From ef9d8ddb7d6fb4eefc2f655fe6c6264af89a59f9 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 20:24:45 +0200 Subject: [PATCH 08/10] Matching tests to new colorized output --- lib/jekyll/configuration.rb | 6 +++--- test/test_configuration.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 19deaf32..e67300a7 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -103,7 +103,7 @@ 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) + raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash) Jekyll.info "Configuration file:", file configuration.deep_merge(next_config) end @@ -125,9 +125,9 @@ module Jekyll # Errno:ENOENT = file not found Jekyll.warn "Configuration file:", "none" rescue => err - Jekyll.warn "WARNING", "Error reading configuration. " + + Jekyll.warn "WARNING:", "Error reading configuration. " + "Using defaults (and options)." - Jekyll.warn "", "#{err}" + $stderr.puts "#{err}" end configuration.backwards_compatibilize diff --git a/test/test_configuration.rb b/test/test_configuration.rb index 6eb35fc4..6e4675c6 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -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 From ef51b0f9e4d753ab39e2c09f874c15545fdc7164 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 20:27:44 +0200 Subject: [PATCH 09/10] Error message is red --- lib/jekyll/deprecator.rb | 2 +- lib/jekyll/logger.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/deprecator.rb b/lib/jekyll/deprecator.rb index 02f00d15..642f6f48 100644 --- a/lib/jekyll/deprecator.rb +++ b/lib/jekyll/deprecator.rb @@ -17,7 +17,7 @@ module Jekyll def self.deprecation_message(args, deprecated_argument, message) if args.include?(deprecated_argument) - Jekyll.warn "Deprecation:", message + Jekyll.error "Deprecation:", message exit(1) end end diff --git a/lib/jekyll/logger.rb b/lib/jekyll/logger.rb index e7af4563..6b30ad95 100644 --- a/lib/jekyll/logger.rb +++ b/lib/jekyll/logger.rb @@ -20,6 +20,16 @@ module Jekyll $stderr.puts (Jekyll.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 error(topic, message) + $stderr.puts (Jekyll.message(topic, message)).red + end + # Public: Build a Jekyll topic method # # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc. From 4ef107f3e811f48c8e674762944c3733ce4f2e03 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 19:27:19 +0200 Subject: [PATCH 10/10] Remove Logger methods from main Jekyll module. --- lib/jekyll.rb | 2 -- lib/jekyll/command.rb | 6 +++--- lib/jekyll/commands/build.rb | 8 ++++---- lib/jekyll/configuration.rb | 8 ++++---- lib/jekyll/deprecator.rb | 2 +- lib/jekyll/logger.rb | 16 ++++++++-------- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 4b385fb2..cbc0d3ae 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -58,8 +58,6 @@ SafeYAML::OPTIONS[:suppress_warnings] = true module Jekyll VERSION = '1.0.0.beta4' - extend Logger - # Public: Generate a Jekyll configuration Hash by merging the default # options with anything in _config.yml, and adding the given options on top. # diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index a7678c30..a352028b 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -18,9 +18,9 @@ module Jekyll site.process rescue Jekyll::FatalException => e puts - Jekyll.warn "ERROR:", "YOUR SITE COULD NOT BE BUILT:" - Jekyll.warn "", "------------------------------------" - Jekyll.warn "", e.message + Jekyll::Logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:" + Jekyll::Logger.error "", "------------------------------------" + Jekyll::Logger.error "", e.message exit(1) end end diff --git a/lib/jekyll/commands/build.rb b/lib/jekyll/commands/build.rb index a40d261f..e559ff4f 100644 --- a/lib/jekyll/commands/build.rb +++ b/lib/jekyll/commands/build.rb @@ -17,9 +17,9 @@ module Jekyll def self.build(site, options) source = options['source'] destination = options['destination'] - Jekyll.info "Source:", source - Jekyll.info "Destination:", destination - print Jekyll.formatted_topic "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,7 +36,7 @@ module Jekyll source = options['source'] destination = options['destination'] - Jekyll.info "Auto-regeneration:", "enabled" + Jekyll::Logger.info "Auto-regeneration:", "enabled" dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true) dw.interval = 1 diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index e67300a7..074d13c3 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -104,7 +104,7 @@ module Jekyll configuration = dup next_config = YAML.safe_load_file(file) raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash) - Jekyll.info "Configuration file:", file + Jekyll::Logger.info "Configuration file:", file configuration.deep_merge(next_config) end @@ -123,9 +123,9 @@ module Jekyll end rescue SystemCallError # Errno:ENOENT = file not found - Jekyll.warn "Configuration file:", "none" + Jekyll::Logger.warn "Configuration file:", "none" rescue => err - Jekyll.warn "WARNING:", "Error reading configuration. " + + Jekyll::Logger.warn "WARNING:", "Error reading configuration. " + "Using defaults (and options)." $stderr.puts "#{err}" end @@ -141,7 +141,7 @@ module Jekyll config = dup # Provide backwards-compatibility if config.has_key? 'auto' - Jekyll.warn "Deprecation:", "'auto' has been changed to " + + Jekyll::Logger.warn "Deprecation:", "'auto' has been changed to " + "'watch'. Please update your configuration to use 'watch'." config['watch'] = config['auto'] end diff --git a/lib/jekyll/deprecator.rb b/lib/jekyll/deprecator.rb index 642f6f48..88e959b7 100644 --- a/lib/jekyll/deprecator.rb +++ b/lib/jekyll/deprecator.rb @@ -17,7 +17,7 @@ module Jekyll def self.deprecation_message(args, deprecated_argument, message) if args.include?(deprecated_argument) - Jekyll.error "Deprecation:", message + Jekyll::Logger.error "Deprecation:", message exit(1) end end diff --git a/lib/jekyll/logger.rb b/lib/jekyll/logger.rb index 6b30ad95..74a1bdc4 100644 --- a/lib/jekyll/logger.rb +++ b/lib/jekyll/logger.rb @@ -6,8 +6,8 @@ module Jekyll # message - the message detail # # Returns nothing - def info(topic, message) - $stdout.puts Jekyll.message(topic, message) + def self.info(topic, message) + $stdout.puts message(topic, message) end # Public: Print a jekyll message to stderr @@ -16,8 +16,8 @@ module Jekyll # message - the message detail # # Returns nothing - def warn(topic, message) - $stderr.puts (Jekyll.message(topic, message)).yellow + def self.warn(topic, message) + $stderr.puts message(topic, message).yellow end # Public: Print a jekyll error message to stderr @@ -26,8 +26,8 @@ module Jekyll # message - the message detail # # Returns nothing - def error(topic, message) - $stderr.puts (Jekyll.message(topic, message)).red + def self.error(topic, message) + $stderr.puts message(topic, message).red end # Public: Build a Jekyll topic method @@ -36,7 +36,7 @@ module Jekyll # message - the message detail # # Returns the formatted message - def message(topic, message) + def self.message(topic, message) formatted_topic(topic) + message.gsub(/\s+/, ' ') end @@ -45,7 +45,7 @@ module Jekyll # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc. # # Returns the formatted topic statement - def formatted_topic(topic) + def self.formatted_topic(topic) "#{topic} ".rjust(20) end end