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)
This commit is contained in:
uu59 2013-04-29 01:41:22 +09:00
parent ad2c706a34
commit 20a837d15c
3 changed files with 7 additions and 7 deletions

View File

@ -16,7 +16,7 @@ module Jekyll
'safe' => false, 'safe' => false,
'show_drafts' => nil, 'show_drafts' => nil,
'limit_posts' => nil, 'limit_posts' => 0,
'lsi' => false, 'lsi' => false,
'future' => true, # remove and make true just default 'future' => true, # remove and make true just default
'pygments' => true, # remove and make true just default 'pygments' => true, # remove and make true just default

View File

@ -28,7 +28,7 @@ module Jekyll
self.future = config['future'] self.future = config['future']
self.show_drafts = config['show_drafts'] self.show_drafts = config['show_drafts']
# given as String if it is came from CLI option # 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.keep_files = config['keep_files']
self.reset self.reset
@ -63,8 +63,8 @@ module Jekyll
self.categories = Hash.new { |hash, key| hash[key] = [] } self.categories = Hash.new { |hash, key| hash[key] = [] }
self.tags = Hash.new { |hash, key| hash[key] = [] } self.tags = Hash.new { |hash, key| hash[key] = [] }
if !self.limit_posts.nil? && self.limit_posts < 1 if self.limit_posts < 0
raise ArgumentError, "Limit posts must be nil or >= 1" raise ArgumentError, "Limit posts must be nil or >= 0"
end end
end end
@ -149,7 +149,7 @@ module Jekyll
self.posts.sort! self.posts.sort!
# limit the posts if :limit_posts option is set # 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 limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
self.posts = self.posts[-limit, limit] self.posts = self.posts[-limit, limit]
end end

View File

@ -58,11 +58,11 @@ class TestGeneratedSite < Test::Unit::TestCase
assert_equal 5, @site.posts.size assert_equal 5, @site.posts.size
end end
should "ensure limit posts is 1 or more" do should "ensure limit posts is 0 or more" do
assert_raise ArgumentError do assert_raise ArgumentError do
clear_dest clear_dest
stub(Jekyll).configuration do 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 end
@site = Site.new(Jekyll.configuration) @site = Site.new(Jekyll.configuration)