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/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 1354cb67..f64d874d 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -62,8 +62,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 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 - if limit_posts + 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 ca676861..0861ee93 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -58,8 +58,19 @@ 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' => -1}) + end + + @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})