Module: Spree::StorefrontHelper
- Includes:
- BaseHelper, ImagesHelper, ShipmentHelper
- Included in:
- SeoController, StoreController, TaxonsController
- Defined in:
- app/helpers/spree/storefront_helper.rb
Instance Method Summary collapse
- #as_aspect_ratio(attachment) ⇒ Object
-
#page_description ⇒ String
Returns the page description for the current page.
-
#page_image ⇒ String
Returns the page image for the current page.
- #paths_equal?(path1, path2) ⇒ Boolean
-
#render_storefront_partials(section, options = {}) ⇒ String
Renders the storefront partials for the given section.
- #show_account_pane? ⇒ Boolean
- #svg_country_icon(country_code) ⇒ Object
- #tailwind_classes_for(flash_type) ⇒ Object
Instance Method Details
#as_aspect_ratio(attachment) ⇒ Object
63 64 65 66 |
# File 'app/helpers/spree/storefront_helper.rb', line 63 def as_aspect_ratio() Spree::Deprecation.warn('as_aspect_ratio is deprecated. Please use spree_asset_aspect_ratio instead.') spree_asset_aspect_ratio() end |
#page_description ⇒ String
Returns the page description for the current page.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/spree/storefront_helper.rb', line 22 def page_description return @page_description if @page_description.present? @page_description = object. if object.respond_to?(:meta_description) if @page_description.blank? && [Spree::Product, Spree::Taxon, Spree::Post].include?(object.class) @page_description = truncate((object.description.to_s).strip, length: 160, separator: ' ', escape: false) end @page_description = current_store. if @page_description.blank? @page_description end |
#page_image ⇒ String
Returns the page image for the current page. This is used for SEO, social media and Open Graph tags.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/spree/storefront_helper.rb', line 40 def page_image return @page_image if @page_image.present? if object.is_a? Spree::Product @page_image = object.default_image&. elsif object.respond_to?(:image) @page_image = object.image end @page_image ||= current_store. @page_image end |
#paths_equal?(path1, path2) ⇒ Boolean
88 89 90 91 92 93 |
# File 'app/helpers/spree/storefront_helper.rb', line 88 def paths_equal?(path1, path2) path1 = URI.parse(path1).path.chomp('/') path2 = URI.parse(path2).path.chomp('/') path1 == path2 end |
#render_storefront_partials(section, options = {}) ⇒ String
Renders the storefront partials for the given section.
13 14 15 16 17 |
# File 'app/helpers/spree/storefront_helper.rb', line 13 def render_storefront_partials(section, = {}) Rails.application.config.spree_storefront.send(section).map do |partial| render partial, end.join.html_safe end |
#show_account_pane? ⇒ Boolean
81 82 83 84 85 86 |
# File 'app/helpers/spree/storefront_helper.rb', line 81 def show_account_pane? !try_spree_current_user && defined?(spree_login_path) && !paths_equal?(canonical_path, spree_login_path) && defined?(spree_signup_path) && !paths_equal?(canonical_path, spree_signup_path) && defined?(spree_forgot_password_path) && !paths_equal?(canonical_path, spree_forgot_password_path) end |
#svg_country_icon(country_code) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/spree/storefront_helper.rb', line 68 def svg_country_icon(country_code) language_to_country = { 'en' => 'us', 'ja' => 'jp', 'uk' => 'ua' } normalized_code = country_code.to_s.downcase final_country_code = language_to_country.fetch(normalized_code, normalized_code) tag.span(class: "fi fi-#{final_country_code}") end |
#tailwind_classes_for(flash_type) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/helpers/spree/storefront_helper.rb', line 54 def tailwind_classes_for(flash_type) { notice: 'alert-notice', success: 'alert-success', error: 'alert-error', alert: 'alert-warning', }.stringify_keys[flash_type.to_s] || flash_type.to_s end |