lib/simple_navigation/item.rb in simple-navigation-2.6.0 vs lib/simple_navigation/item.rb in simple-navigation-2.7.0
- old
+ new
@@ -1,10 +1,10 @@
module SimpleNavigation
# Represents an item in your navigation. Gets generated by the item method in the config-file.
class Item
- attr_reader :key, :name, :url, :sub_navigation, :method
+ attr_reader :key, :name, :url, :sub_navigation, :method, :highlights_on
attr_writer :html_options
# see ItemContainer#item
#
# The subnavigation (if any) is either provided by a block or passed in directly as <tt>items</tt>
@@ -12,10 +12,11 @@
@container = container
@key = key
@method = options.delete(:method)
@name = name
@url = url
+ @highlights_on = options.delete(:highlights_on)
@html_options = options
if sub_nav_block || items
@sub_navigation = ItemContainer.new(@container.level + 1)
sub_nav_block.call @sub_navigation if sub_nav_block
@sub_navigation.items = items if items
@@ -61,10 +62,13 @@
key == @container.current_explicit_navigation
end
# Returns true if the item's url matches the request's current url.
def selected_by_url?
- if auto_highlight?
+ if highlights_on
+ raise ArgumentError, ':highlights_on must be a regexp' unless highlights_on.instance_of?(Regexp)
+ SimpleNavigation.template.request.request_uri =~ highlights_on
+ elsif auto_highlight?
!!(root_path_match? || (SimpleNavigation.template && SimpleNavigation.template.current_page?(url)))
else
false
end
end
\ No newline at end of file