Merge pull request #263 from Skud/crop_photos

Crop photos
This commit is contained in:
Skud
2013-07-29 08:11:05 -07:00
9 changed files with 89 additions and 47 deletions

View File

@@ -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)

View File

@@ -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' }

View File

@@ -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 }

View File

@@ -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(", ")

View File

@@ -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(", ")

View File

@@ -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 }

View File

@@ -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

View File

@@ -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

View File

@@ -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)')