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.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add(name, url = nil, options = {}) ⇒ Object
- #divider(name = nil) ⇒ 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.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tabit/item.rb', line 15 def initialize(name, url = nil, = {}) @name, @url, @options = name, url, @active = @options.delete(:active) || configuration.active_detect @type = @options.delete(:type) || :default @children = [] @options[:inner] ||= {} @options[:outer] ||= {} end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
13 14 15 |
# File 'lib/tabit/item.rb', line 13 def active @active end |
#children ⇒ Object
Returns the value of attribute children.
8 9 10 |
# File 'lib/tabit/item.rb', line 8 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/tabit/item.rb', line 10 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/tabit/item.rb', line 12 def @options end |
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/tabit/item.rb', line 11 def url @url end |
Instance Method Details
#active? ⇒ Boolean
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tabit/item.rb', line 108 def active? if template.is_active_link? url, active true else children.each do |child| if child.active? return true end end false end end |
#add(name, url = nil, options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/tabit/item.rb', line 26 def add(name, url = nil, = {}) Item.new(name, url, ).tap do |adding| @children << adding yield adding if block_given? end end |
#divider(name = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tabit/item.rb', line 45 def divider(name = nil) [:class] = '' if [:class].nil? [:class] << " #{configuration.divider_class}" [:class].strip! @children << template.content_tag( :li, name, ) end |
#heading(name = nil, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tabit/item.rb', line 33 def heading(name = nil, = {}) [:class] = '' if [:class].nil? [:class] << " #{configuration.heading_class}" [:class].strip! @children << template.content_tag( :li, name, ) end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tabit/item.rb', line 57 def to_s clazz = if active? configuration.active_class else '' end case configuration.active_scope when :outer [:outer][:class] = '' if @options[:outer][:class].nil? [:outer][:class] << " #{clazz}" [:outer][:class].strip! when :inner [:inner][:class] = '' if @options[:inner][:class].nil? [:inner][:class] << " #{clazz}" [:inner][:class].strip! end case @type when :dropdown [:outer][:class] = '' if @options[:outer][:class].nil? [:outer][:class] << " dropdown" [:outer][:class].strip! [:inner][:class] = '' if @options[:inner][:class].nil? [:inner][:class] << " dropdown-toggle" [:inner][:class].strip! [:inner][:data] ||= {} [:inner][:data][:toggle] = 'dropdown' template.content_tag( :li, [ template.link_to([name, content_tag(:b, '', :class => 'caret')].join.html_safe, url, [:inner]), output ].compact.join.html_safe, [:outer] ) else template.content_tag( :li, [ template.link_to(name, url, [:inner]), output ].compact.join.html_safe, [:outer] ) end end |