Skip to content
Browse files

Merge remote branch 'technoweenie/no-leading-zeroes'

Conflicts:
	lib/jekyll/post.rb
  • Loading branch information...
2 parents f6ef6f2 + e8d119e commit 5335debfb2366219f7a3b03110bd0523720fa576 @mojombo mojombo committed
Showing with 26 additions and 13 deletions.
  1. +3 −1 lib/jekyll/post.rb
  2. +23 −12 test/test_post.rb
View
4 lib/jekyll/post.rb
@@ -124,10 +124,12 @@ def url
"month" => date.strftime("%m"),
"day" => date.strftime("%d"),
"title" => CGI.escape(slug),
+ "i_day" => date.strftime("%d").to_i.to_s,
+ "i_month" => date.strftime("%m").to_i.to_s,
"categories" => categories.join('/'),
"output_ext" => self.output_ext
}.inject(template) { |result, token|
- result.gsub(/:#{token.first}/, token.last)
+ result.gsub(/:#{Regexp.escape token.first}/, token.last)
}.gsub(/\/\//, "/")
end
View
35 test/test_post.rb
@@ -18,10 +18,10 @@ def do_render(post)
end
should "ensure valid posts are valid" do
- assert Post.valid?("2008-10-19-foo-bar.textile")
- assert Post.valid?("foo/bar/2008-10-19-foo-bar.textile")
+ assert Post.valid?("2008-09-09-foo-bar.textile")
+ assert Post.valid?("foo/bar/2008-09-09-foo-bar.textile")
- assert !Post.valid?("lol2008-10-19-foo-bar.textile")
+ assert !Post.valid?("lol2008-09-09-foo-bar.textile")
assert !Post.valid?("blah")
end
@@ -31,7 +31,7 @@ def do_render(post)
@post.site = @site
@real_file = "2008-10-18-foo-bar.textile"
- @fake_file = "2008-10-19-foo-bar.textile"
+ @fake_file = "2008-09-09-foo-bar.textile"
@source = source_dir('_posts')
end
@@ -39,17 +39,17 @@ def do_render(post)
@post.categories = []
@post.process(@fake_file)
- assert_equal Time.parse("2008-10-19"), @post.date
+ assert_equal Time.parse("2008-09-09"), @post.date
assert_equal "foo-bar", @post.slug
assert_equal ".textile", @post.ext
- assert_equal "/2008/10/19", @post.dir
- assert_equal "/2008/10/19/foo-bar", @post.id
+ assert_equal "/2008/09/09", @post.dir
+ assert_equal "/2008/09/09/foo-bar", @post.id
end
should "create url based on date and title" do
@post.categories = []
@post.process(@fake_file)
- assert_equal "/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
end
should "CGI escape urls" do
@@ -106,7 +106,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
end
end
@@ -118,7 +118,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/beer/2008/09/09/foo-bar.html", @post.url
end
end
@@ -131,7 +131,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/food/beer/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/food/beer/2008/09/09/foo-bar.html", @post.url
end
end
@@ -155,7 +155,18 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title/", @post.template
- assert_equal "/2008/10/19/foo-bar/", @post.url
+ assert_equal "/2008/09/09/foo-bar/", @post.url
+ end
+ end
+
+ context "with custom date permalink" do
+ setup do
+ @post.site.permalink_style = '/:categories/:year/:i_month/:i_day/:title/'
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/2008/9/9/foo-bar/", @post.url
end
end

0 comments on commit 5335deb

Please sign in to comment.
Something went wrong with that request. Please try again.