Module: BreadcrumbsHelper

Defined in:
app/helpers/breadcrumbs_helper.rb

Instance Method Summary collapse

Instance Method Details



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/breadcrumbs_helper.rb', line 36

def breadcrumb_lis_for_breadcrumb_hashes( breadcrumbs )
  breadcrumbs.collect do |breadcrumb|
    css_class = "crumb"
    css_class = "root crumb" if breadcrumb == breadcrumbs.first
    css_class = "last crumb" if breadcrumb == breadcrumbs.last
    css_class += " slim" if breadcrumb[ :slim ]
    c =  :li, :class => css_class do

      # Do not use turbolinks for external links, since they are directed by the PagesController.
      # The redirect to external sites causes a 'forbidden' error when using turbolinks.
      #
      if breadcrumb[:navable].kind_of?(Page) && breadcrumb[:navable].redirect_to.kind_of?(String)
        link_options = {'data-no-turbolink' => true}
      else
        link_options = {}
      end

      link_to breadcrumb[ :title ], breadcrumb[ :navable ], link_options
    end
    unless breadcrumb == breadcrumbs.last
      c+=  :li, " ".html_safe, :class => "crumb sep"
    end
    c
  end.join.html_safe
end

This returns the html code for an unordered list containing the bread crumb elements.



7
8
9
# File 'app/helpers/breadcrumbs_helper.rb', line 7

def breadcrumb_ul
  cached_breadcrumb_ul
end


20
21
22
23
24
25
# File 'app/helpers/breadcrumbs_helper.rb', line 20

def breadcrumb_ul_for_navable( navable )
   :ul do
    breadcrumbs = navable.nav_node.breadcrumbs   # => [ { title: 'foo', navable: ... }, ... ]
    breadcrumb_lis_for_breadcrumb_hashes( breadcrumbs )
  end
end


27
28
29
30
31
32
33
34
# File 'app/helpers/breadcrumbs_helper.rb', line 27

def breadcrumb_ul_for_navables( navables = [] )
  breadcrumbs = navables.collect do |navable|
    breadcrumb = { title: navable.title, navable: navable }
  end
   :ul do
    breadcrumb_lis_for_breadcrumb_hashes( breadcrumbs )
  end
end

#cached_breadcrumb_ulObject



11
12
13
14
# File 'app/helpers/breadcrumbs_helper.rb', line 11

def cached_breadcrumb_ul
  return cached_breadcrumb_ul_for_navable @navable if @navable
  return breadcrumb_ul_for_navables @navables if @navables
end

#cached_breadcrumb_ul_for_navable(navable) ⇒ Object



16
17
18
# File 'app/helpers/breadcrumbs_helper.rb', line 16

def cached_breadcrumb_ul_for_navable(navable)
  Rails.cache.fetch([navable, 'breadcrumb_ul_for_navable', navable.ancestors_cache_key]) { breadcrumb_ul_for_navable(navable) }
end