diff --git a/frontend/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb similarity index 93% rename from frontend/app/helpers/spree/base_helper.rb rename to core/app/helpers/spree/base_helper.rb index fb659074a46..cc4af9161c1 100644 --- a/frontend/app/helpers/spree/base_helper.rb +++ b/core/app/helpers/spree/base_helper.rb @@ -1,6 +1,21 @@ module Spree module BaseHelper + def available_countries + checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone]) + + if checkout_zone && checkout_zone.kind == 'country' + countries = checkout_zone.country_list + else + countries = Country.all + end + + countries.collect do |country| + country.name = Spree.t(country.iso, scope: 'country_names', default: country.name) + country + end.sort_by { |c| c.name.parameterize } + end + # Defined because Rails' current_page? helper is not working when Spree is mounted at root. def current_spree_page?(url) path = request.fullpath.gsub(/^\/\//, '/') @@ -12,9 +27,30 @@ def current_spree_page?(url) return false end - # human readable list of variant options - def variant_options(v, options={}) - v.options_text + def display_price(product_or_variant) + product_or_variant.price_in(current_currency).display_price.to_html + end + + def gem_available?(name) + Gem::Specification.find_by_name(name) + rescue Gem::LoadError + false + rescue + Gem.available?(name) + end + + def link_to_tracking(shipment, options = {}) + return unless shipment.tracking && shipment.shipping_method + + if shipment.tracking_url + link_to(shipment.tracking, shipment.tracking_url, options) + else + content_tag(:span, shipment.tracking) + end + end + + def logo(image_path=Spree::Config[:logo]) + link_to image_tag(image_path), spree.root_path end def meta_data @@ -43,51 +79,6 @@ def meta_data_tags end.join("\n") end - def body_class - @body_class ||= content_for?(:sidebar) ? 'two-col' : 'one-col' - @body_class - end - - def logo(image_path=Spree::Config[:logo]) - link_to image_tag(image_path), spree.root_path - end - - def available_countries - checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone]) - - if checkout_zone && checkout_zone.kind == 'country' - countries = checkout_zone.country_list - else - countries = Country.all - end - - countries.collect do |country| - country.name = Spree.t(country.iso, scope: 'country_names', default: country.name) - country - end.sort_by { |c| c.name.parameterize } - end - - def seo_url(taxon) - return spree.nested_taxons_path(taxon.permalink) - end - - def gem_available?(name) - Gem::Specification.find_by_name(name) - rescue Gem::LoadError - false - rescue - Gem.available?(name) - end - - def display_price(product_or_variant) - product_or_variant.price_in(current_currency).display_price.to_html - end - - def pretty_time(time) - [I18n.l(time.to_date, format: :long), - time.strftime("%l:%M %p")].join(" ") - end - def method_missing(method_name, *args, &block) if image_style = image_style_from_method_name(method_name) define_image_method(image_style) @@ -97,26 +88,21 @@ def method_missing(method_name, *args, &block) end end - def link_to_tracking(shipment, options = {}) - return unless shipment.tracking && shipment.shipping_method - - if shipment.tracking_url - link_to(shipment.tracking, shipment.tracking_url, options) - else - content_tag(:span, shipment.tracking) - end + def pretty_time(time) + [I18n.l(time.to_date, format: :long), time.strftime("%l:%M %p")].join(" ") end - private + def seo_url(taxon) + return spree.nested_taxons_path(taxon.permalink) + end - # Returns style of image or nil - def image_style_from_method_name(method_name) - if method_name.to_s.match(/_image$/) && style = method_name.to_s.sub(/_image$/, '') - possible_styles = Spree::Image.attachment_definitions[:attachment][:styles] - style if style.in? possible_styles.with_indifferent_access - end + # human readable list of variant options + def variant_options(v, options={}) + v.options_text end + private + def create_product_image_tag(image, product, options, style) options.reverse_merge! alt: image.alt.blank? ? product.name : image.alt image_tag image.attachment.url(style), options @@ -140,5 +126,13 @@ def define_image_method(style) end end end + + # Returns style of image or nil + def image_style_from_method_name(method_name) + if method_name.to_s.match(/_image$/) && style = method_name.to_s.sub(/_image$/, '') + possible_styles = Spree::Image.attachment_definitions[:attachment][:styles] + style if style.in? possible_styles.with_indifferent_access + end + end end end diff --git a/frontend/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb similarity index 99% rename from frontend/spec/helpers/base_helper_spec.rb rename to core/spec/helpers/base_helper_spec.rb index 743cca5f22c..36a92ae58fc 100644 --- a/frontend/spec/helpers/base_helper_spec.rb +++ b/core/spec/helpers/base_helper_spec.rb @@ -66,7 +66,6 @@ it "should raise NoMethodError when style is not exists" do expect { another_strange_image(product) }.to raise_error(NoMethodError) end - end context "link_to_tracking" do @@ -128,7 +127,6 @@ def link_to_tracking_html(options = {}) it "should raise NoMethodError when statement with name equal to style name called" do expect { foobar(product) }.to raise_error(NoMethodError) end - end context "pretty_time" do diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rb index 1a48e462dfb..4d8e24fdea0 100644 --- a/frontend/app/helpers/spree/frontend_helper.rb +++ b/frontend/app/helpers/spree/frontend_helper.rb @@ -1,5 +1,10 @@ module Spree module FrontendHelper + def body_class + @body_class ||= content_for?(:sidebar) ? 'two-col' : 'one-col' + @body_class + end + def breadcrumbs(taxon, separator=" ") return "" if current_page?("/") || taxon.nil? separator = raw(separator)