From aa8ed89f65cb2d412f38bedcdf322f5efdf65dc1 Mon Sep 17 00:00:00 2001 From: eee-c Date: Wed, 16 Sep 2009 05:38:16 -0400 Subject: [PATCH] Alternate preparations of recipes, including styling --- couch/_design/recipes/views/alternatives/map.js | 13 +++++++++++++ couch/_design/recipes/views/titles/map.js | 5 +++++ features/recipe_alternate_preparations.feature | 2 +- helpers.rb | 2 +- public/stylesheets/style.css | 6 ++++++ public/stylesheets/style.less | 10 ++++++++++ spec/eee_helpers_spec.rb | 10 +++++----- spec/views/recipe.haml_spec.rb | 1 + views/recipe.haml | 2 ++ 9 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 couch/_design/recipes/views/alternatives/map.js create mode 100644 couch/_design/recipes/views/titles/map.js diff --git a/couch/_design/recipes/views/alternatives/map.js b/couch/_design/recipes/views/alternatives/map.js new file mode 100644 index 0000000..afed28f --- /dev/null +++ b/couch/_design/recipes/views/alternatives/map.js @@ -0,0 +1,13 @@ +function(doc) { + if (doc['type'] == 'Alternative') { + for (var i=0; i < doc['recipes'].length; i++) { + var alternatives = []; + for (var j=0; j < doc['recipes'].length; j++) { + if (i != j) { + alternatives.push(doc['recipes'][j]); + } + } + emit(doc['recipes'][i], alternatives); + } + } +} diff --git a/couch/_design/recipes/views/titles/map.js b/couch/_design/recipes/views/titles/map.js new file mode 100644 index 0000000..7499510 --- /dev/null +++ b/couch/_design/recipes/views/titles/map.js @@ -0,0 +1,5 @@ +function(doc) { + if (doc['type'] == 'Recipe') { + emit(doc['_id'], doc['title']); + } +} diff --git a/features/recipe_alternate_preparations.feature b/features/recipe_alternate_preparations.feature index 67db0f9..c55dc8d 100644 --- a/features/recipe_alternate_preparations.feature +++ b/features/recipe_alternate_preparations.feature @@ -16,7 +16,7 @@ Feature: Alternate preparations for recipes Given a "Hearty Pancake" recipe with "wheat germ" And a "Buttermilk Pancake" recipe with "buttermilk" And a "Pancake" recipe with "chocolate chips" - When the three pancake recipes are alternate preparations of each other + And the three pancake recipes are alternate preparations of each other And I visit the "Hearty Pancake" recipe Then I should see a link to the "Buttermilk Pancake" recipe And I should see a link to the "Pancake" recipe diff --git a/helpers.rb b/helpers.rb index e870bd7..08def0b 100644 --- a/helpers.rb +++ b/helpers.rb @@ -271,7 +271,7 @@ def couch_alternatives(permalink) results.first && results.first['value'] end - def alternative_preparations(permalink) + def alternate_preparations(permalink) ids = couch_alternatives(permalink) if ids && ids.size > 0 %Q|Alternate Preparations: | + diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 7a28d8c..981ad6a 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -274,3 +274,9 @@ ul#eee-categories li a.active { color: #dd0000; } height: 16.5em; width: 100%; } +#recipe-alternates { + margin: 0 8px; + padding-left: 10px; + text-indent: -10px; +} +.label { font-weight: bold; } diff --git a/public/stylesheets/style.less b/public/stylesheets/style.less index f01c019..dce1809 100644 --- a/public/stylesheets/style.less +++ b/public/stylesheets/style.less @@ -287,3 +287,13 @@ ul#eee-categories { height: 16.5em; width: 100%; } + +#recipe-alternates { + margin:0 8px; + padding-left:10px; + text-indent:-10px; +} + +.label { + font-weight: bold; +} diff --git a/spec/eee_helpers_spec.rb b/spec/eee_helpers_spec.rb index 793eee7..2ec3009 100644 --- a/spec/eee_helpers_spec.rb +++ b/spec/eee_helpers_spec.rb @@ -570,7 +570,7 @@ end end -describe "alternative_preparations" do +describe "alternate_preparations" do before(:each) do stub!(:couch_alternatives). and_return([]) @@ -579,10 +579,10 @@ end it "should retrieve IDs" do should_receive(:couch_alternatives).and_return([]) - alternative_preparations('2009-09-13') + alternate_preparations('2009-09-13') end it "should return nothing if there are no alternate preparations" do - alternative_preparations('2009-09-14'). + alternate_preparations('2009-09-14'). should be_nil end @@ -597,11 +597,11 @@ ]) end it "should have two links" do - alternative_preparations('2009-09-14'). + alternate_preparations('2009-09-14'). should have_selector("a", :count => 2) end it "should label the alternate preparations as such" do - alternative_preparations('2009-09-14'). + alternate_preparations('2009-09-14'). should contain("Alternate Preparations:") end end diff --git a/spec/views/recipe.haml_spec.rb b/spec/views/recipe.haml_spec.rb index 49ff507..d03767b 100644 --- a/spec/views/recipe.haml_spec.rb +++ b/spec/views/recipe.haml_spec.rb @@ -31,6 +31,7 @@ stub!(:partial) stub!(:recipe_update_of) stub!(:recipe_updated_by) + stub!(:alternate_preparations) end it "should display the recipe's title" do diff --git a/views/recipe.haml b/views/recipe.haml index 41b7250..44d2bb7 100644 --- a/views/recipe.haml +++ b/views/recipe.haml @@ -50,6 +50,8 @@ = recipe_updated_by(@recipe['_id']) %div = recipe_update_of(@recipe['_id']) +#recipe-alternates + = alternate_preparations(@recipe['_id']) - if @recipe['preparations'] %ul.preparations