Module: Nesta::Navigation::Renderers

Defined in:
lib/nesta/navigation.rb

Instance Method Summary collapse

Instance Method Details



32
33
34
35
36
37
38
39
40
# File 'lib/nesta/navigation.rb', line 32

def breadcrumb_ancestors
  ancestors = []
  page = @page
  while page
    ancestors << page
    page = page.parent
  end
  ancestors.reverse
end


55
56
57
# File 'lib/nesta/navigation.rb', line 55

def breadcrumb_label(page)
  (page.abspath == '/') ? 'Home' : page.heading
end

#display_breadcrumbs(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nesta/navigation.rb', line 42

def display_breadcrumbs(options = {})
  haml_tag :ul, :class => options[:class] do
    breadcrumb_ancestors[0...-1].each do |page|
      haml_tag :li do
        haml_tag :a, :href => page.abspath do
          haml_concat breadcrumb_label(page)
        end
      end
    end
    haml_tag(:li) { haml_concat breadcrumb_label(@page) }
  end
end

#display_menu(menu, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/nesta/navigation.rb', line 4

def display_menu(menu, options = {})
  defaults = { :class => nil, :levels => 2 }
  options = defaults.merge(options)
  if options[:levels] > 0
    haml_tag :ul, :class => options[:class] do
      menu.each do |item|
        display_menu_item(item, options)
      end
    end
  end
end

#display_menu_item(item, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nesta/navigation.rb', line 16

def display_menu_item(item, options = {})
  if item.respond_to?(:each)
    if (options[:levels] - 1) > 0
      haml_tag :li do
        display_menu(item, :levels => (options[:levels] - 1))
      end
    end
  else
    haml_tag :li do
      haml_tag :a, :<, :href => item.abspath do
        haml_concat item.heading
      end
    end
  end
end