Module: Spree::BaseHelper
- Defined in:
- app/helpers/spree/base_helper.rb
Instance Method Summary collapse
- #available_countries ⇒ Object
- #body_class ⇒ Object
- #breadcrumbs(taxon, separator = " » ") ⇒ Object
- #current_orders_product_count ⇒ Object
- #flash_messages ⇒ Object
- #format_price(price, options = {}) ⇒ Object
- #link_to_cart(text = t('cart')) ⇒ Object
- #logo(image_path = ) ⇒ Object
- #meta_data_tags ⇒ Object
- #order_price(order, options = {}) ⇒ Object
-
#seo_url(taxon, product = nil) ⇒ Object
generates nested url to product based on supplied taxon.
- #stylesheet_paths ⇒ Object
- #stylesheet_tags(paths = stylesheet_paths) ⇒ Object
- #taxons_tree(root_taxon, current_taxon, max_level = 1) ⇒ Object
- #todays_short_date ⇒ Object
-
#variant_options(v, allow_back_orders = , include_style = true) ⇒ Object
human readable list of variant options.
- #yesterdays_short_date ⇒ Object
Instance Method Details
#available_countries ⇒ Object
141 142 143 144 |
# File 'app/helpers/spree/base_helper.rb', line 141 def available_countries return Country.all unless zone = Zone.find_by_name(Spree::Config[:checkout_zone]) zone.country_list end |
#body_class ⇒ Object
81 82 83 84 |
# File 'app/helpers/spree/base_helper.rb', line 81 def body_class @body_class ||= content_for?(:sidebar) ? 'two-col' : 'one-col' @body_class end |
#breadcrumbs(taxon, separator = " » ") ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/spree/base_helper.rb', line 113 def (taxon, separator=" » ") return "" if current_page?("/") || taxon.nil? separator = raw(separator) crumbs = [content_tag(:li, link_to(t(:home) , root_path) + separator)] if taxon crumbs << content_tag(:li, link_to(t('products') , products_path) + separator) crumbs << taxon.ancestors.collect { |ancestor| content_tag(:li, link_to(ancestor.name , seo_url(ancestor)) + separator) } unless taxon.ancestors.empty? crumbs << content_tag(:li, content_tag(:span, taxon.name)) else crumbs << content_tag(:li, content_tag(:span, t('products'))) end crumb_list = content_tag(:ul, raw(crumbs.flatten.map{|li| li.mb_chars}.join)) content_tag(:div, crumb_list + tag(:br, {:class => 'clear'}, false, true), :id => 'breadcrumbs') end |
#current_orders_product_count ⇒ Object
165 166 167 168 169 170 171 |
# File 'app/helpers/spree/base_helper.rb', line 165 def current_orders_product_count if current_order.blank? || current_order.item_count < 1 return 0 else return current_order.item_count end end |
#flash_messages ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/spree/base_helper.rb', line 103 def [:notice, :error].map do |msg_type| if flash[msg_type] content_tag :div, flash[msg_type], :class => "flash #{msg_type}" else '' end end.join("\n").html_safe end |
#format_price(price, options = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'app/helpers/spree/base_helper.rb', line 146 def format_price(price, ={}) .assert_valid_keys(:show_vat_text) .reverse_merge! :show_vat_text => Spree::Config[:show_price_inc_vat] formatted_price = number_to_currency price if [:show_vat_text] I18n.t(:price_with_vat_included, :price => formatted_price) else formatted_price end end |
#link_to_cart(text = t('cart')) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/spree/base_helper.rb', line 3 def link_to_cart(text = t('cart')) return "" if current_page?(cart_path) css_class = nil if current_order.nil? or current_order.line_items.empty? text = "#{text}: (#{t('empty')})" css_class = 'empty' else text = "#{text}: (#{current_order.item_count}) #{order_price(current_order)}" css_class = 'full' end link_to text, cart_path, :class => css_class end |
#logo(image_path = ) ⇒ Object
99 100 101 |
# File 'app/helpers/spree/base_helper.rb', line 99 def logo(image_path=Spree::Config[:logo]) link_to image_tag(image_path), root_path end |
#meta_data_tags ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/spree/base_helper.rb', line 67 def object = instance_variable_get('@'+controller_name.singularize) = { :keywords => Spree::Config[:default_meta_keywords], :description => Spree::Config[:default_meta_description] } if object.kind_of?(ActiveRecord::Base) [:keywords] = object. if object[:meta_keywords].present? [:description] = object. if object[:meta_description].present? end .map do |name, content| tag('meta', :name => name, :content => content) end.join("\n") end |
#order_price(order, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/spree/base_helper.rb', line 16 def order_price(order, ={}) .assert_valid_keys(:format_as_currency, :show_vat_text, :show_price_inc_vat) .reverse_merge! :format_as_currency => true, :show_vat_text => true # overwrite show_vat_text if show_price_inc_vat is false [:show_vat_text] = Spree::Config[:show_price_inc_vat] amount = order.total .delete(:format_as_currency) ? number_to_currency(amount) : amount end |
#seo_url(taxon, product = nil) ⇒ Object
generates nested url to product based on supplied taxon
158 159 160 161 162 163 |
# File 'app/helpers/spree/base_helper.rb', line 158 def seo_url(taxon, product = nil) return '/t/' + taxon.permalink if product.nil? warn "DEPRECATION: the /t/taxon-permalink/p/product-permalink urls are "+ "not used anymore. Use product_url instead. (called from #{caller[0]})" return product_url(product) end |
#stylesheet_paths ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/helpers/spree/base_helper.rb', line 90 def stylesheet_paths paths = Spree::Config[:stylesheets] if (paths.blank?) [] else paths.split(',') end end |
#stylesheet_tags(paths = stylesheet_paths) ⇒ Object
86 87 88 |
# File 'app/helpers/spree/base_helper.rb', line 86 def (paths=stylesheet_paths) paths.blank? ? '' : stylesheet_link_tag(paths, :cache => true) end |
#taxons_tree(root_taxon, current_taxon, max_level = 1) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/helpers/spree/base_helper.rb', line 128 def taxons_tree(root_taxon, current_taxon, max_level = 1) return '' if max_level < 1 || root_taxon.children.empty? content_tag :ul, :class => 'taxons-list' do root_taxon.children.map do |taxon| css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil content_tag :li, :class => css_class do link_to(taxon.name, seo_url(taxon)) + taxons_tree(taxon, current_taxon, max_level - 1) end end.join("\n").html_safe end end |
#todays_short_date ⇒ Object
28 29 30 |
# File 'app/helpers/spree/base_helper.rb', line 28 def todays_short_date utc_to_local(Time.now.utc).to_ordinalized_s(:stub) end |
#variant_options(v, allow_back_orders = , include_style = true) ⇒ Object
human readable list of variant options
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/spree/base_helper.rb', line 37 def (v, allow_back_orders = Spree::Config[:allow_backorders], include_style = true) ActiveSupport::Deprecation.warn("variant_options method is deprecated, and will be removed in 0.80.0", caller) list = v. # We shouldn't show out of stock if the product is infact in stock # or when we're not allowing backorders. unless (allow_back_orders || v.in_stock?) list = if include_style content_tag(:span, "(#{t(:out_of_stock)}) #{list}", :class => "out-of-stock") else "#{t(:out_of_stock)} #{list}" end end list end |
#yesterdays_short_date ⇒ Object
32 33 34 |
# File 'app/helpers/spree/base_helper.rb', line 32 def yesterdays_short_date utc_to_local(Time.now.utc.yesterday).to_ordinalized_s(:stub) end |