Class: Breadcrumb
- Inherits:
-
Object
- Object
- Breadcrumb
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/breadcrumb.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
- #add(name, url = nil, options = {}) ⇒ Object
- #display ⇒ Object
-
#initialize ⇒ Breadcrumb
constructor
A new instance of Breadcrumb.
Constructor Details
#initialize ⇒ Breadcrumb
Returns a new instance of Breadcrumb.
5 6 7 |
# File 'lib/breadcrumb.rb', line 5 def initialize self.items = [] end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/breadcrumb.rb', line 3 def items @items end |
Instance Method Details
#add(name, url = nil, options = {}) ⇒ Object
9 10 11 |
# File 'lib/breadcrumb.rb', line 9 def add(name, url = nil, = {}) items << [name, url, ] end |
#display ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/breadcrumb.rb', line 13 def display size = items.size crumbs = items.to_enum(:each_with_index).collect do |item, index| name, url, = item [:class] ||= "" [:class] << " item-#{index}" [:class] << " last" if size - 1 == index [:class].squish! if url.nil? or size - 1 == index content_tag(:li, name, ) else content_tag(:li, content_tag(:a, name, :href => url), ) end end.join("\n") content_tag(:ul, "\n#{crumbs}\n".html_safe, :id => "breadcrumbs") end |