diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb new file mode 100644 index 0000000000..2906a308aa --- /dev/null +++ b/app/helpers/shared_helper.rb @@ -0,0 +1,12 @@ +module SharedHelper + def distributor_link_class(distributor) + cart = current_order(true) + @active_distributors ||= Enterprise.distributors_with_active_order_cycles + + klass = "shop-distributor" + klass += " empties-cart" unless cart.line_items.empty? || cart.distributor == distributor + klass += @active_distributors.include?(distributor) ? ' active' : ' inactive' + klass + end +end + diff --git a/app/helpers/temp_landing_page_helper.rb b/app/helpers/temp_landing_page_helper.rb index 02277e7322..fc4617f1b1 100644 --- a/app/helpers/temp_landing_page_helper.rb +++ b/app/helpers/temp_landing_page_helper.rb @@ -1,11 +1,2 @@ module TempLandingPageHelper - def temp_landing_page_distributor_link_class(distributor) - cart = current_order(true) - @active_distributors ||= Enterprise.distributors_with_active_order_cycles - - klass = "shop-distributor" - klass += " empties-cart" unless cart.line_items.empty? || cart.distributor == distributor - klass += @active_distributors.include?(distributor) ? ' active' : ' inactive' - klass - end end diff --git a/app/views/enterprises/show.html.haml b/app/views/enterprises/show.html.haml index 305f294a81..3c672b4cdd 100644 --- a/app/views/enterprises/show.html.haml +++ b/app/views/enterprises/show.html.haml @@ -12,7 +12,7 @@ %ul#supplier-distributors - if @distributors.delete @enterprise - %li= link_to "Buy direct from the farm", shop_enterprise_path(@enterprise), {class: temp_landing_page_distributor_link_class(@enterprise)} + %li= link_to "Buy direct from the farm", shop_enterprise_path(@enterprise), {class: distributor_link_class(@enterprise)} - @distributors.each do |distributor| - %li= link_to distributor.name, shop_enterprise_path(distributor), {class: temp_landing_page_distributor_link_class(distributor)} + %li= render partial: "shared/distributor", object: distributor diff --git a/app/views/home/temp_landing_page.html.haml b/app/views/home/temp_landing_page.html.haml index 848b6f2422..228837d903 100644 --- a/app/views/home/temp_landing_page.html.haml +++ b/app/views/home/temp_landing_page.html.haml @@ -29,6 +29,7 @@ .large-12.columns.centered %h3 WHERE WOULD YOU LIKE TO SHOP? %p.secondary Select your hub from the list below + - @groups.in_groups_of(4, false) do |row| .row.landing-page-row.hub_group{:class => (row.last == @groups.last ? "with-bottom-border" : "")} - row.each do |group| @@ -38,10 +39,7 @@ - group.enterprises.is_distributor.by_name.each do |distributor| .row.distributor-link-row .large-12.columns - = succeed ',' do - = link_to "#{distributor.name}".html_safe, shop_enterprise_path(distributor), {class: temp_landing_page_distributor_link_class(distributor)} - - %span.secondary= distributor.city + = render partial: "shared/distributor", object: distributor %footer .row.landing-page-row .large-6.columns.text-left diff --git a/app/views/shared/_distributor.html.haml b/app/views/shared/_distributor.html.haml new file mode 100644 index 0000000000..2712e522a1 --- /dev/null +++ b/app/views/shared/_distributor.html.haml @@ -0,0 +1,3 @@ += succeed ',' do + = link_to "#{distributor.name}".html_safe, shop_enterprise_path(distributor), {class: distributor_link_class(distributor)} +%span.secondary= distributor.city