From ad2c706a34bbfab4803be6db33d574cbf44bc4fa Mon Sep 17 00:00:00 2001 From: uu59 Date: Sun, 28 Apr 2013 02:03:08 +0900 Subject: [PATCH 1/4] Fix `jekyll serve --limit_posts n` failed --- lib/jekyll/site.rb | 3 ++- test/test_generated_site.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 1354cb67..7a4e15f0 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -27,7 +27,8 @@ module Jekyll self.include = config['include'] self.future = config['future'] self.show_drafts = config['show_drafts'] - self.limit_posts = config['limit_posts'] + # given as String if it is came from CLI option + self.limit_posts = config['limit_posts'].nil? ? nil : config["limit_posts"].to_i self.keep_files = config['keep_files'] self.reset diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index ca676861..bb6a6eb0 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -68,5 +68,15 @@ class TestGeneratedSite < Test::Unit::TestCase @site = Site.new(Jekyll.configuration) end end + + should "ensure if limit_posts is a String (from CLI option)" do + clear_dest + stub(Jekyll).configuration do + Jekyll::Configuration::DEFAULTS.merge({'limit_posts' => "3"}) + end + @site = Site.new(Jekyll.configuration) + + assert_equal 3, @site.limit_posts + end end end From 20a837d15cf63172d22312fefdd0d5ce65867349 Mon Sep 17 00:00:00 2001 From: uu59 Date: Mon, 29 Apr 2013 01:41:22 +0900 Subject: [PATCH 2/4] Change default value of limit_posts from nil to 0 (see #1004) Before this commit meaning of limit_posts: nil: no limit. generate all posts 0: raise error n ( > 0): generate n posts only n ( < 0): raise error else: raise error After this commit: nil: same as 0 0: no limit. generate all posts n ( > 0): generate n posts only n ( < 0): raise error else: almost same as 0 (depend on `to_i` result) --- lib/jekyll/configuration.rb | 2 +- lib/jekyll/site.rb | 8 ++++---- test/test_generated_site.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 24c96e0f..4bc41682 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -16,7 +16,7 @@ module Jekyll 'safe' => false, 'show_drafts' => nil, - 'limit_posts' => nil, + 'limit_posts' => 0, 'lsi' => false, 'future' => true, # remove and make true just default 'pygments' => true, # remove and make true just default diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 7a4e15f0..107b0951 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -28,7 +28,7 @@ module Jekyll self.future = config['future'] self.show_drafts = config['show_drafts'] # given as String if it is came from CLI option - self.limit_posts = config['limit_posts'].nil? ? nil : config["limit_posts"].to_i + self.limit_posts = config['limit_posts'].to_i self.keep_files = config['keep_files'] self.reset @@ -63,8 +63,8 @@ module Jekyll self.categories = Hash.new { |hash, key| hash[key] = [] } self.tags = Hash.new { |hash, key| hash[key] = [] } - if !self.limit_posts.nil? && self.limit_posts < 1 - raise ArgumentError, "Limit posts must be nil or >= 1" + if self.limit_posts < 0 + raise ArgumentError, "Limit posts must be nil or >= 0" end end @@ -149,7 +149,7 @@ module Jekyll self.posts.sort! # limit the posts if :limit_posts option is set - if limit_posts + unless limit_posts.zero? limit = self.posts.length < limit_posts ? self.posts.length : limit_posts self.posts = self.posts[-limit, limit] end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index bb6a6eb0..4d12867f 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -58,11 +58,11 @@ class TestGeneratedSite < Test::Unit::TestCase assert_equal 5, @site.posts.size end - should "ensure limit posts is 1 or more" do + should "ensure limit posts is 0 or more" do assert_raise ArgumentError do clear_dest stub(Jekyll).configuration do - Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) + Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => -1}) end @site = Site.new(Jekyll.configuration) From 94756340cd2149cc042c746d31baacbe9bc57bee Mon Sep 17 00:00:00 2001 From: uu59 Date: Mon, 29 Apr 2013 15:51:37 +0900 Subject: [PATCH 3/4] Remove to_i. Let commander gem do it #1004 --- bin/jekyll | 4 ++-- lib/jekyll/site.rb | 3 +-- test/test_generated_site.rb | 10 ---------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 0eea75e0..6d3767e6 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -48,7 +48,7 @@ command :build do |c| c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.option '--future', 'Publishes posts with a future date' - c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish' + c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' c.option '--drafts', 'Render posts in the _drafts folder' @@ -66,7 +66,7 @@ command :serve do |c| c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.option '--future', 'Publishes posts with a future date' - c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish' + c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' c.option '--drafts', 'Render posts in the _drafts folder' diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 107b0951..227f5312 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -27,8 +27,7 @@ module Jekyll self.include = config['include'] self.future = config['future'] self.show_drafts = config['show_drafts'] - # given as String if it is came from CLI option - self.limit_posts = config['limit_posts'].to_i + self.limit_posts = config['limit_posts'] self.keep_files = config['keep_files'] self.reset diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 4d12867f..09532226 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -68,15 +68,5 @@ class TestGeneratedSite < Test::Unit::TestCase @site = Site.new(Jekyll.configuration) end end - - should "ensure if limit_posts is a String (from CLI option)" do - clear_dest - stub(Jekyll).configuration do - Jekyll::Configuration::DEFAULTS.merge({'limit_posts' => "3"}) - end - @site = Site.new(Jekyll.configuration) - - assert_equal 3, @site.limit_posts - end end end From 0f52f15cc29f63ef1488e9228115b1e1ec9d3341 Mon Sep 17 00:00:00 2001 From: uu59 Date: Mon, 29 Apr 2013 21:07:46 +0900 Subject: [PATCH 4/4] Clean up code #1104 --- lib/jekyll/site.rb | 4 ++-- test/test_generated_site.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 227f5312..f64d874d 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -63,7 +63,7 @@ module Jekyll self.tags = Hash.new { |hash, key| hash[key] = [] } if self.limit_posts < 0 - raise ArgumentError, "Limit posts must be nil or >= 0" + raise ArgumentError, "limit_posts must not be a negative number" end end @@ -148,7 +148,7 @@ module Jekyll self.posts.sort! # limit the posts if :limit_posts option is set - unless limit_posts.zero? + if limit_posts > 0 limit = self.posts.length < limit_posts ? self.posts.length : limit_posts self.posts = self.posts[-limit, limit] end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 09532226..0861ee93 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -68,5 +68,16 @@ class TestGeneratedSite < Test::Unit::TestCase @site = Site.new(Jekyll.configuration) end end + + should "acceptable limit post is 0" do + assert_nothing_raised ArgumentError do + clear_dest + stub(Jekyll).configuration do + Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) + end + + @site = Site.new(Jekyll.configuration) + end + end end end