Class: Padrino::Helpers::Breadcrumb

Inherits:
Object
  • Object
show all
Defined in:
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.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


20
21
22
23
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 20

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

Instance Attribute Details

#homeObject

Returns the value of attribute home.



5
6
7
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 5

def home
  @home
end

#itemsObject

Returns the value of attribute items.



6
7
8
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 6

def items
  @items
end

Instance Method Details

#add(name, url, caption) ⇒ Object Also known as: <<

Add a new breadcrumbs

Examples:

breadcrumbs.add "foo", "/foo", "Foo Link"
breadcrumbs.add :foo, "/foo", "Foo Link"

Parameters:

  • name (String)

    The name of resource

  • name (Symbol)

    The name of resource

  • url (String)

    The url href.

  • caption (String)

    The text caption



87
88
89
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 87

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

#del(name) ⇒ Object

Remove a Breadcrumbs

Examples:

breadcrumbs.del "foo"
breadcrumbs.del :foo

Parameters:

  • name (String)

    The name of resource to delete from breadcrumbs list

  • name (Symbol)

    The name of resource to delete from breadcrumbs list



107
108
109
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 107

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

#resetObject

Reset breadcrumbs to default or personal home

Examples:

breadcrumbs.reset


51
52
53
54
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 51

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

#reset!Object

Reset breadcrumbs to default home

Examples:

breadcrumbs.reset!


63
64
65
66
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 63

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

#set_home(url, caption) ⇒ Object

Set the custom home (Parent) link

Examples:

breadcrumbs.set_home "/HomeFoo", "Foo Home"

Parameters:

  • url (String)

    The url href

  • caption (String)

    The text caption.



39
40
41
42
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb', line 39

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