Sha256: fd3ac2f09a43825477833e0c777b3fe9f36c0c0b043402c998adc9b8bf4830c1
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
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) @name = name @url = url @html_options = options if sub_nav_block @sub_navigation = ItemContainer.new sub_nav_block.call @sub_navigation end end # Returns true if this navigation item should be rendered as 'selected' for the specified current_navigation. def selected?(current_navigation) key == current_navigation 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_class = self.autogenerate_item_ids? ? key.to_s : nil @html_options @html_options[:class] = [default_class, @html_options[:class], self.selected_class(current_navigation)].flatten.compact.uniq.join(' ') @html_options.delete(:class) if @html_options[:class].blank? @html_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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
krasivotokak-simple-navigation-1.4.1 | lib/simple_navigation/item.rb |