Module: Www::BreadcrumbHelper

Defined in:
app/helpers/www/breadcrumb_helper.rb

Instance Method Summary collapse

Instance Method Details

#absolute_url(url, scheme: 'https', host: WEB_HOSTNAME_WITHOUT_PORT, port: APP_PORT_NUMBER) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/www/breadcrumb_helper.rb', line 27

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



16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/www/breadcrumb_helper.rb', line 16

def cart_breadcrumb(links = [], options = {})
  # 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: options[:style] || '' })
end

#formatted_breadcrumb(links = [], options = {}) ⇒ Object

https://schema.org/BreadcrumbList
Pass array containing link info [{ url: 'https://www.gohere.com', name: 'website' }, ...]



4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/www/breadcrumb_helper.rb', line 4

def formatted_breadcrumb(links = [], options = {})
  # 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: options[:style] || '' })
end

#product_line_breadcrumb(product_line) ⇒ Object



40
41
42
43
44
45
# File 'app/helpers/www/breadcrumb_helper.rb', line 40

def product_line_breadcrumb(product_line)
  return unless product_line

  plp = Www::ProductLinePresenter.new(product_line, self)
  formatted_breadcrumb plp.breadcrumb_links_array
end