Skip to content

Commit

Permalink
Navigation between meals, using meal titles
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Jun 11, 2009
1 parent c9018d6 commit 74928db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion features/browse_meals.feature
@@ -1,7 +1,7 @@
Feature: Browse Meals

So that I can find meals made on special occasions
As a person interested in finding meals
As a person interested in exploring meals and how they drive certain recipes
I want to browse meals by date

Scenario: Browsing a meal in a given year
Expand Down
5 changes: 4 additions & 1 deletion helpers.rb
Expand Up @@ -132,7 +132,10 @@ def link_to_adjacent_view_date(current, couch_view, options={})

if next_result
next_uri = next_result['key'].gsub(/-/, '/')
link_text = block_given? ? yield(next_result['key']) : next_result['key']
link_text = block_given? ?
yield(next_result['key'], next_result['value']) :
next_result['key']

%Q|<a href="/meals/#{next_uri}">#{link_text}</a>|
else
""
Expand Down
8 changes: 4 additions & 4 deletions spec/eee_helpers_spec.rb
Expand Up @@ -237,13 +237,13 @@
:href => "/meals/2009/05",
:content => "foo")
end
it "should link to block text + date, if block is given" do
link_to_adjacent_view_date("2009-04", @count_by_month) do |date|
"foo #{date} bar"
it "should link to the CouchDB view's key and value, if block is given" do
link_to_adjacent_view_date("2009-04", @count_by_month) do |date, value|
"foo #{date} bar #{value} baz"
end.
should have_selector("a",
:href => "/meals/2009/05",
:content => "foo 2009-05 bar")
:content => "foo 2009-05 bar 3 baz")
end
end
end
Expand Down
17 changes: 14 additions & 3 deletions spec/views/meal.haml_spec.rb
Expand Up @@ -14,8 +14,10 @@
'description' => @description,
'menu' => ["Peanut Butter and Jelly Sandwich"]
}
assigns[:meals_by_date] = [{"key" => "2009-05-15", "value" => []},
{"key" => "2009-05-31", "value" => []}]
assigns[:meals_by_date] = [{ "key" => "2009-05-15",
"value" => ['2009-05-15', "Foo"] },
{ "key" => "2009-05-31",
"value" => ["2009-05-31", "Bar"] }]
end

it "should display a breadcrumb link to the other meals in this year" do
Expand All @@ -37,7 +39,16 @@

it "should link to previous meal" do
render("/views/meal.haml")
response.should have_selector("a", :href => "/meals/2009/05/15")
response.should have_selector("a",
:href => "/meals/2009/05/15",
:content => "May 15, 2009")
end

it "should link to previous meal title" do
render("/views/meal.haml")
response.should have_selector("a",
:href => "/meals/2009/05/15",
:content => "Foo")
end

it "should display the meal's summary" do
Expand Down
6 changes: 4 additions & 2 deletions views/meal.haml
Expand Up @@ -6,9 +6,11 @@
= @meal['title']

%div.navigation
=link_to_adjacent_view_date(@meal['date'], @meals_by_date, :previous => true)
&lsaquo;
=link_to_adjacent_view_date(@meal['date'], @meals_by_date, :previous => true) { |d,v| Date.parse(d).strftime("#{v[1]} (%B %e, %Y)") }
|
=link_to_adjacent_view_date(@meal['date'], @meals_by_date)
=link_to_adjacent_view_date(@meal['date'], @meals_by_date) { |d,v| Date.parse(d).strftime("#{v[1]} (%B %e, %Y)") }
&rsaquo;

#summary
= wiki @meal['summary']
Expand Down
4 changes: 2 additions & 2 deletions views/meal_by_month.haml
Expand Up @@ -5,9 +5,9 @@
%h1= "Meals from #{month_text(@month)}"

%div.navigation
=link_to_adjacent_view_date(@month, @count_by_year, :previous => true) { |d| month_text(d) }
=link_to_adjacent_view_date(@month, @count_by_year, :previous => true) { |d,v| month_text(d) }
|
=link_to_adjacent_view_date(@month, @count_by_year) { |d| month_text(d) }
=link_to_adjacent_view_date(@month, @count_by_year) { |d,v| month_text(d) }

.meals
- @meals["rows"].each do |meal_result|
Expand Down

0 comments on commit 74928db

Please sign in to comment.