Module: EffectiveMenusHelper

Defined in:
app/helpers/effective_menus_helper.rb

Instance Method Summary collapse

Instance Method Details



41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/effective_menus_helper.rb', line 41

def breadcrumbs_fallback(page = @page, root: 'Home')
  label = (page if page.kind_of?(Effective::Page)) || @page_title || 'Here'

  (:ol, class: 'breadcrumb') do
    [
      (:li, link_to(root, root_path, title: root), class: 'breadcrumb-item'),
      (:li, label, class: 'breadcrumb-item active', 'aria-current': 'page')
    ].join.html_safe
  end
end


35
36
37
38
39
# File 'app/helpers/effective_menus_helper.rb', line 35

def breadcrumbs_root_url(page = @page, root: 'Home')
  (:ol, class: 'breadcrumb') do
    (:li, root, class: 'breadcrumb-item active', 'aria-current': 'page')
  end
end

#render_breadcrumbs(menu, page = @page, root: 'Home') ⇒ Object Also known as: render_breadcrumb



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/effective_menus_helper.rb', line 15

def render_breadcrumbs(menu, page = @page, root: 'Home')
  return breadcrumbs_root_url(page, root: root) if request.path == '/'
  return breadcrumbs_fallback(page, root: root) unless page.kind_of?(Effective::Page)

  parents = [page.menu_parent].compact

  (:ol, class: 'breadcrumb') do
    (
      [(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item')] +
      parents.map do |page|
        url = (page.menu_url.presence || effective_pages.page_path(page))
        (:li, link_to(page, url, title: page.title), class: 'breadcrumb-item')
      end +
      [(:li, page, class: 'breadcrumb-item active', 'aria-current': 'page')]
    ).join.html_safe
  end
end

#render_menu(name, options = {}, &block) ⇒ Object



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

def render_menu(name, options = {}, &block)
  name = name.to_s
  menu = Array(EffectivePages.menus).find { |menu| menu.to_s == name }

  if menu.blank?
    raise("unable to find menu #{name}. Please add it to config/initializers/effective_pages.rb")
  end

  (:ul, options) { render('effective/pages/menu', menu: menu) }
end