Skip to content

Commit

Permalink
string format breadcrumb tag
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Feb 25, 2011
2 parents 6838411 + a6e230d commit d3f3bab
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 deletions.
14 changes: 12 additions & 2 deletions app/models/archive_page.rb
Expand Up @@ -25,8 +25,18 @@ def existing_child_types
}

def child_path(child)
date = child.published_at || Time.now
clean_path "#{ path }/#{ date.strftime '%Y/%m/%d' }/#{ child.slug }"
@year, @month, @day = $1, ($2 || 1).to_i, ($3 || 1).to_i if child.request and child.request.request_uri =~ %r{/(\d{4})(?:/(\d{2})(?:/(\d{2}))?)?/?$}
date = (@year ? Date.new(@year.to_i, @month, @day) : (child.published_at || Time.now))

if ArchiveYearIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y' }/"
elsif ArchiveMonthIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y/%m' }/"
elsif ArchiveDayIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y/%m/%d/' }/"
else
clean_url "#{ url }/#{ date.strftime '%Y/%m/%d' }/#{ child.slug }"
end
end
alias_method :child_url, :child_path

Expand Down
18 changes: 10 additions & 8 deletions lib/archive_index_tags_and_methods.rb
Expand Up @@ -6,13 +6,15 @@ module ArchiveIndexTagsAndMethods
tag.expand
end

tag "title" do |tag|
setup_date_parts
page = tag.locals.page
unless @year.nil?
Date.new((@year || 1).to_i, (@month || 1).to_i, (@day || 1).to_i).strftime(page.title)
else
page.title
[:title, :breadcrumb].each do |method|
tag method.to_s do |tag|
setup_date_parts
page = tag.locals.page
unless @year.nil?
Date.new((@year || 1).to_i, (@month || 1).to_i, (@day || 1).to_i).strftime(page.send(method))
else
page.send(method)
end
end
end

Expand Down Expand Up @@ -54,4 +56,4 @@ def setup_date_parts
@year, @month, @day = $1, $2, $3 if request_uri =~ %r{/(\d{4})(?:/(\d{2})(?:/(\d{2}))?)?/?$}
end

end
end
10 changes: 9 additions & 1 deletion spec/models/archive_day_index_page_spec.rb
Expand Up @@ -19,4 +19,12 @@
it "should render the <r:title /> tag with interpolated date" do
@page.should render('<r:title />').as('June 09, 2000 Archive').on('/archive/2000/06/09/')
end
end

it "should render the <r:breadcrumb /> tag with interpolated date" do
@page.should render('<r:breadcrumb />').as('June 09, 2000 Archive').on('/archive/2000/06/09/')
end

it "should render the <r:url /> tag with interpolated date" do
@page.should render('<r:url />').as('/archive/2000/06/09/').on('/archive/2000/06/09')
end
end
10 changes: 9 additions & 1 deletion spec/models/archive_month_index_page_spec.rb
Expand Up @@ -19,4 +19,12 @@
it "should render the <r:title /> tag with interpolated date" do
@page.should render('<r:title />').as('June 2000 Archive').on('/archive/2000/06/')
end
end

it "should render the <r:breadcrumb /> tag with interpolated date" do
@page.should render('<r:breadcrumb />').as('June 2000 Archive').on('/archive/2000/06/')
end

it "should render the <r:url /> tag with interpolated date" do
@page.should render('<r:url />').as('/archive/2000/06/').on('/archive/2000/06')
end
end
8 changes: 4 additions & 4 deletions spec/models/archive_page_spec.rb
Expand Up @@ -14,19 +14,19 @@
end

it "should find the year index" do
archive.find_by_url('/archive/2000/').should == pages(:year_index)
archive.find_by_path('/archive/2000/').should == pages(:year_index)
end

it "should find the month index" do
archive.find_by_url('/archive/2000/06/').should == pages(:month_index)
archive.find_by_path('/archive/2000/06/').should == pages(:month_index)
end

it "should find the day index" do
archive.find_by_url('/archive/2000/06/09/').should == pages(:day_index)
archive.find_by_path('/archive/2000/06/09/').should == pages(:day_index)
end

it "should find child URLs from the homepage" do
pages(:home).find_by_url('/archive/2000/01/01/article-1/').should == pages(:article_1)
pages(:home).find_by_path('/archive/2000/01/01/article-1/').should == pages(:article_1)
end

its(:single_use_children){ should == [ArchiveDayIndexPage, ArchiveMonthIndexPage, ArchiveYearIndexPage, FileNotFoundPage]}
Expand Down
11 changes: 10 additions & 1 deletion spec/models/archive_year_index_page_spec.rb
Expand Up @@ -19,4 +19,13 @@
it "should render the <r:title /> tag with interpolated date" do
@page.should render('<r:title />').as('2000 Archive').on('/archive/2000')
end
end

it "should render the <r:breadcrumb /> tag with interpolated date" do
@page.should render('<r:breadcrumb />').as('2000 Archive').on('/archive/2000')
end

it "should render the <r:url /> tag with interpolated date" do
@page.should render('<r:url />').as('/archive/2000/').on('/archive/2000')
end

end

0 comments on commit d3f3bab

Please sign in to comment.