Class: Tabit::Item
- Inherits:
-
Object
- Object
- Tabit::Item
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/tabit/item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add(name, url = nil, options = {}) ⇒ Object
- #divider(name = nil, options = {}) ⇒ Object
- #heading(name = nil, options = {}) ⇒ Object
-
#initialize(name, url = nil, options = {}) ⇒ Item
constructor
A new instance of Item.
- #to_s ⇒ Object
Constructor Details
#initialize(name, url = nil, options = {}) ⇒ Item
Returns a new instance of Item.
39 40 41 42 43 44 45 46 |
# File 'lib/tabit/item.rb', line 39 def initialize(name, url = nil, = {}) self.name = name self.url = url self. = self.active = self..delete(:active) || configuration.active_detect self.type = self..delete(:type) || :default end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
36 37 38 |
# File 'lib/tabit/item.rb', line 36 def active @active end |
#children ⇒ Object
Returns the value of attribute children.
31 32 33 |
# File 'lib/tabit/item.rb', line 31 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/tabit/item.rb', line 33 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
35 36 37 |
# File 'lib/tabit/item.rb', line 35 def @options end |
#type ⇒ Object
Returns the value of attribute type.
37 38 39 |
# File 'lib/tabit/item.rb', line 37 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
34 35 36 |
# File 'lib/tabit/item.rb', line 34 def url @url end |
Instance Method Details
#active? ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tabit/item.rb', line 86 def active? if template.is_active_link? url, active true else children.each do |child| next if child.is_a? String return true if child.active? end false end end |
#add(name, url = nil, options = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/tabit/item.rb', line 48 def add(name, url = nil, = {}) Item.new(name, url, ).tap do |adding| children.push adding yield adding if block_given? end end |
#divider(name = nil, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/tabit/item.rb', line 65 def divider(name = nil, = {}) configuration.divider_class, children.push template.content_tag( :li, name, ) end |
#heading(name = nil, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/tabit/item.rb', line 55 def heading(name = nil, = {}) configuration.heading_class, children.push template.content_tag( :li, name, ) end |
#to_s ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tabit/item.rb', line 75 def to_s configure_item_attrs case type when :dropdown generate_dropdown_item else generate_default_item end end |