Class SimpleNavigation::Configuration
In: lib/simple_navigation/core/configuration.rb
Parent: Object

Responsible for evaluating and handling the config/navigation.rb file.

Methods

eval_config   items   loaded?   new   run  

Included Modules

Singleton

Attributes

auto_highlight  [RW] 
autogenerate_item_ids  [RW] 
id_generator  [RW] 
primary_navigation  [R] 
renderer  [RW] 
selected_class  [RW] 

Public Class methods

Evals the config_file for the given navigation_context

[Source]

# File lib/simple_navigation/core/configuration.rb, line 15
      def eval_config(navigation_context = :default)
        SimpleNavigation.context_for_eval.instance_eval(SimpleNavigation.config_files[navigation_context])
      end

Sets the config‘s default-settings

[Source]

# File lib/simple_navigation/core/configuration.rb, line 27
    def initialize
      @renderer = SimpleNavigation.default_renderer || SimpleNavigation::Renderer::List
      @selected_class = 'selected'
      @autogenerate_item_ids = true
      @id_generator = Proc.new {|id| id.to_s }
      @auto_highlight = true
    end

Starts processing the configuration

[Source]

# File lib/simple_navigation/core/configuration.rb, line 20
      def run(&block)
        block.call Configuration.instance
      end

Public Instance methods

This is the main method for specifying the navigation items. It can be used in two ways:

  1. Declaratively specify your items in the config/navigation.rb file using a block. It then yields an SimpleNavigation::ItemContainer for adding navigation items.
  2. Directly provide your items to the method (e.g. when loading your items from the database).

Example for block style (configuration file)

  config.items do |primary|
    primary.item :my_item, 'My item', my_item_path
    ...
  end

To consider when directly providing items

items_provider should be:

  • a methodname (as symbol) that returns your items. The method needs to be available in the view (i.e. a helper method)
  • an object that responds to :items
  • an enumerable containing your items

The items you specify have to fullfill certain requirements. See SimpleNavigation::ItemAdapter for more details.

[Source]

# File lib/simple_navigation/core/configuration.rb, line 53
    def items(items_provider=nil, &block)
      raise 'please specify either items_provider or block, but not both' if (items_provider && block) || (items_provider.nil? && block.nil?)
      @primary_navigation = ItemContainer.new
      if block
        block.call @primary_navigation
      else
        @primary_navigation.items = SimpleNavigation::ItemsProvider.new(items_provider).items
      end
    end

Returns true if the config_file has already been evaluated.

[Source]

# File lib/simple_navigation/core/configuration.rb, line 64
    def loaded?
      !@primary_navigation.nil?
    end

[Validate]