Class: Gretel::Crumbs

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::UrlHelper
Defined in:
lib/gretel/crumbs.rb

Class Method Summary collapse

Class Method Details

.allObject



12
13
14
# File 'lib/gretel/crumbs.rb', line 12

def all
  @crumbs ||= {}
end

.controllerObject

hack because Rails.application.routes.url_helpers needs a controller method



6
7
# File 'lib/gretel/crumbs.rb', line 6

def controller # hack because Rails.application.routes.url_helpers needs a controller method
end

.crumb(name, &block) ⇒ Object



16
17
18
# File 'lib/gretel/crumbs.rb', line 16

def crumb(name, &block)
  all[name] = block
end

.get_crumb(name, object = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gretel/crumbs.rb', line 20

def get_crumb(name, object = nil)
  raise "Crumb '#{name}' not found." unless all[name]
  
  @object = object # share the object so we can call it from link() and parent()
  @link = nil
  @parent = nil
  
  all[name].call(object)
  Gretel::Crumb.new(@link, @parent)
end

.layout(&block) ⇒ Object



8
9
10
# File 'lib/gretel/crumbs.rb', line 8

def layout(&block)
  instance_eval &block
end


31
32
33
34
35
36
# File 'lib/gretel/crumbs.rb', line 31

def link(text, url)
  text = text.call(@object) if text.is_a?(Proc)
  url = url.call(@object) if url.is_a?(Proc)
  
  @link = Gretel::Link.new(text, url)
end

.parent(name, object = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/gretel/crumbs.rb', line 38

def parent(name, object = nil)
  name = name.call(@object) if name.is_a?(Proc)
  object = object.call(@object) if object.is_a?(Proc)

  @parent = Gretel::Parent.new(name, object)
end