Module: SiteMap::ViewHelpers

Defined in:
lib/site_map/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#display_crumbs(options = {}) ⇒ Object



30
31
32
33
# File 'lib/site_map/view_helpers.rb', line 30

def display_crumbs(options = {})
  options[:html] ||= {:class => "breadcrumb"}
  self.display_joined_view_nodes(@view_node.self_and_ancestors, options)
end

#display_joined_view_nodes(view_nodes, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/site_map/view_helpers.rb', line 38

def display_joined_view_nodes(view_nodes, options = {})
  options = {
    :connector => " > ",
    :html => true
  }.merge(options)
  display_view_nodes = view_nodes.collect do |view_node|
    if options[:html]
      html_options = options[:html].kind_of?(::Hash) ? options[:html] : {}
      (:a, view_node_label(view_node), html_options.merge({
        :href => view_node_url(view_node)
      }))
    else
      view_node_label(view_node)
    end
  end
  display_connector = if options[:html]
    (:span, options[:connector])
  else
    options[:connector]
  end
  display_view_nodes.join(display_connector)
end

#display_menuObject



34
35
36
# File 'lib/site_map/view_helpers.rb', line 34

def display_menu

end

#display_title(options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/site_map/view_helpers.rb', line 25

def display_title(options = {})
  self.display_joined_view_nodes([@view_node.parent, @view_node], options.merge({
    :html => false
  }))
end

#view_node_label(view_node) ⇒ Object

subbing hash options into view node label, code thanks to kelredd-useful



10
11
12
13
14
15
16
# File 'lib/site_map/view_helpers.rb', line 10

def view_node_label(view_node)
  label_string = view_node.label.dup
  view_node_label_options.each do |label_key, value|
    label_string.gsub!(":#{label_key}", value.to_s)
  end
  label_string
end

#view_node_label_optionsObject

Override in view scope to resolve against your labels



5
6
7
# File 'lib/site_map/view_helpers.rb', line 5

def view_node_label_options
  {}
end

#view_node_url(view_node) ⇒ Object



17
18
19
# File 'lib/site_map/view_helpers.rb', line 17

def view_node_url(view_node)
  eval(view_node.url.to_s)
end

#view_node_visible(view_node) ⇒ Object Also known as: view_node_visible?



20
21
22
# File 'lib/site_map/view_helpers.rb', line 20

def view_node_visible(view_node)
  eval(view_node.visible.to_s)
end