class SimpleNavigation::Configuration

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

Attributes

active_leaf_class[W]
auto_highlight[RW]
autogenerate_item_ids[RW]
consider_item_names_as_safe[RW]
highlight_on_subpath[RW]
id_generator[W]
ignore_anchors_on_auto_highlight[RW]
ignore_query_params_on_auto_highlight[RW]
name_generator[W]
primary_navigation[RW]
renderer[W]
selected_class[W]

Public Class Methods

eval_config(navigation_context = :default) click to toggle source

Evals the config_file for the given navigation_context

# File lib/simple_navigation/configuration.rb, line 24
def self.eval_config(navigation_context = :default)
  context = SimpleNavigation.config_files[navigation_context]
  SimpleNavigation.context_for_eval.instance_eval(context)
end
new() click to toggle source

Sets the config’s default-settings

# File lib/simple_navigation/configuration.rb, line 35
def initialize
  @autogenerate_item_ids = true
  @auto_highlight = true
  @consider_item_names_as_safe = false
  @highlight_on_subpath = false
  @ignore_anchors_on_auto_highlight = true
  @ignore_query_params_on_auto_highlight = true
end
run(&block) click to toggle source

Starts processing the configuration

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

Public Instance Methods

active_leaf_class() click to toggle source
# File lib/simple_navigation/configuration.rb, line 44
def active_leaf_class
  @active_leaf_class ||= 'simple-navigation-active-leaf'
end
id_generator() click to toggle source
# File lib/simple_navigation/configuration.rb, line 48
def id_generator
  @id_generator ||= :to_s.to_proc
end
items(items_provider = nil, &block) click to toggle source

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.

# File lib/simple_navigation/configuration.rb, line 76
def items(items_provider = nil, &block)
  if (items_provider && block) || (items_provider.nil? && block.nil?)
    fail('please specify either items_provider or block, but not both')
  end

  self.primary_navigation = ItemContainer.new

  if block
    block.call primary_navigation
  else
    primary_navigation.items = ItemsProvider.new(items_provider).items
  end
end
loaded?() click to toggle source

Returns true if the config_file has already been evaluated.

# File lib/simple_navigation/configuration.rb, line 91
def loaded?
  !primary_navigation.nil?
end
name_generator() click to toggle source
# File lib/simple_navigation/configuration.rb, line 95
def name_generator
  @name_generator ||= proc { |name| name }
end
renderer() click to toggle source
# File lib/simple_navigation/configuration.rb, line 99
def renderer
  @renderer ||= SimpleNavigation.default_renderer ||
                SimpleNavigation::Renderer::List
end
selected_class() click to toggle source
# File lib/simple_navigation/configuration.rb, line 104
def selected_class
  @selected_class ||= 'selected'
end