Skip to content

Commit

Permalink
Affordances: meal dates on the homepage, read more link for the meals…
Browse files Browse the repository at this point in the history
… on the homepage, only linking to new recipes from the homepage, alternating the meal thumbnails on the homepage, older meals listed at the bottom of the homepage, categories at the top of all pages.
  • Loading branch information
eee-c committed Jun 23, 2009
1 parent 62d5dbb commit d72b4ec
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 14 deletions.
4 changes: 3 additions & 1 deletion eee.rb
Expand Up @@ -21,12 +21,14 @@
data = RestClient.get url
@meal_view = JSON.parse(data)['rows']

@meals = @meal_view[0...10].inject([]) do |memo, couch_rec|
@meals = @meal_view.inject([]) do |memo, couch_rec|
data = RestClient.get "#{@@db}/#{couch_rec['key']}"
meal = JSON.parse(data)
memo + [meal]
end

@older_meals = @meals.slice!(10,3) || []

haml :index
end

Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/site.rb
Expand Up @@ -46,7 +46,7 @@
:content_type => 'application/json'

# Update the meal to include the recipe in the menu
meal['menu'] << "[recipe:#{permalink}]"
meal['menu'] << "[recipe:#{permalink.gsub(/-/, '/')}]"
RestClient.put "#{@@db}/#{meal['_id']}",
meal.to_json,
:content_type => 'application/json'
Expand Down
2 changes: 1 addition & 1 deletion spec/eee_spec.rb
Expand Up @@ -85,7 +85,7 @@
RestClient.
should_receive(:get).
with(/2009-0/).
exactly(10).times.
exactly(13).times.
and_return('{"title":"foo",' +
'"date":"2009-06-17",' +
'"summary":"foo summary",' +
Expand Down
68 changes: 62 additions & 6 deletions spec/views/index.haml_spec.rb
Expand Up @@ -9,6 +9,7 @@
"menu" => [],
"_attachments" => {"image1.jpg" => { }}
}]
assigns[:older_meals] = []
end

it "should include the meal titles" do
Expand All @@ -23,6 +24,11 @@
:content => "Bar")
end

it "should include a pretty date for each meal" do
render("/views/index.haml")
response.should have_selector(".meals", :content => "May 15")
end

it "should include a summary of the meals" do
render("/views/index.haml")
response.should have_selector("p", :content => "Bar summary")
Expand All @@ -44,18 +50,68 @@
:height => "150")
end

it "should suggest that the user read more..." do
render("/views/index.haml")
response.should have_selector(".meals a",
:href => "/meals/2009/05/15",
:content => "Read more…")
end

it "should include a comma separated list of menu items" do
assigns[:meals][0]["menu"] << "chips"
assigns[:meals][0]["menu"] << "salsa"
stub!(:recipe_link).
and_return(%Q|<a href="/recipes/2009/05/15/recipe1">chips</a>|,
%Q|<a href="/recipes/2009/05/15/recipe2">salsa</a>|)

assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe1]"
assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe2]"

render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips, salsa")
end

it "should wikify menu items" do
assigns[:meals][0]["menu"] << "_really_ hot salsa"
it "should only include new recipe menu items" do
stub!(:recipe_link).
and_return(%Q|<a href="/recipes/2009/05/15/recipe1">chips</a>|)

assigns[:meals][0]["menu"] << "[recipe:2009/05/14/recipe1]"
assigns[:meals][0]["menu"] << "chili"
assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe2]"

render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips")
end

it "should not include a delimiter between \"Read more\" and new recipes when no new recipes" do
render("/views/index.haml")
response.should have_selector(".menu-items em",
:content => "really")
response.should_not have_selector(".meals",
:content => "|")

end

context "13 or more meals have been preared" do
before(:each) do
assigns[:meals] =
[{ "_id" => "2009-05-15",
"date" => "2009-05-15",
"title" => "Bar",
"summary" => "Bar summary",
"menu" => [],
"_attachments" => {"image1.jpg" => { }}
}] * 10

assigns[:older_meals] =
[{ "_id" => "2009-04-15",
"date" => "2009-04-15",
"title" => "Foo"
}] * 3
end
it "should link to the next 3" do
render("/views/index.haml")
response.should have_selector("a",
:href => "/meals/2009/04/15",
:content => "Foo")
end
end
end
30 changes: 25 additions & 5 deletions views/index.haml
@@ -1,10 +1,30 @@
.meals

%h1 Meals
- @meals.each do |meal|
- date = Date.parse(meal['date'])
%a{:href => date.strftime("/meals/%Y/%m/%d")}
= image_link meal, :width => 200, :height => 150
%h2
%div{:class => "meal meal#{date.day % 2}"}
%a{:href => date.strftime("/meals/%Y/%m/%d")}
= image_link meal, :width => 200, :height => 150
%h2
%a{:href => date.strftime("/meals/%Y/%m/%d")}= meal["title"]
%div= date.strftime("%B %e")
= wiki(meal["summary"])

- new_recipe_regexp = Regexp.new(date.strftime("%Y/%m/%d"))
- new_recipes = meal["menu"].select{ |r| r =~ new_recipe_regexp }
(
%a{:href => date.strftime("/meals/%Y/%m/%d")}
Read more&hellip;
- if new_recipes.length > 0
|
%span.menu-items= wiki(new_recipes.join(", "))
)
.other-meals
%i Older meals:
- @older_meals.each do |meal|
- date = Date.parse(meal['date'])
%a{:href => date.strftime("/meals/%Y/%m/%d")}= meal["title"]
= wiki(meal["summary"])
.menu-items= wiki(meal["menu"].join(", "))
,
- date = Date.parse(@meals[0]['date'])
%a{:href => date.strftime("/meals/%Y/%m")} More&hellip;
2 changes: 2 additions & 0 deletions views/meal_by_month.haml
@@ -1,3 +1,5 @@
= categories({})

- date = Date.parse("#{@month}-01")
.breadcrumbs
= breadcrumbs(date, :month)
Expand Down
2 changes: 2 additions & 0 deletions views/meal_by_year.haml
@@ -1,3 +1,5 @@
= categories({})

- date = Date.parse("#{@year}-01-01")
.breadcrumbs
= breadcrumbs(date, :year)
Expand Down
2 changes: 2 additions & 0 deletions views/no_results.haml
@@ -1,3 +1,5 @@
= categories({})

%form{:method => "get", :action => "/recipes/search"}
%input{:type => "text", :value => @query, :name => "query", :size => 31, :maxlength => 2048}
%input{:type => "submit", :value => "Search", :name => "s"}
Expand Down
2 changes: 2 additions & 0 deletions views/search.haml
@@ -1,3 +1,5 @@
= categories({})

%table
%tr
%th
Expand Down

0 comments on commit d72b4ec

Please sign in to comment.