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
66
67
68
69
70
71
72
73
|
# File 'app/helpers/spree/base_helper.rb', line 66
def method_missing(method_name, *args, &block)
if image_style = image_style_from_method_name(method_name)
define_image_method(image_style)
self.send(method_name, *args)
else
super
end
end
|
Instance Method Details
#available_countries ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/helpers/spree/base_helper.rb', line 4
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
|
#display_price(product_or_variant) ⇒ Object
19
20
21
22
23
24
|
# File 'app/helpers/spree/base_helper.rb', line 19
def display_price(product_or_variant)
product_or_variant.
price_in(current_currency).
display_price_including_vat_for(current_price_options).
to_html
end
|
#link_to_tracking(shipment, options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'app/helpers/spree/base_helper.rb', line 26
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
|
#logo(image_path = Spree::Config[:logo]) ⇒ Object
36
37
38
|
# File 'app/helpers/spree/base_helper.rb', line 36
def logo(image_path=Spree::Config[:logo])
link_to image_tag(image_path), spree.root_path
end
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/helpers/spree/base_helper.rb', line 40
def meta_data
object = instance_variable_get('@'+controller_name.singularize)
meta = {}
if object.kind_of? 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.kind_of?(Spree::Product)
meta[:description] = truncate(strip_tags(object.description), length: 160, separator: ' ')
end
meta.reverse_merge!({
keywords: current_store.meta_keywords,
description: current_store.meta_description,
}) if meta[:keywords].blank? or meta[:description].blank?
meta
end
|
60
61
62
63
64
|
# File 'app/helpers/spree/base_helper.rb', line 60
def meta_data_tags
meta_data.map do |name, content|
tag('meta', name: name, content: content)
end.join("\n")
end
|
#pretty_time(time) ⇒ Object
75
76
77
|
# File 'app/helpers/spree/base_helper.rb', line 75
def pretty_time(time)
[I18n.l(time.to_date, format: :long), time.strftime("%l:%M %p")].join(" ")
end
|
#seo_url(taxon) ⇒ Object
79
80
81
|
# File 'app/helpers/spree/base_helper.rb', line 79
def seo_url(taxon)
return spree.nested_taxons_path(taxon.permalink)
end
|
#variant_options(v, options = {}) ⇒ Object
human readable list of variant options
84
85
86
|
# File 'app/helpers/spree/base_helper.rb', line 84
def variant_options(v, options={})
v.options_text
end
|