Skip to content

Commit

Permalink
Changing to the template permalink system, only test_post passing so far
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 25, 2009
1 parent 73fa7dc commit 288d504
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
25 changes: 23 additions & 2 deletions lib/jekyll/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 44 additions & 15 deletions test/test_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 288d504

Please sign in to comment.