Module: Spree::FrontendHelper
- Defined in:
- app/helpers/spree/frontend_helper.rb
Instance Method Summary collapse
- #body_class ⇒ Object
- #breadcrumbs(taxon, separator = " ") ⇒ Object
- #checkout_progress(numbers: false) ⇒ Object
- #flash_messages(opts = {}) ⇒ Object
- #link_to_cart(text = nil) ⇒ Object
-
#store_menu? ⇒ Boolean
helper to determine if its appropriate to show the store menu.
- #taxons_tree(root_taxon, current_taxon, max_level = 1) ⇒ Object
Instance Method Details
#body_class ⇒ Object
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 |
#breadcrumbs(taxon, separator = " ") ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/spree/frontend_helper.rb', line 8 def (taxon, separator=" ") return "" if current_page?("/") || taxon.nil? separator = raw(separator) crumbs = [content_tag(:li, content_tag(:span, link_to(content_tag(: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 << content_tag(:li, content_tag(:span, link_to(content_tag(: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| content_tag(:li, content_tag(:span, link_to(content_tag(: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 << content_tag(:li, content_tag(:span, link_to(content_tag(: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 << content_tag(:li, content_tag(:span, Spree.t(:products), itemprop: "item"), class: 'active', itemscope: "itemscope", itemtype: "https://schema.org/ListItem", itemprop: "itemListElement") end crumb_list = content_tag(:ol, raw(crumbs.flatten.map{|li| li.mb_chars}.join), class: 'breadcrumb', itemscope: "itemscope", itemtype: "https://schema.org/BreadcrumbList") content_tag(:nav, crumb_list, id: 'breadcrumbs', class: 'col-md-12') end |
#checkout_progress(numbers: false) ⇒ Object
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 51 |
# File 'app/helpers/spree/frontend_helper.rb', line 23 def checkout_progress(numbers: false) states = @order.checkout_steps items = states.each_with_index.map do |state, i| text = Spree.t("order_state.#{state}").titleize text.prepend("#{i.succ}. ") if numbers 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 content_tag('li', text, class: css_classes.join(' ')) else content_tag('li', content_tag('a', text), class: css_classes.join(' ')) end end content_tag('ul', raw(items.join("\n")), class: 'progress-steps nav nav-pills nav-justified', id: "checkout-step-#{@order.state}") end |
#flash_messages(opts = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/spree/frontend_helper.rb', line 53 def (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(content_tag :div, text, class: "alert alert-#{msg_type}") end end nil end |
#link_to_cart(text = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/spree/frontend_helper.rb', line 64 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
80 81 82 |
# File 'app/helpers/spree/frontend_helper.rb', line 80 def %w{thank_you}.exclude? params[:action] end |
#taxons_tree(root_taxon, current_taxon, max_level = 1) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/spree/frontend_helper.rb', line 84 def taxons_tree(root_taxon, current_taxon, max_level = 1) return '' if max_level < 1 || root_taxon.leaf? content_tag :div, class: 'list-group' do taxons = 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 safe_join(taxons, "\n") end end |