Permalink
Browse files

Changing to the template permalink system, only test_post passing so far

  • Loading branch information...
1 parent 73fa7dc commit 288d5045d2fbb278505d120259bc29a6b6b9b74f @qrush qrush committed Apr 25, 2009
Showing with 67 additions and 17 deletions.
  1. +23 −2 lib/jekyll/post.rb
  2. +44 −15 test/test_post.rb
View
@@ -109,13 +109,34 @@ def permalink
self.data && self.data['permalink']
end
+ def template
+ case self.site.permalink_style
+ when :pretty
+ "/:year/:month/:day/:title"
+ when :none
+ "/:title.html"
+ when :date
+ "/:year/:month/:day/:title.html"
+ else
+ self.site.permalink_style
+ end
+ end
+
# The generated relative url of this post
# e.g. /2008/11/05/my-awesome-post.html
#
# Returns <String>
def url
- ext = self.site.permalink_style == :pretty ? '' : '.html'
- permalink || self.id + ext
+ return permalink if permalink
+
+ {
+ "year" => date.strftime("%Y"),
+ "month" => date.strftime("%m"),
+ "day" => date.strftime("%d"),
+ "title" => slug
+ }.inject(template) { |result, token|
+ result.gsub(/:#{token.first}/, token.last)
+ }
end
# The UID for this post (useful in feeds)
View
@@ -49,8 +49,7 @@ def do_render(post)
assert_equal "/2008/10/19/foo-bar.html", @post.url
end
-
- should "respect permalink" do
+ should "respect permalink in yaml front matter" do
file = "2008-12-03-permalinked-post.textile"
@post.process(file)
@post.read_yaml(@source, file)
@@ -60,27 +59,57 @@ def do_render(post)
assert_equal "my_category/permalinked-post", @post.url
end
- context "with permalink style of none" do
+
+ context "with site wide permalink" do
setup do
- @post.site.permalink_style = :none
@post.categories = []
- @post.process(@fake_file)
end
- should "process the url correctly" do
- assert_equal "/foo-bar.html", @post.url
+ context "with unspecified (date) style" do
+ setup do
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:year/:month/:day/:title.html", @post.template
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
+ end
end
- end
- context "with permalink style of pretty" do
- setup do
- @post.site.permalink_style = :pretty
- @post.categories = []
- @post.process(@fake_file)
+ context "with none style" do
+ setup do
+ @post.site.permalink_style = :none
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:title.html", @post.template
+ assert_equal "/foo-bar.html", @post.url
+ end
end
- should "process the url correctly" do
- assert_equal "/2008/10/19/foo-bar", @post.url
+ context "with pretty style" do
+ setup do
+ @post.site.permalink_style = :pretty
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:year/:month/:day/:title", @post.template
+ assert_equal "/2008/10/19/foo-bar", @post.url
+ end
+ end
+
+ context "with prefix style and no extension" do
+ setup do
+ @post.site.permalink_style = "/prefix/:title"
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/prefix/:title", @post.template
+ assert_equal "/prefix/foo-bar", @post.url
+ end
end
end

0 comments on commit 288d504

Please sign in to comment.