From 6478d9cb1b4646c40ded2cbf786e6ff308456cd2 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 10:31:45 +1300 Subject: [PATCH 1/6] Haml clean up for crops views --- app/views/crops/_find_seeds.html.haml | 5 +- app/views/crops/_form.html.haml | 3 +- app/views/crops/_grown_for.html.haml | 4 +- app/views/crops/_harvests.html.haml | 5 +- app/views/crops/_hierarchy.html.haml | 2 +- app/views/crops/_image_with_popover.html.haml | 20 +++----- app/views/crops/_index_card.html.haml | 11 ++-- app/views/crops/_photos.html.haml | 4 +- app/views/crops/_planting_advice.html.haml | 8 +-- app/views/crops/_plantings.html.haml | 4 +- app/views/crops/_popover.html.haml | 2 +- app/views/crops/_scientific_names.html.haml | 4 +- app/views/crops/_thumbnail.html.haml | 6 ++- app/views/crops/_varieties.html.haml | 6 +-- app/views/crops/_wrangle.html.haml | 9 ++-- app/views/crops/edit.html.haml | 25 +++++++--- app/views/crops/hierarchy.html.haml | 2 +- app/views/crops/index.html.haml | 8 ++- app/views/crops/index.rss.haml | 4 +- app/views/crops/new.html.haml | 23 ++++++--- app/views/crops/requested.haml | 4 +- app/views/crops/search.html.haml | 7 ++- app/views/crops/show.html.haml | 50 +++++++++++-------- app/views/crops/wrangle.html.haml | 13 ++--- 24 files changed, 136 insertions(+), 93 deletions(-) diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml index 80e92397a..8aa34ec8f 100644 --- a/app/views/crops/_find_seeds.html.haml +++ b/app/views/crops/_find_seeds.html.haml @@ -11,7 +11,10 @@ %p = link_to "View all #{crop.name} seeds", seeds_by_crop_path(crop) %p - = link_to "Purchase seeds via Ebay", "http://rover.ebay.com/rover/1/705-53470-19255-0/1?icep_ff3=9&pub=5575213277&toolid=10001&campid=5337940151&customid=&icep_uq=#{URI.escape crop.name}&icep_sellerId=&icep_ex_kw=&icep_sortBy=12&icep_catId=181003&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229515&kwid=902099&mtid=824&kw=lg", target: "_blank", rel: "noopener noreferrer" + = link_to "Purchase seeds via Ebay", + "http://rover.ebay.com/rover/1/705-53470-19255-0/1?icep_ff3=9&pub=5575213277&toolid=10001&campid=5337940151&customid=&icep_uq=#{URI.escape crop.name}&icep_sellerId=&icep_ex_kw=&icep_sortBy=12&icep_catId=181003&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229515&kwid=902099&mtid=824&kw=lg", + target: "_blank", + rel: "noopener noreferrer" - if crop.approved? - if current_member %p= link_to "List #{crop.name} seeds to trade", new_seed_path(crop_id: crop.id) diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index d5495046a..41b89478d 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -104,7 +104,7 @@ .form-group = f.label :reason_for_rejection, 'Reason for rejection', class: 'control-label col-md-2' .col-md-8 - = f.select(:reason_for_rejection, @crop.reasons_for_rejection, { include_blank: true }, { class: 'form-control' }) + = f.select(:reason_for_rejection, @crop.reasons_for_rejection, include_blank: true, class: 'form-control') .form-group = f.label :rejection_notes, 'Rejection notes', class: 'control-label col-md-2' @@ -113,7 +113,6 @@ %span.help-block Please provide additional notes why this crop request was rejected if the above reasons do not apply. - .form-group .form-actions.col-md-offset-2.col-md-8 = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/crops/_grown_for.html.haml b/app/views/crops/_grown_for.html.haml index e1d8544f7..fed0eba7e 100644 --- a/app/views/crops/_grown_for.html.haml +++ b/app/views/crops/_grown_for.html.haml @@ -3,5 +3,5 @@ - if crop.harvests.empty? not known. - else - - popular_plant_parts = crop.popular_plant_parts.sort_by {|s, freq| freq }.reverse - != popular_plant_parts.map {|p, freq| link_to(p, p) + " (#{freq})" }.join(", ") + - popular_plant_parts = crop.popular_plant_parts.sort_by { |_s, freq| freq }.reverse + != popular_plant_parts.map { |p, freq| link_to(p, p) + " (#{freq})" }.join(", ") diff --git a/app/views/crops/_harvests.html.haml b/app/views/crops/_harvests.html.haml index 3935aed96..4a70bb251 100644 --- a/app/views/crops/_harvests.html.haml +++ b/app/views/crops/_harvests.html.haml @@ -1,4 +1,4 @@ -%h4 #{ crop.name.capitalize } harvests +%h4 #{crop.name.capitalize} harvests - if crop.harvests.empty? %p Nobody has harvested this crop yet. @@ -17,5 +17,4 @@ - if current_member %p= link_to "Harvest #{crop.name}", new_harvest_path(crop_id: crop.id) - else - = render partial: 'shared/signin_signup', locals: {to: "track your #{crop.name} harvests" } - + = render partial: 'shared/signin_signup', locals: { to: "track your #{crop.name} harvests" } diff --git a/app/views/crops/_hierarchy.html.haml b/app/views/crops/_hierarchy.html.haml index c53c7c5ed..19be51f6d 100644 --- a/app/views/crops/_hierarchy.html.haml +++ b/app/views/crops/_hierarchy.html.haml @@ -3,7 +3,7 @@ - unless defined? max - max = 0 # list all without "show all" toggle button - display_crops.each do |c| - %li.crop-hierarchy{ class: max != 0 && @count >= max ? ['hide', 'toggle'] : []} + %li.crop-hierarchy{ class: max != 0 && @count >= max ? ['hide', 'toggle'] : [] } = link_to c, c - @count += 1 - if c.varieties.present? diff --git a/app/views/crops/_image_with_popover.html.haml b/app/views/crops/_image_with_popover.html.haml index 0b9e969e0..6744ccfe1 100644 --- a/app/views/crops/_image_with_popover.html.haml +++ b/app/views/crops/_image_with_popover.html.haml @@ -1,13 +1,9 @@ - cache crop do - = link_to | - image_tag( | - crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png', | - :alt => crop.name, | - :class => 'image-responsive crop-image' | - ), | - crop, | - :rel => "popover", | - 'data-trigger' => 'hover', | - 'data-title' => crop.name, | - 'data-content' => "#{ render :partial => 'crops/popover', :locals => { :crop => crop } }", | - 'data-html' => true | + = link_to image_tag(crop.default_photo.present? ? crop.default_photo.thumbnail_url : 'placeholder_150.png', + alt: crop.name, class: 'image-responsive crop-image'), + crop.name, + rel: "popover", + 'data-trigger': 'hover', + 'data-title': crop.name, + 'data-content': render(partial: 'crops/popover', locals: { crop: crop }), + 'data-html': true diff --git a/app/views/crops/_index_card.html.haml b/app/views/crops/_index_card.html.haml index 89a62aec5..c893148f1 100644 --- a/app/views/crops/_index_card.html.haml +++ b/app/views/crops/_index_card.html.haml @@ -1,9 +1,12 @@ .well .row .col-md-4 - = link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), alt: '', class: 'img crop-image'), crop + = link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), + alt: '', + class: 'img crop-image'), + crop .col-md-8 - %h3{:style => 'padding-top: 0px; margin-top: 0px'} + %h3{ style: 'padding-top: 0px; margin-top: 0px' } = link_to crop, crop %p @@ -16,6 +19,6 @@ by #{ENV['GROWSTUFF_SITE_NAME']} members - if can? :create, Planting - = link_to 'Plant this', new_planting_path(:params => { crop_id: crop.id }), class: 'btn btn-primary' + = link_to 'Plant this', new_planting_path(params: { crop_id: crop.id }), class: 'btn btn-primary' - if can? :create, Seed - = link_to 'Add seeds to stash', new_seed_path(:params => { crop_id: crop.id }), class: 'btn btn-primary' + = link_to 'Add seeds to stash', new_seed_path(params: { crop_id: crop.id }), class: 'btn btn-primary' diff --git a/app/views/crops/_photos.html.haml b/app/views/crops/_photos.html.haml index 78bccb781..ed49e312a 100644 --- a/app/views/crops/_photos.html.haml +++ b/app/views/crops/_photos.html.haml @@ -1,5 +1,5 @@ .row - - if !crop.photos.empty? + - unless crop.photos.empty? - crop.photos.first(3).each do |p| .col-md-4 - = render partial: "photos/thumbnail", locals: { :photo => p } + = 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 index 713e6ded8..4a444794a 100644 --- a/app/views/crops/_planting_advice.html.haml +++ b/app/views/crops/_planting_advice.html.haml @@ -3,13 +3,13 @@ - if crop.planted_from.empty? not known. - else - - planted_from = crop.planted_from.sort_by {|s, freq| freq }.reverse - = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") + - planted_from = crop.planted_from.sort_by { |_, freq| freq }.reverse + = planted_from.map { |s, freq| "#{s} (#{freq})" }.join(", ") %p %strong Plant in: - if crop.sunniness.empty? not known. - else - - sunniness = crop.sunniness.sort_by {|s, freq| freq }.reverse - = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") + - sunniness = crop.sunniness.sort_by { |_, freq| freq }.reverse + = sunniness.map { |s, freq| "#{s} (#{freq})" }.join(", ") diff --git a/app/views/crops/_plantings.html.haml b/app/views/crops/_plantings.html.haml index b8d308868..351c6ba4c 100644 --- a/app/views/crops/_plantings.html.haml +++ b/app/views/crops/_plantings.html.haml @@ -1,4 +1,4 @@ -%h4 See who's planted #{ crop.name.pluralize } +%h4 See who's planted #{crop.name.pluralize} - if crop.plantings.empty? %p Nobody has planted this crop yet. @@ -17,5 +17,5 @@ - if current_member %p= link_to "Plant #{crop.name}", new_planting_path(crop_id: crop.id) - else - = render partial: 'shared/signin_signup', locals: {to: "track your #{crop.name} plantings" } + = render partial: 'shared/signin_signup', locals: { to: "track your #{crop.name} plantings" } diff --git a/app/views/crops/_popover.html.haml b/app/views/crops/_popover.html.haml index f1d0f8937..18a77b771 100644 --- a/app/views/crops/_popover.html.haml +++ b/app/views/crops/_popover.html.haml @@ -1,6 +1,6 @@ %p %small - - if crop.scientific_names.size > 0 + - unless crop.scientific_names.empty? %i = crop.scientific_names.first.name %br/ diff --git a/app/views/crops/_scientific_names.html.haml b/app/views/crops/_scientific_names.html.haml index aa90cb357..88d93e7a5 100644 --- a/app/views/crops/_scientific_names.html.haml +++ b/app/views/crops/_scientific_names.html.haml @@ -8,9 +8,9 @@ %li = sn.name - if can? :edit, sn - = link_to 'Edit', edit_scientific_name_path(sn), { class: 'btn btn-default btn-xs' } + = link_to 'Edit', edit_scientific_name_path(sn), class: 'btn btn-default btn-xs' - if can? :destroy, sn = link_to 'Delete', sn, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' %p - if can? :edit, crop - = link_to 'Add', new_scientific_name_path( crop_id: crop.id ), { class: 'btn btn-default btn-xs' } + = link_to 'Add', new_scientific_name_path(crop_id: crop.id), class: 'btn btn-default btn-xs' diff --git a/app/views/crops/_thumbnail.html.haml b/app/views/crops/_thumbnail.html.haml index 6c0520fbe..1926b31d8 100644 --- a/app/views/crops/_thumbnail.html.haml +++ b/app/views/crops/_thumbnail.html.haml @@ -2,11 +2,13 @@ .crop-thumbnail - if crop - cache cache_key_for(Crop, crop.id) do - = link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), alt: crop.name, class: 'img'), crop + = link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), + alt: crop.name, class: 'img'), + crop .cropinfo .cropname = link_to crop.name, crop - - if crop.scientific_names.size > 0 + - unless crop.scientific_names.empty? .scientificname = crop.scientific_names.first.name .plantingcount diff --git a/app/views/crops/_varieties.html.haml b/app/views/crops/_varieties.html.haml index f5c1096c9..5cdc453ed 100644 --- a/app/views/crops/_varieties.html.haml +++ b/app/views/crops/_varieties.html.haml @@ -11,10 +11,10 @@ Varieties of #{crop.name}: - max = 5 - = render partial: 'hierarchy', locals: { display_crops:[ crop ], max: max } + = render partial: 'hierarchy', locals: { display_crops: [crop], max: max } - if max != 0 && @count > max - = button_tag "Show all #{@count-1} varieties", class: 'btn btn-link toggle crop-hierarchy' + = button_tag "Show all #{@count - 1} varieties", class: 'btn btn-link toggle crop-hierarchy' = button_tag "Show less varieties", class: 'btn btn-link toggle crop-hierarchy hide' - - if ! crop.parent and crop.varieties.empty? + - if !crop.parent && crop.varieties.empty? %p None known. diff --git a/app/views/crops/_wrangle.html.haml b/app/views/crops/_wrangle.html.haml index 47b795613..8e8f87558 100644 --- a/app/views/crops/_wrangle.html.haml +++ b/app/views/crops/_wrangle.html.haml @@ -1,4 +1,4 @@ -- if can? :edit, crop or can? :destroy, crop +- if can?(:edit, crop) || can?(:destroy, crop) %h4 Crop wrangling %p You are a @@ -6,6 +6,9 @@ %strong CROP WRANGLER %p - if can? :edit, crop - = link_to 'Edit crop', edit_crop_path(crop), { class: 'btn btn-default btn-xs' } + = link_to 'Edit crop', edit_crop_path(crop), class: 'btn btn-default btn-xs' - if can? :destroy, crop - = link_to 'Delete crop', crop, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' + = link_to 'Delete crop', crop, + method: :delete, + data: { confirm: 'Are you sure?' }, + class: 'btn btn-default btn-xs' diff --git a/app/views/crops/edit.html.haml b/app/views/crops/edit.html.haml index da8863252..1c497d838 100644 --- a/app/views/crops/edit.html.haml +++ b/app/views/crops/edit.html.haml @@ -2,18 +2,29 @@ - if @crop.approval_status == "approved" - if @crop.requester - %p Requested by #{link_to @crop.requester, @crop.requester} #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. - %p Approved by #{link_to @crop.creator, @crop.creator}. + %p + Requested by #{link_to @crop.requester, @crop.requester} + #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. + %p + Approved by #{link_to @crop.creator, @crop.creator}. - else - %p Added by #{link_to @crop.creator, @crop.creator} #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. + %p + Added by #{link_to @crop.creator, @crop.creator} + #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. - elsif @crop.approval_status == "pending" .alert.alert-danger - %p Requested by #{link_to @crop.requester, @crop.requester} #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. - %p Status: #{@crop.approval_status}. + %p + Requested by #{link_to @crop.requester, @crop.requester} + #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. + %p + Status: #{@crop.approval_status}. - elsif @crop.approval_status == "rejected" .alert.alert-danger - %p Requested by #{link_to @crop.requester, @crop.requester} #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. - %p Status: #{@crop.approval_status} by #{link_to @crop.creator, @crop.creator}. + %p + Requested by #{link_to @crop.requester, @crop.requester} + #{distance_of_time_in_words(@crop.created_at, Time.zone.now)} ago. + %p + Status: #{@crop.approval_status} by #{link_to @crop.creator, @crop.creator}. = render 'form' diff --git a/app/views/crops/hierarchy.html.haml b/app/views/crops/hierarchy.html.haml index 9f589789c..7f3bed5e5 100644 --- a/app/views/crops/hierarchy.html.haml +++ b/app/views/crops/hierarchy.html.haml @@ -6,4 +6,4 @@ = link_to "crops database", crops_path - cache cache_key_for(Crop) do - = render partial: "hierarchy", locals: { display_crops:@crops } + = render partial: "hierarchy", locals: { display_crops: @crops } diff --git a/app/views/crops/index.html.haml b/app/views/crops/index.html.haml index aa325f8e9..f0abebab9 100644 --- a/app/views/crops/index.html.haml +++ b/app/views/crops/index.html.haml @@ -15,7 +15,11 @@ = form_tag(crops_path, method: :get, class: 'form-inline', role: 'form') do .form-group = label_tag :sort, "Sort by:", class: 'sr-only' - = select_tag "sort", options_for_select({"Sort by popularity" => 'popular', "Sort alphabetically" => 'alpha'}, @sort || 'popular'), class: 'form-control' + = select_tag "sort", + options_for_select({ "Sort by popularity": 'popular', + "Sort alphabetically": 'alpha' }, + @sort || 'popular'), + class: 'form-control' = submit_tag "Show", class: 'btn btn-primary' .pagination @@ -28,7 +32,7 @@ - if can? :create, Crop %div - = link_to 'New Crop', new_crop_path, { class: 'btn btn-primary'} + = link_to 'New Crop', new_crop_path, class: 'btn btn-primary' .pagination = will_paginate @paginated_crops diff --git a/app/views/crops/index.rss.haml b/app/views/crops/index.rss.haml index bf8691b10..a8facaf56 100644 --- a/app/views/crops/index.rss.haml +++ b/app/views/crops/index.rss.haml @@ -1,11 +1,11 @@ -%rss{version: 2.0} +%rss{ version: 2.0 } %channel %title Recently added crops (#{ENV['GROWSTUFF_SITE_NAME']}) %link= crops_url - @crops.each do |crop| %item %title= crop.name - %pubDate= crop.created_at.to_s(:rfc822) + %pubdate= crop.created_at.to_s(:rfc822) %link= post_url(crop) %guid= post_url(crop) diff --git a/app/views/crops/new.html.haml b/app/views/crops/new.html.haml index bd4f6e613..86b0aad17 100644 --- a/app/views/crops/new.html.haml +++ b/app/views/crops/new.html.haml @@ -1,14 +1,23 @@ - content_for :title, (can?(:wrangle, @crop) ? "New crop" : "Suggest a crop") - unless can? :wrangler, @crop - - %p Thanks for taking the time to suggest a crop! Our crop database is managed by volunteers, and we appreciate your help. Here are some things to consider when suggesting a new crop: - + %p + Thanks for taking the time to suggest a crop! Our crop database is + managed by volunteers, and we appreciate your help. Here are some + things to consider when suggesting a new crop: %ul - %li First, you might want to #{link_to 'search our crops', crops_search_path} to make sure we don't have it already, perhaps under an alternate name. + %li + First, you might want to #{link_to 'search our crops', crops_search_path} + to make sure we don't have it already, perhaps under an alternate name. + %li + The Growstuff database only contains edible crops. In future we hope to + support other crops, but for now, if your suggestion is not edible we + won't be able to add it. - %li The Growstuff database only contains edible crops. In future we hope to support other crops, but for now, if your suggestion is not edible we won't be able to add it. - - %li At this time, we are only adding crops which have a Wikipedia page. If you want to add a specific variety of crop that doesn't have its own Wikipedia entry, please use the more general form of the crop instead and put the name of your variety in the notes/description. + %li + At this time, we are only adding crops which have a Wikipedia page. If you + want to add a specific variety of crop that doesn't have its own Wikipedia + entry, please use the more general form of the crop instead and put the name + of your variety in the notes/description. = render 'form' diff --git a/app/views/crops/requested.haml b/app/views/crops/requested.haml index 06f0b7706..bd0f1cfd5 100644 --- a/app/views/crops/requested.haml +++ b/app/views/crops/requested.haml @@ -3,7 +3,7 @@ %p Crops you have requested -%div.pagination +.pagination = will_paginate @requested .row @@ -11,5 +11,5 @@ .col-md-2.six-across = render partial: "thumbnail", locals: { crop: crop } -%div.pagination +.pagination = will_paginate @requested diff --git a/app/views/crops/search.html.haml b/app/views/crops/search.html.haml index f455dcf5d..e47f2d484 100644 --- a/app/views/crops/search.html.haml +++ b/app/views/crops/search.html.haml @@ -9,7 +9,10 @@ = form_tag crops_search_path, method: :get, id: 'crop-search', class: 'form-inline' do .form-group = label_tag :term, "Search crops:", class: 'sr-only' - = text_field_tag 'term', nil, class: 'search-query input-medium form-control', :placeholder => 'Search crops', value: @term + = text_field_tag 'term', nil, + class: 'search-query input-medium form-control', + placeholder: 'Search crops', + value: @term = submit_tag "Search", class: 'btn btn-primary' - if @matches.empty? @@ -25,7 +28,7 @@ .pagination = will_paginate @paginated_matches - %div#paginated_matches + #paginated_matches .row - @paginated_matches.each do |c| .col-md-2.six-across diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 0b1c093e9..286017b22 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -19,20 +19,23 @@ = link_to "Harvest this", new_harvest_path(crop_id: @crop.id), class: 'btn btn-default' - if can? :create, Seed - = link_to 'Add seeds to stash', new_seed_path(:params => { crop_id: @crop.id }), class: 'btn btn-default' + = link_to 'Add seeds to stash', new_seed_path(params: { crop_id: @crop.id }), class: 'btn btn-default' - if member_signed_in? = display_seed_availability(@current_member, @crop) - = link_to "View your seeds", seeds_by_owner_path(:owner => current_member.slug) + = link_to "View your seeds", seeds_by_owner_path(owner: current_member.slug) .row .col-md-9 - unless current_member - Learn how to grow #{ @crop.name.pluralize } from growers around the world. #{ ENV['GROWSTUFF_SITE_NAME'] } has tips and advice from real-life growers, including when to plant #{ @crop.name.pluralize }, how to harvest #{ @crop.name.pluralize }, and more. + Learn how to grow #{@crop.name.pluralize} from growers around the world. + #{ENV['GROWSTUFF_SITE_NAME']} has tips and advice from real-life growers, + including when to plant #{@crop.name.pluralize}, how to harvest + #{@crop.name.pluralize}, and more. = render partial: 'photos', locals: { crop: @crop } %h2 - - if @crop.plantings.size > 0 + - if !@crop.plantings.empty? = @crop.name.titleize has been planted = pluralize(@crop.plantings.size, "time") @@ -43,7 +46,7 @@ %h2 Sunniness Chart - %div#sunchart + #sunchart %h2 Crop Map @@ -52,37 +55,36 @@ - if current_member && current_member.location.blank? = link_to "Set your location.", edit_member_registration_path + #cropmap - - %div#cropmap - - %a{:name => 'posts'} - %h2 What people are saying about #{ @crop.name.pluralize } + %a{ name: 'posts' } + %h2 What people are saying about #{@crop.name.pluralize} - if @posts.empty? %p - Nobody has posted about #{ @crop.name.pluralize } yet. + Nobody has posted about #{@crop.name.pluralize} yet. %p - if can? :create, Post = link_to "Post something", new_post_path, class: 'btn btn-default' - else - = render partial: "shared/signin_signup", locals: {to: "post your tips and experiences growing #{ @crop.name.pluralize }" } + = render partial: "shared/signin_signup", + locals: { to: "post your tips and experiences growing #{@crop.name.pluralize}" } - else .pagination = page_entries_info @posts - = will_paginate @posts, :params => {:anchor => "posts"} + = will_paginate @posts, params: { anchor: "posts" } - @posts.each do |post| = render partial: "posts/single", locals: { post: post, subject: true } .pagination = page_entries_info @posts - = will_paginate @posts, :params => {:anchor => "posts"} + = will_paginate @posts, params: { anchor: "posts" } .col-md-3 = render partial: 'wrangle', locals: { crop: @crop } - %h4 How to grow #{ @crop.name.pluralize } + %h4 How to grow #{@crop.name.pluralize} = render partial: 'grown_for', locals: { crop: @crop } = render partial: 'planting_advice', locals: { crop: @crop } @@ -90,7 +92,7 @@ = render partial: 'scientific_names', locals: { crop: @crop } = render partial: 'alternate_names', locals: { crop: @crop } - %h4 #{ @crop.name.capitalize } varieties + %h4 #{@crop.name.capitalize} varieties = render partial: 'varieties', locals: { crop: @crop } = render partial: 'plantings', locals: { crop: @crop } @@ -98,13 +100,21 @@ = render partial: 'find_seeds', locals: { crop: @crop } - %h4 Learn more about #{ @crop.name.pluralize } + %h4 Learn more about #{@crop.name.pluralize} %ul %li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url, target: "_blank", rel: "noopener noreferrer" %li - = link_to "OpenFarm - Growing guide", "https://openfarm.cc/en/crops/#{URI.escape @crop.name}", target: "_blank", rel: "noopener noreferrer" + = link_to "OpenFarm - Growing guide", "https://openfarm.cc/en/crops/#{URI.escape @crop.name}", + target: "_blank", + rel: "noopener noreferrer" %li - = link_to "Gardenate - Planting reminders", "http://www.gardenate.com/plant/#{URI.escape @crop.name}", target: "_blank", rel: "noopener noreferrer" + = link_to "Gardenate - Planting reminders", "http://www.gardenate.com/plant/#{URI.escape @crop.name}", + target: "_blank", rel: "noopener noreferrer" - if current_member && current_member.location %li - = link_to "Google", "http://www.google.com/search?q=#{URI.escape ["Growing", @crop.name, current_member.location].join(" ")}", target: "_blank", rel: "noopener noreferrer" + = link_to "Google", + 'http://www.google.com/search?q=' + URI.escape(['Growing', + @crop.name, + current_member.location].join(' ')), + target: "_blank", + rel: "noopener noreferrer" diff --git a/app/views/crops/wrangle.html.haml b/app/views/crops/wrangle.html.haml index 922f00f16..fc8ba3015 100644 --- a/app/views/crops/wrangle.html.haml +++ b/app/views/crops/wrangle.html.haml @@ -17,12 +17,12 @@ .tabbable %ul.nav.nav-tabs - %li{ class: @approval_status.blank? ? 'active' : ''} + %li{ class: @approval_status.blank? ? 'active' : '' } = link_to "Recently added", wrangle_crops_path - %li{ class: @approval_status == "pending" ? 'active' : ''} - = link_to "Pending approval", wrangle_crops_path(:approval_status => "pending") - %li{ class: @approval_status == "rejected" ? 'active' : ''} - = link_to "Rejected", wrangle_crops_path(:approval_status => "rejected") + %li{ class: @approval_status == "pending" ? 'active' : '' } + = link_to "Pending approval", wrangle_crops_path(approval_status: "pending") + %li{ class: @approval_status == "rejected" ? 'active' : '' } + = link_to "Rejected", wrangle_crops_path(approval_status: "rejected") %h2 - if @approval_status == "pending" @@ -37,7 +37,8 @@ = page_entries_info @crops = will_paginate @crops -%table{ class: "table table-striped", id: @approval_status.blank? ? 'recently-added-crops' : "#{@approval_status}-crops"} +%table{ class: "table table-striped", + id: @approval_status.blank? ? 'recently-added-crops' : "#{@approval_status}-crops" } %tr %th System name %th English Wikipedia URL From 80371c835c17e77f084ed4615ab8d921797ad764 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 10:40:58 +1300 Subject: [PATCH 2/6] Moved long line (ebay url) to helper --- app/helpers/crops_helper.rb | 4 ++++ app/views/crops/_find_seeds.html.haml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/crops_helper.rb b/app/helpers/crops_helper.rb index da3f72f10..079d56598 100644 --- a/app/helpers/crops_helper.rb +++ b/app/helpers/crops_helper.rb @@ -18,4 +18,8 @@ module CropsHelper "You have an unknown quantity of seeds of this crop." end end + + def crop_ebay_seeds_url(crop) + "http://rover.ebay.com/rover/1/705-53470-19255-0/1?icep_ff3=9&pub=5575213277&toolid=10001&campid=5337940151&customid=&icep_uq=#{URI.escape crop.name}&icep_sellerId=&icep_ex_kw=&icep_sortBy=12&icep_catId=181003&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229515&kwid=902099&mtid=824&kw=lg" # rubocop:disable Metrics/LineLength + end end diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml index 8aa34ec8f..83967fc86 100644 --- a/app/views/crops/_find_seeds.html.haml +++ b/app/views/crops/_find_seeds.html.haml @@ -12,7 +12,7 @@ = link_to "View all #{crop.name} seeds", seeds_by_crop_path(crop) %p = link_to "Purchase seeds via Ebay", - "http://rover.ebay.com/rover/1/705-53470-19255-0/1?icep_ff3=9&pub=5575213277&toolid=10001&campid=5337940151&customid=&icep_uq=#{URI.escape crop.name}&icep_sellerId=&icep_ex_kw=&icep_sortBy=12&icep_catId=181003&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229515&kwid=902099&mtid=824&kw=lg", + crop_ebay_seeds_url(crop), target: "_blank", rel: "noopener noreferrer" - if crop.approved? From 43e4ed43cd25a9ba5721272157d08fe0b1043f17 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 10:46:22 +1300 Subject: [PATCH 3/6] Travis starts checking the haml that's cleaned up To stop regressions to bad haml again --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ab1dcfed6..a2675ff40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ before_script: - bundle exec rake assets:precompile script: - bundle exec rubocop --display-cop-names --rails + - bundle exec haml-lint app/views/account_types app/views/admin app/views/alternate_names app/views/account_types app/views/comments app/views/crops - script/gemfile_check - bundle exec script/check_contributors_md - bundle exec rake db:migrate --trace From 4ee789ca0668a887dd2b55c42292f97e532212e1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 10:59:40 +1300 Subject: [PATCH 4/6] Popular plant parts are now sorted by popularity --- app/models/crop.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index e923f9b50..082eee20e 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -167,7 +167,7 @@ class Crop < ActiveRecord::Base harvests.each do |h| popular_plant_parts[h.plant_part] += 1 if h.plant_part end - popular_plant_parts + popular_plant_parts.sort_by { |_s, freq| freq }.reverse end def interesting? From f37c9152affb3f57b7a3c5ae7f04722e7412bba9 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 11:21:33 +1300 Subject: [PATCH 5/6] Simplified the "grown for" view --- app/views/crops/_grown_for.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/crops/_grown_for.html.haml b/app/views/crops/_grown_for.html.haml index fed0eba7e..33465c21c 100644 --- a/app/views/crops/_grown_for.html.haml +++ b/app/views/crops/_grown_for.html.haml @@ -3,5 +3,6 @@ - if crop.harvests.empty? not known. - else - - popular_plant_parts = crop.popular_plant_parts.sort_by { |_s, freq| freq }.reverse - != popular_plant_parts.map { |p, freq| link_to(p, p) + " (#{freq})" }.join(", ") + - crop.popular_plant_parts.map do |plant_part, frequency| + = link_to plant_part.name, plant_part_path(plant_part) + (#{frequency}) From 8408fdc845b98721366bb678e1b74e65bf9cdeaa Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Feb 2017 13:22:18 +1300 Subject: [PATCH 6/6] Moved popular plant plarts calculation into sql --- app/models/crop.rb | 10 +++++----- app/views/crops/_grown_for.html.haml | 5 +++-- spec/models/crop_spec.rb | 10 ++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 082eee20e..fb55a5823 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -163,11 +163,11 @@ class Crop < ActiveRecord::Base # key: plant part (eg. 'fruit') # value: count of how many times it's been used by harvests def popular_plant_parts - popular_plant_parts = Hash.new(0) - harvests.each do |h| - popular_plant_parts[h.plant_part] += 1 if h.plant_part - end - popular_plant_parts.sort_by { |_s, freq| freq }.reverse + PlantPart.joins(:harvests) + .where("crop_id = ?", id) + .order("count_harvests_id DESC") + .group("plant_parts.id", "plant_parts.name") + .count("harvests.id") end def interesting? diff --git a/app/views/crops/_grown_for.html.haml b/app/views/crops/_grown_for.html.haml index 33465c21c..0544bdb5f 100644 --- a/app/views/crops/_grown_for.html.haml +++ b/app/views/crops/_grown_for.html.haml @@ -3,6 +3,7 @@ - if crop.harvests.empty? not known. - else - - crop.popular_plant_parts.map do |plant_part, frequency| - = link_to plant_part.name, plant_part_path(plant_part) + - crop.popular_plant_parts.each do |plant_part, frequency| + - id, name = plant_part + = link_to name, plant_part_path(id: id) (#{frequency}) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 438c6a56b..5fa9994fe 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -248,9 +248,9 @@ describe Crop do it 'counts each plant_part value' do @fruit = FactoryGirl.create(:plant_part) - @seed = FactoryGirl.create(:plant_part) - @root = FactoryGirl.create(:plant_part) - @bulb = FactoryGirl.create(:plant_part) + @seed = FactoryGirl.create(:plant_part, name: 'seed') + @root = FactoryGirl.create(:plant_part, name: 'root') + @bulb = FactoryGirl.create(:plant_part, name: 'bulb') @harvest1 = FactoryGirl.create(:harvest, crop: crop, plant_part: @fruit @@ -267,7 +267,9 @@ describe Crop do crop: crop, plant_part: @root ) - crop.popular_plant_parts.should == { @fruit => 2, @seed => 1, @root => 1 } + crop.popular_plant_parts.should == { [@fruit.id, @fruit.name] => 2, + [@seed.id, @seed.name] => 1, + [@root.id, @root.name] => 1 } end end