Skip to content

Commit

Permalink
Alternate preparations of recipes, including styling
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Sep 16, 2009
1 parent 852075d commit aa8ed89
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 7 deletions.
13 changes: 13 additions & 0 deletions 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);
}
}
}
5 changes: 5 additions & 0 deletions couch/_design/recipes/views/titles/map.js
@@ -0,0 +1,5 @@
function(doc) {
if (doc['type'] == 'Recipe') {
emit(doc['_id'], doc['title']);
}
}
2 changes: 1 addition & 1 deletion features/recipe_alternate_preparations.feature
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helpers.rb
Expand Up @@ -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|<span class="label">Alternate Preparations:</span> | +
Expand Down
6 changes: 6 additions & 0 deletions public/stylesheets/style.css
Expand Up @@ -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; }
10 changes: 10 additions & 0 deletions public/stylesheets/style.less
Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions spec/eee_helpers_spec.rb
Expand Up @@ -570,7 +570,7 @@
end
end

describe "alternative_preparations" do
describe "alternate_preparations" do
before(:each) do
stub!(:couch_alternatives).
and_return([])
Expand All @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/views/recipe.haml_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions views/recipe.haml
Expand Up @@ -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
Expand Down

0 comments on commit aa8ed89

Please sign in to comment.