lib/simple_navigation/item.rb in simple-navigation-1.2.2 vs lib/simple_navigation/item.rb in simple-navigation-1.3.0

- old
+ new

@@ -1,10 +1,11 @@ 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_writer :html_options # see ItemContainer#item def initialize(key, name, url, options, sub_nav_block) @key = key @method = options.delete(:method) @@ -23,19 +24,25 @@ end # Returns the html-options hash for the item, i.e. the options specified for this item in the config-file. # It also adds the 'selected' class to the list of classes if necessary. def html_options(current_navigation) - default_options = {:id => key.to_s} + default_options = self.autogenerate_item_ids? ? {:id => key.to_s} : {} options = default_options.merge(@html_options) options[:class] = [@html_options[:class], self.selected_class(current_navigation)].flatten.compact.join(' ') options.delete(:class) if options[:class].blank? options end def selected_class(current_navigation) #:nodoc: selected?(current_navigation) ? SimpleNavigation.config.selected_class : nil end + + protected + + def autogenerate_item_ids? + SimpleNavigation.config.autogenerate_item_ids + end end end \ No newline at end of file