Module: Spree::FrontendHelper

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

Instance Method Summary collapse

Instance Method Details

#body_classObject



3
4
5
6
# File 'app/helpers/spree/frontend_helper.rb', line 3

def body_class
  @body_class ||= content_for?(:sidebar) ? 'two-col' : 'one-col'
  @body_class
end


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/spree/frontend_helper.rb', line 8

def breadcrumbs(taxon, separator=" ")
  return "" if current_page?("/") || taxon.nil?
  separator = raw(separator)
  crumbs = [(:li, (:span, link_to((:span, Spree.t(:home), itemprop: "name"), spree.root_path, itemprop: "url") + separator, itemprop: "item"), itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement")]
  if taxon
    crumbs << (:li, (:span, link_to((:span, Spree.t(:products), itemprop: "name"), spree.products_path, itemprop: "url") + separator, itemprop: "item"), itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement")
    crumbs << taxon.ancestors.collect { |ancestor| (:li, (:span, link_to((:span, ancestor.name, itemprop: "name"), seo_url(ancestor), itemprop: "url") + separator, itemprop: "item"), itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement") } unless taxon.ancestors.empty?
    crumbs << (:li, (:span, link_to((:span, taxon.name, itemprop: "name") , seo_url(taxon), itemprop: "url"), itemprop: "item"), class: 'active', itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement")
  else
    crumbs << (:li, (:span, Spree.t(:products), itemprop: "item"), class: 'active', itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement")
  end
  crumb_list = (:ol, raw(crumbs.flatten.map{|li| li.mb_chars}.join), class: 'breadcrumb', itemscope: "itemscope", itemtype: "https://schema.org/BreadcrumbList")
  (:nav, crumb_list, id: 'breadcrumbs', class: 'col-md-12')
end

#checkout_progressObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/spree/frontend_helper.rb', line 23

def checkout_progress
  states = @order.checkout_steps
  items = states.map do |state|
    text = Spree.t("order_state.#{state}").titleize

    css_classes = []
    current_index = states.index(@order.state)
    state_index = states.index(state)

    if state_index < current_index
      css_classes << 'completed'
      text = link_to text, checkout_state_path(state)
    end

    css_classes << 'next' if state_index == current_index + 1
    css_classes << 'active' if state == @order.state
    css_classes << 'first' if state_index == 0
    css_classes << 'last' if state_index == states.length - 1
    # No more joined classes. IE6 is not a target browser.
    # Hack: Stops <a> being wrapped round previous items twice.
    if state_index < current_index
      ('li', text, class: css_classes.join(' '))
    else
      ('li', ('a', text), class: css_classes.join(' '))
    end
  end
  ('ul', raw(items.join("\n")), class: 'progress-steps nav nav-pills nav-justified', id: "checkout-step-#{@order.state}")
end

#flash_messages(opts = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/spree/frontend_helper.rb', line 52

def flash_messages(opts = {})
  ignore_types = ["order_completed"].concat(Array(opts[:ignore_types]).map(&:to_s) || [])

  flash.each do |msg_type, text|
    unless ignore_types.include?(msg_type)
      concat( :div, text, class: "alert alert-#{msg_type}")
    end
  end
  nil
end


63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/spree/frontend_helper.rb', line 63

def link_to_cart(text = nil)
  text = text ? h(text) : Spree.t('cart')
  css_class = nil

  if simple_current_order.nil? or simple_current_order.item_count.zero?
    text = "<span class='glyphicon glyphicon-shopping-cart'></span> #{text}: (#{Spree.t('empty')})"
    css_class = 'empty'
  else
    text = "<span class='glyphicon glyphicon-shopping-cart'></span> #{text}: (#{simple_current_order.item_count})  <span class='amount'>#{simple_current_order.display_total.to_html}</span>"
    css_class = 'full'
  end

  link_to text.html_safe, spree.cart_path, :class => "cart-info #{css_class}"
end

#store_menu?Boolean

helper to determine if its appropriate to show the store menu

Returns:

  • (Boolean)


79
80
81
# File 'app/helpers/spree/frontend_helper.rb', line 79

def store_menu?
  %w{thank_you}.exclude? params[:action]
end

#taxons_tree(root_taxon, current_taxon, max_level = 1) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'app/helpers/spree/frontend_helper.rb', line 83

def taxons_tree(root_taxon, current_taxon, max_level = 1)
  return '' if max_level < 1 || root_taxon.leaf?
   :div, class: 'list-group' do
    root_taxon.children.map do |taxon|
      css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'list-group-item active' : 'list-group-item'
      link_to(taxon.name, seo_url(taxon), class: css_class) + taxons_tree(taxon, current_taxon, max_level - 1)
    end.join("\n").html_safe
  end
end