From 20a837d15cf63172d22312fefdd0d5ce65867349 Mon Sep 17 00:00:00 2001 From: uu59 Date: Mon, 29 Apr 2013 01:41:22 +0900 Subject: [PATCH] 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)