diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 024bd1578..2014f5e11 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -37,3 +37,4 @@ submit the change with your pull request. - Gary Traffanstedt / [blimey85](https://github.com/blimey85) - Yaw Boakye / [yawboakye](https://github.com/yawboakye) - Ryan Clark / [IAMRYO](https://github.com/IAMRYO) +- Marty Hines / [martyhines](https://github.com/martyhines) diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml new file mode 100644 index 000000000..02d56b856 --- /dev/null +++ b/app/views/crops/_find_seeds.html.haml @@ -0,0 +1,19 @@ +%h4 Find seeds +- if crop.seeds.empty? + %p + There are no seeds available to trade. +- else + %ul + - crop.seeds.tradable.each do |seed| + %li + = link_to seed.owner, seed.owner + - if seed.owner.location + in #{seed.owner.location} + - else + (location unknown) + will trade #{seed.tradable_to}. + = link_to "View details.", seed_path(seed) +- if current_member + = link_to "List your seeds to trade.", new_seed_path() +- else + = render :partial => 'shared/signin_signup', :locals => { :to => 'list your seeds to trade' } diff --git a/app/views/crops/_photos.html.haml b/app/views/crops/_photos.html.haml new file mode 100644 index 000000000..664911723 --- /dev/null +++ b/app/views/crops/_photos.html.haml @@ -0,0 +1,6 @@ +- if !crop.photos.empty? + %ul.thumbnails + .row + - crop.photos.first(4).each do |p| + %li.span2 + = render :partial => "photos/thumbnail", :locals => { :photo => p } diff --git a/app/views/crops/_planting_advice.html.haml b/app/views/crops/_planting_advice.html.haml new file mode 100644 index 000000000..4a44502e7 --- /dev/null +++ b/app/views/crops/_planting_advice.html.haml @@ -0,0 +1,10 @@ +- if crop.planted_from.length > 0 + %p + Plant from: + - planted_from = crop.planted_from.sort_by {|s, freq| freq }.reverse + = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") +- if crop.sunniness.length > 0 + %p + Plant in: + - sunniness = crop.sunniness.sort_by {|s, freq| freq }.reverse + = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") diff --git a/app/views/crops/_varieties.html.haml b/app/views/crops/_varieties.html.haml new file mode 100644 index 000000000..e268ac7b4 --- /dev/null +++ b/app/views/crops/_varieties.html.haml @@ -0,0 +1,12 @@ +- if crop.parent + %p + = crop.system_name + is a variety of + = succeed "." do + = link_to crop.parent, crop.parent +- if crop.varieties.count > 0 + %p + Varieties of + = succeed ":" do + = crop.system_name + != crop.varieties.map{ |c| link_to c, c }.join(", ") diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index c46485f3e..253ec758f 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -2,28 +2,11 @@ .row .span9 - - if @crop.parent - %p - = @crop.system_name - is a variety of - = succeed "." do - = link_to @crop.parent, @crop.parent - - if @crop.varieties.count > 0 - %p - Varieties of - = succeed ":" do - = @crop.system_name - != @crop.varieties.map{ |c| link_to c, c }.join(", ") - - if @crop.planted_from.length > 0 - %p - Plant from: - - planted_from = @crop.planted_from.sort_by {|s, freq| freq }.reverse - = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") - - if @crop.sunniness.length > 0 - %p - Plant in: - - sunniness = @crop.sunniness.sort_by {|s, freq| freq }.reverse - = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") + = render :partial => 'photos', :locals => { :crop => @crop } + + = render :partial => 'varieties', :locals => { :crop => @crop } + + = render :partial => 'planting_advice', :locals => { :crop => @crop } %p - if @crop.plantings_count > 0 @@ -71,26 +54,9 @@ %p - if can? :edit, @crop = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-mini' } + %h4 More information %ul %li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url - %h4 Find seeds - - if @crop.seeds.empty? - %p - There are no seeds available to trade. - - else - %ul - - @crop.seeds.tradable.each do |seed| - %li - = link_to seed.owner, seed.owner - - if seed.owner.location - in #{seed.owner.location} - - else - (location unknown) - will trade #{seed.tradable_to}. - = link_to "View details.", seed_path(seed) - - if current_member - = link_to "List your seeds to trade.", new_seed_path() - - else - = render :partial => 'shared/signin_signup', :locals => { :to => 'list your seeds to trade' } + = render :partial => 'find_seeds', :locals => { :crop => @crop } diff --git a/app/views/photos/_thumbnail.html.haml b/app/views/photos/_thumbnail.html.haml new file mode 100644 index 000000000..e0526d8cd --- /dev/null +++ b/app/views/photos/_thumbnail.html.haml @@ -0,0 +1,9 @@ +.thumbnail(style='height: 220px') + = link_to image_tag(photo.thumbnail_url, :alt => photo.title, :class => 'img-rounded'), photo + %p + = link_to photo.title, photo + %br/ + %small + %i + by + = link_to photo.owner, photo.owner diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index a2d0c8870..91d6282a7 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -54,12 +54,7 @@ - @planting.photos.each do |p| - c += 1 %li.span2 - .thumbnail(style='height: 220px') - = link_to image_tag(p.thumbnail_url, :alt => p.title, :class => 'img-rounded'), p - %p - = link_to p.title, p - by - = link_to p.owner, p.owner + = render :partial => 'photos/thumbnail', :locals => { :photo => p } - if (c % 6) == 0 .row - if can? :create, Photo and can? :edit, @planting diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 281806091..dd79a443a 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -9,6 +9,30 @@ describe "crops/show" do assign(:crop, @crop) end + context 'photos' do + before(:each) do + @planting = FactoryGirl.create(:planting, :crop => @crop) + @photo1 = FactoryGirl.create(:photo) + @photo2 = FactoryGirl.create(:photo) + @photo3 = FactoryGirl.create(:photo) + @photo4 = FactoryGirl.create(:photo) + @planting.photos << [@photo1, @photo2, @photo3, @photo4] + render + end + + it 'shows 4 photos across the top of the page' do + assert_select "div.thumbnail>a>img", :count => 4 + end + + it 'links to the photo detail page' do + assert_select "a[href=#{photo_path(@photo1)}]" + end + + it 'links to the photo owner' do + assert_select "a[href=#{member_path(@photo1.owner)}]" + end + end + it "shows the wikipedia URL" do render assert_select("a[href=#{@crop.en_wikipedia_url}]", 'Wikipedia (English)')