Module: Spree::BaseHelper

Defined in:
app/helpers/spree/base_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'app/helpers/spree/base_helper.rb', line 65

def method_missing(method_name, *args, &block)
  if image_style = image_style_from_method_name(method_name)
    define_image_method(image_style)
    send(method_name, *args)
  else
    super
  end
end

Instance Method Details

#available_countriesObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/spree/base_helper.rb', line 3

def available_countries
  checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone])

  countries = if checkout_zone && checkout_zone.kind == 'country'
                checkout_zone.country_list
              else
                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

#display_price(product_or_variant) ⇒ Object



18
19
20
21
22
23
# File 'app/helpers/spree/base_helper.rb', line 18

def display_price(product_or_variant)
  product_or_variant.
    price_in(current_currency).
    display_price_including_vat_for(current_price_options).
    to_html
end


25
26
27
28
29
30
31
32
33
# File 'app/helpers/spree/base_helper.rb', line 25

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
    (:span, shipment.tracking)
  end
end

#logo(image_path = Spree::Config[:logo]) ⇒ Object



35
36
37
# File 'app/helpers/spree/base_helper.rb', line 35

def (image_path = Spree::Config[:logo])
  link_to image_tag(image_path), spree.respond_to?(:root_path) ? spree.root_path : main_app.root_path
end

#meta_dataObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/spree/base_helper.rb', line 39

def 
  object = instance_variable_get('@' + controller_name.singularize)
  meta = {}

  if object.is_a? ApplicationRecord
    meta[:keywords] = object.meta_keywords if object[:meta_keywords].present?
    meta[:description] = object.meta_description if object[:meta_description].present?
  end

  if meta[:description].blank? && object.is_a?(Spree::Product)
    meta[:description] = truncate(strip_tags(object.description), length: 160, separator: ' ')
  end

  if meta[:keywords].blank? || meta[:description].blank?
    meta.reverse_merge!(keywords: current_store.meta_keywords,
                        description: current_store.meta_description)
  end
  meta
end

#meta_data_tagsObject



59
60
61
62
63
# File 'app/helpers/spree/base_helper.rb', line 59

def 
  .map do |name, content|
    tag('meta', name: name, content: content)
  end.join("\n")
end

#pretty_time(time) ⇒ Object



74
75
76
# File 'app/helpers/spree/base_helper.rb', line 74

def pretty_time(time)
  [I18n.l(time.to_date, format: :long), time.strftime('%l:%M %p')].join(' ')
end

#seo_url(taxon) ⇒ Object



78
79
80
# File 'app/helpers/spree/base_helper.rb', line 78

def seo_url(taxon)
  spree.nested_taxons_path(taxon.permalink)
end

#variant_options(v, _options = {}) ⇒ Object

human readable list of variant options



83
84
85
# File 'app/helpers/spree/base_helper.rb', line 83

def variant_options(v, _options = {})
  v.options_text
end