Class: Tabit::Item

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/tabit/item.rb

Direct Known Subclasses

Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  self.name = name
  self.url = url
  self.options = options

  self.active = self.options.delete(:active) || configuration.active_detect
  self.type = self.options.delete(:type) || :default
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



36
37
38
# File 'lib/tabit/item.rb', line 36

def active
  @active
end

#childrenObject

Returns the value of attribute children.



31
32
33
# File 'lib/tabit/item.rb', line 31

def children
  @children
end

#nameObject

Returns the value of attribute name.



33
34
35
# File 'lib/tabit/item.rb', line 33

def name
  @name
end

#optionsObject

Returns the value of attribute options.



35
36
37
# File 'lib/tabit/item.rb', line 35

def options
  @options
end

#typeObject

Returns the value of attribute type.



37
38
39
# File 'lib/tabit/item.rb', line 37

def type
  @type
end

#urlObject

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

Returns:

  • (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, options = {})
  Item.new(name, url, options).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, options = {})
  append_class_to_options configuration.divider_class, options

  children.push template.(
    :li,
    name,
    options
  )
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, options = {})
  append_class_to_options configuration.heading_class, options

  children.push template.(
    :li,
    name,
    options
  )
end

#to_sObject



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