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
63
64
65
66
67
68
69
70
|
# File 'app/helpers/spree/base_helper.rb', line 63
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
|
# File 'app/helpers/spree/base_helper.rb', line 19
def display_price(product_or_variant)
product_or_variant.price_in(current_currency).display_price.to_html
end
|
#link_to_tracking(shipment, options = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/helpers/spree/base_helper.rb', line 23
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
33
34
35
|
# File 'app/helpers/spree/base_helper.rb', line 33
def logo(image_path=Spree::Config[:logo])
link_to image_tag(image_path), spree.root_path
end
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/helpers/spree/base_helper.rb', line 37
def meta_data
object = instance_variable_get('@'+controller_name.singularize)
meta = {}
if object.kind_of? ActiveRecord::Base
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
|
57
58
59
60
61
|
# File 'app/helpers/spree/base_helper.rb', line 57
def meta_data_tags
meta_data.map do |name, content|
tag('meta', name: name, content: content)
end.join("\n")
end
|
#pretty_time(time) ⇒ Object
72
73
74
|
# File 'app/helpers/spree/base_helper.rb', line 72
def pretty_time(time)
[I18n.l(time.to_date, format: :long), time.strftime("%l:%M %p")].join(" ")
end
|
#seo_url(taxon) ⇒ Object
76
77
78
|
# File 'app/helpers/spree/base_helper.rb', line 76
def seo_url(taxon)
return spree.nested_taxons_path(taxon.permalink)
end
|
#variant_options(v, options = {}) ⇒ Object
human readable list of variant options
81
82
83
|
# File 'app/helpers/spree/base_helper.rb', line 81
def variant_options(v, options={})
v.options_text
end
|