Module: Www::BreadcrumbHelper
- Defined in:
- app/helpers/www/breadcrumb_helper.rb
Overview
View helper: breadcrumb.
Instance Method Summary collapse
- #absolute_url(url, scheme: 'https', host: WEB_HOSTNAME_WITHOUT_PORT, port: APP_PORT_NUMBER) ⇒ Object
- #cart_breadcrumb(links = [], options = {}) ⇒ Object
-
#formatted_breadcrumb(links = [], options = {}) ⇒ Object
https://schema.org/BreadcrumbList Pass array containing link info [{ url: 'https://www.gohere.com', name: 'website' }, ...].
- #product_line_breadcrumb(product_line) ⇒ Object
Instance Method Details
#absolute_url(url, scheme: 'https', host: WEB_HOSTNAME_WITHOUT_PORT, port: APP_PORT_NUMBER) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/www/breadcrumb_helper.rb', line 41 def absolute_url(url, scheme: 'https', host: WEB_HOSTNAME_WITHOUT_PORT, port: APP_PORT_NUMBER) clean_url = Addressable::URI.unencode(url.to_s) uri = Addressable::URI.parse(clean_url) uri.host ||= host uri.scheme ||= scheme uri.port ||= port uri.port = nil if uri.port&.in?([443, 80]) uri.to_s rescue StandardError logger.error "Unable to parse #{url} in absolute_url method" nil end |
#cart_breadcrumb(links = [], options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/www/breadcrumb_helper.rb', line 30 def (links = [], = {}) # return unless links.present? links = links.map do |l| # Url has to be present, so by default put the requested original url # typically this will be the last link in your list pointing to itself # l[:url] = request.original_url if l[:url].nil? OpenStruct.new(**l) end render(partial: '/www/cart_breadcrumb', locals: { links: links, style: [:style] || '' }) end |
#formatted_breadcrumb(links = [], options = {}) ⇒ Object
https://schema.org/BreadcrumbList
Pass array containing link info [{ url: 'https://www.gohere.com', name: 'website' }, ...]
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/www/breadcrumb_helper.rb', line 6 def (links = [], = {}) # Auto-derive a SEO-friendly page topic from the breadcrumb crumbs when # the page didn't set one explicitly. Reverses the crumb chain so the # most specific term leads — `[{name:'Floor Heating'},{name:'Bathroom'}]` # becomes "Bathroom Floor Heating". Downstream consumers (see # `posts_section` / `page_topic` in PageSectionsHelper) use this for # related-content section headings like "Bathroom Floor Heating Posts". # Pages can override with an explicit `page_topic 'X'` call. if @page_topic.blank? && links.is_a?(Array) && links.any? crumb_names = links.filter_map { |l| (l.is_a?(Hash) ? l[:name] : l[:name] || l['name']).to_s.strip.presence } @page_topic = crumb_names.reverse.join(' ').presence end # return unless links.present? links = links.map do |l| # Url has to be present, so by default put the requested original url # typically this will be the last link in your list pointing to itself l[:url] = request.path if l[:url].nil? OpenStruct.new(**l) end render(partial: '/www/structured_breadcrumb', locals: { links: links, style: [:style] || '' }) end |
#product_line_breadcrumb(product_line) ⇒ Object
54 55 56 57 58 59 |
# File 'app/helpers/www/breadcrumb_helper.rb', line 54 def (product_line) return unless product_line plp = Www::ProductLinePresenter.new(product_line, self) plp. end |