Module: Gretel::HelperMethods

Includes:
ActionView::Helpers::UrlHelper
Defined in:
lib/gretel/helper_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/gretel/helper_methods.rb', line 7

def self.included(base)
  base.send :helper_method, :breadcrumb_for, :breadcrumb
end

Instance Method Details



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gretel/helper_methods.rb', line 11

def breadcrumb(*args)
  options = args.extract_options!
  name, object = args[0], args[1]
  
  if name
    @_breadcrumb_name = name
    @_breadcrumb_object = object
  else
    if @_breadcrumb_name
      crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
    elsif options[:show_root_alone]
      crumb = breadcrumb_for(:root, options)
    end
  end
  
  if crumb && options[:pretext]
    crumb = options[:pretext].html_safe + " " + crumb
  end
  
  crumb
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gretel/helper_methods.rb', line 33

def breadcrumb_for(*args)
  options = args.extract_options!
  link_last = options[:link_last]
  options[:link_last] = true
  separator = (options[:separator] || ">").html_safe

  name, object = args[0], args[1]
  
  crumb = Crumbs.get_crumb(name, object)
  out = link_to_if(link_last, crumb.link.text, crumb.link.url)
  
  while parent = crumb.parent
    last_parent = parent.name
    crumb = Crumbs.get_crumb(parent.name, parent.object)
    out = link_to(crumb.link.text, crumb.link.url) + " " + separator + " " + out
  end
  
  # TODO: Refactor this
  if options[:autoroot] && name != :root && last_parent != :root
    crumb = Crumbs.get_crumb(:root)
    out = link_to(crumb.link.text, crumb.link.url) + " " + separator + " " + out
  end
  
  out
end

#controllerObject

hack because ActionView::Helpers::UrlHelper needs a controller method



4
5
# File 'lib/gretel/helper_methods.rb', line 4

def controller # hack because ActionView::Helpers::UrlHelper needs a controller method
end