Class: Padrino::Contrib::Helpers::Breadcrumb

Inherits:
Object
  • Object
show all
Defined in:
lib/padrino-contrib/helpers/breadcrumbs.rb

Constant Summary collapse

DEFAULT_URL =
"/"
DEFAULT_CAPTION =
"Home Page"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBreadcrumb

Initialize breadcrumbs with default value.

Examples:

before do
  @breadcrumbs = breadcrumbs.new
end


18
19
20
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 18

def initialize
  reset!
end

Instance Attribute Details

#homeObject

Returns the value of attribute home.



5
6
7
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 5

def home
  @home
end

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 5

def items
  @items
end

Instance Method Details

#add(name, url, caption, options = {}) ⇒ Object Also known as: <<

Add a new breadcrumbs.

Examples:

breadcrumbs.add "foo", "/foo", "Foo Link", :id => "foo-id"
breadcrumbs.add :foo, "/foo", "Foo Link", :class => "foo-class"

Parameters:

  • name (String)

    The name of resource.

  • name (Symbol)

    The name of resource.

  • url (String)

    The url href.

  • caption (String)

    The text caption.

  • options (Hash) (defaults to: {})

    The HTML options to include in li.



95
96
97
98
99
100
101
102
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 95

def add(name, url, caption, options = {})
  items << {
    :name    => name.to_sym,
    :url     => url.to_s,
    :caption => caption.to_s.humanize.html_safe,
    :options => options
  }
end

#del(name) ⇒ Object

Remove a breadcrumb.

Examples:

breadcrumbs.del "foo"
breadcrumbs.del :foo

Parameters:

  • name (String)

    The name of resource to delete from breadcrumbs list.



115
116
117
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 115

def del(name)
  items.delete_if { |item| item[:name] == name.to_sym }
end

#resetObject

Reset breadcrumbs to default or personal home.

Examples:

breadcrumbs.reset


53
54
55
56
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 53

def reset
  self.items = []
  self.items << home
end

#reset!Object

Reset breadcrumbs to default home.

Examples:

breadcrumbs.reset!


64
65
66
67
68
69
70
71
72
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 64

def reset!
  self.home = {
    :name    => :home,
    :url     => DEFAULT_URL,
    :caption => DEFAULT_CAPTION,
    :options => {}
  }
  reset
end

#set_home(url, caption, options = {}) ⇒ Object

Set the custom home (Parent) link.

Examples:

breadcrumbs.set_home "/HomeFoo", "Foo Home", :id => "home-breadcrumb"

Parameters:

  • url (String)

    The url href.

  • caption (String)

    The text caption.

  • options (Hash) (defaults to: {})

    The HTML options to include in li.



37
38
39
40
41
42
43
44
45
# File 'lib/padrino-contrib/helpers/breadcrumbs.rb', line 37

def set_home(url, caption, options = {})
  self.home = {
    :url     => url.to_s,
    :caption => caption.to_s.humanize.html_safe,
    :name    => :home,
    :options => options
  }
  reset
end