lib/tabit/item.rb in tabit-0.2.0 vs lib/tabit/item.rb in tabit-0.2.1
- old
+ new
@@ -7,43 +7,41 @@
attr_accessor :children
attr_accessor :name
attr_accessor :url
attr_accessor :options
+ attr_accessor :active
def initialize(name, url = nil, options = {})
@name, @url, @options = name, url, options
-
+
@active = @options.delete(:active) || configuration.active_detect
@type = @options.delete(:type) || :default
-
@children = []
@options[:inner] ||= {}
@options[:outer] ||= {}
-
- clazz = template.active_link_to_class(
- url,
- {
- active: @active,
- class_active: configuration.active_class
- }
- )
-
- @options[:outer][:class] = '' if @options[:outer][:class].nil?
- @options[:outer][:class] << " #{clazz}"
- @options[:outer][:class].strip!
end
def add(name, url = nil, options = {})
Item.new(name, url, options).tap do |adding|
@children << adding
yield adding if block_given?
end
end
def to_s
+ clazz = if active?
+ configuration.active_class
+ else
+ ''
+ end
+
+ options[:outer][:class] = '' if @options[:outer][:class].nil?
+ options[:outer][:class] << " #{clazz}"
+ options[:outer][:class].strip!
+
case @type
when :dropdown
options[:outer][:class] = '' if @options[:outer][:class].nil?
options[:outer][:class] << " dropdown"
options[:outer][:class].strip!
@@ -70,9 +68,23 @@
template.link_to(name, url, options[:inner]),
output
].compact.join.html_safe,
options[:outer]
)
+ end
+ end
+
+ 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
protected
def output