From 8f7e229e8c0f3ae4d4de6635893200f582cd3490 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 20:56:20 +0200 Subject: [PATCH 1/4] Cleaned up the deprecator a little --- lib/jekyll/deprecator.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/deprecator.rb b/lib/jekyll/deprecator.rb index 8cbb93a5..23af739d 100644 --- a/lib/jekyll/deprecator.rb +++ b/lib/jekyll/deprecator.rb @@ -2,18 +2,18 @@ module Jekyll class Deprecator def self.process(args) no_subcommand(args) - deprecation_message args, "--server", "The --server command has been replaced by the \ + arg_is_present? args, "--server", "The --server command has been replaced by the \ 'serve' subcommand." - deprecation_message args, "--no-server", "To build Jekyll without launching a server, \ + arg_is_present? 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 \ + arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'." + arg_is_present? 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 \ + arg_is_present? 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 \ + arg_is_present? 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." + arg_is_present? args, "--url", "The 'url' setting can only be set in your config files." end def self.no_subcommand(args) @@ -23,10 +23,14 @@ module Jekyll end end - def self.deprecation_message(args, deprecated_argument, message) + def self.arg_is_present?(args, deprecated_argument, message) if args.include?(deprecated_argument) - Jekyll.logger.error "Deprecation:", message + deprecation_message(message) end end + + def self.deprecation_message(message) + Jekyll.logger.error "Deprecation:", message + end end end From 6eec3a7942540966371a7ef6b78a8323fcede852 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 20:56:29 +0200 Subject: [PATCH 2/4] Print warning when `paginate` is set to `true`. Related to #1105. Sample output: ~/code/jekyll/tsite$ ../bin/jekyll build --trace Configuration file: /Users/parker/code/jekyll/tsite/_config.yml Config Warning: The `paginate` key must be a positive integer or nil. It's currently set to 'true'. Source: /Users/parker/code/jekyll/tsite Destination: /Users/parker/code/jekyll/tsite/_site Generating... done. --- lib/jekyll/configuration.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 5b5dda4b..b560aa1d 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -150,7 +150,7 @@ module Jekyll $stderr.puts "#{err}" end - configuration.backwards_compatibilize + configuration.fix_common_issues.backwards_compatibilize end # Public: Split a CSV string into an array containing its values @@ -205,5 +205,17 @@ module Jekyll config end + def fix_common_issues + config = clone + + if config.has_key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 0) + Jekyll.logger.warn "Config Warning:", "The `paginate` key must be a" + + " positive integer or nil. It's currently set to '#{config['paginate'].inspect}'." + config['paginate'] = nil + end + + config + end + end end From d19c6983f281e9d78e51344fbc01d0aaa58312f8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 21:04:15 +0200 Subject: [PATCH 3/4] paginate option cannot be 0. --- lib/jekyll/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index b560aa1d..e00db8b1 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -208,7 +208,7 @@ module Jekyll def fix_common_issues config = clone - if config.has_key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 0) + if config.has_key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 1) Jekyll.logger.warn "Config Warning:", "The `paginate` key must be a" + " positive integer or nil. It's currently set to '#{config['paginate'].inspect}'." config['paginate'] = nil From 46b0d5037b213a9e1f5640b4922e2c9feb5aa382 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 21:22:08 +0200 Subject: [PATCH 4/4] Add test for Configuration#fix_common_issues --- test/test_configuration.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_configuration.rb b/test/test_configuration.rb index 0e6372b0..c57408e5 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -79,6 +79,20 @@ class TestConfiguration < Test::Unit::TestCase assert_equal @config.backwards_compatibilize["include"], %w[STOP_THE_PRESSES.txt .heloses .git] end end + context "#fix_common_issues" do + setup do + @config = Proc.new do |val| + Configuration[{ + 'paginate' => val + }] + end + end + should "sets an invalid 'paginate' value to nil" do + assert_nil @config.call(0).fix_common_issues['paginate'] + assert_nil @config.call(-1).fix_common_issues['paginate'] + assert_nil @config.call(true).fix_common_issues['paginate'] + end + end context "loading configuration" do setup do @path = File.join(Dir.pwd, '_config.yml')