Module: Represent::NavigationHelper

Defined in:
lib/represent/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/represent/navigation_helper.rb', line 50

def breadcrumb(current_url, options, &block)
  item = site.find_by_url(current_url)
  return "" unless item
  haml_tag :a, options.merge(:href => current_url) do
    if block_given?
      yield item
    else
      haml_concat item.title
    end
  end
  if options[:to] != current_url
    haml_concat options[:delimiter] || " » "
    next_node = options[:to].gsub(/#{current_url}\/?/, "").split("/").first
    breadcrumb("#{current_url}/#{next_node}", options, &block)
  end
end


44
45
46
47
48
# File 'lib/represent/navigation_helper.rb', line 44

def breadcrumb_for(item, options = {}, &block)
  options[:from] ||= "/" + item.url.gsub(/^\//, "").split("/").first
  options[:to] ||= item.url
  breadcrumb(options[:from], options, &block)
end


4
5
6
7
8
9
10
# File 'lib/represent/navigation_helper.rb', line 4

def menu_for(item, options = {}, &block)
  if item.respond_to?(:children) && !item.children.blank?
    menu_tag(item.children, options, &block)
  else
    menu_tag(item, options, &block)
  end
end
  • menu_tag(c(:menu)) do |attributes, node|

- attributes = “one two” - node



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/represent/navigation_helper.rb', line 15

def menu_tag(array, options = {}, &block)
  return "" if array.empty?
  menu_attributes = nil
  if options.has_key?(:menu_attributes)
    menu_attributes = options[:menu_attributes]
    options.delete(:menu_attributes)
  end
  haml_tag :ul, menu_attributes do
    array.each_with_index do |node, i|
      attributes = options.has_key?(:li_attributes) ? options[:li_attributes] : {}
      attributes[:class] ||= ""
      if i == 0 and options.has_key?(:first)
        attributes[:class] << " #{options[:first]}"
      elsif i == array.length - 1 and options.has_key?(:last)
        attributes[:class] << " #{options[:last]}"
      end
      haml_tag :li, attributes do
        if block_given?
          yield node
        else
          haml_concat node.title
        end
        next unless (node.respond_to?(:children))
        menu_tag(node.children, options, &block)
      end
    end
  end
end