Module: Spree::StorefrontHelper

Includes:
BaseHelper
Included in:
SeoController, StoreController, TaxonsController
Defined in:
app/helpers/spree/storefront_helper.rb

Instance Method Summary collapse

Instance Method Details

#as_aspect_ratio(attachment) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/spree/storefront_helper.rb', line 49

def as_aspect_ratio(attachment)
  return unless attachment.present?
  return unless attachment.analyzed?

   = attachment.
  aspect_ratio = ['aspect_ratio'].presence

  return aspect_ratio if aspect_ratio

  width = ['width']&.to_f
  return unless width

  height = ['height']&.to_f
  return unless height

  width / height
end

#page_descriptionObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/spree/storefront_helper.rb', line 12

def page_description
  return @page_description if @page_description.present?

  @page_description = object.meta_description if object.respond_to?(:meta_description)

  if @page_description.blank? && [Spree::Product, Spree::Taxon, Spree::Post].include?(object.class)
    @page_description = truncate(strip_tags(object.description.to_s).strip, length: 160, separator: ' ', escape: false)
  end

  @page_description = current_store.meta_description if @page_description.blank?

  @page_description
end

#page_imageObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/spree/storefront_helper.rb', line 26

def page_image
  return @page_image if @page_image.present?

  if object.is_a? Spree::Product
    @page_image = object.default_image&.attachment
  elsif object.respond_to?(:image)
    @page_image = object.image
  end

  @page_image ||= current_store.social_image

  @page_image
end

#paths_equal?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'app/helpers/spree/storefront_helper.rb', line 79

def paths_equal?(path1, path2)
  path1 = URI.parse(path1).path.chomp('/')
  path2 = URI.parse(path2).path.chomp('/')

  path1 == path2
end

#render_storefront_partials(section) ⇒ Object



6
7
8
9
10
# File 'app/helpers/spree/storefront_helper.rb', line 6

def render_storefront_partials(section)
  Rails.application.config.spree_storefront.send(section).map do |partial|
    render partial: partial
  end.join.html_safe
end

#show_account_pane?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'app/helpers/spree/storefront_helper.rb', line 72

def 
  !try_spree_current_user &&
    (defined?() && !paths_equal?(canonical_path, )) &&
    (defined?() && !paths_equal?(canonical_path, )) &&
    (defined?(spree_forgot_password_path) && !paths_equal?(canonical_path, spree_forgot_password_path))
end

#svg_country_icon(country_code) ⇒ Object



67
68
69
70
# File 'app/helpers/spree/storefront_helper.rb', line 67

def svg_country_icon(country_code)
  country_code = :us if country_code.to_s.downcase == 'en'
  tag.span(class: "fi fi-#{country_code.downcase}")
end

#tailwind_classes_for(flash_type) ⇒ Object



40
41
42
43
44
45
46
47
# File 'app/helpers/spree/storefront_helper.rb', line 40

def tailwind_classes_for(flash_type)
  {
    notice: 'alert-notice',
    success: 'alert-success',
    error: 'alert-error',
    alert: 'alert-warning',
  }.stringify_keys[flash_type.to_s] || flash_type.to_s
end