Class: SimpleNavigation::Configuration
- Inherits:
-
Object
- Object
- SimpleNavigation::Configuration
- Includes:
- Singleton
- Defined in:
- lib/simple_navigation/core/configuration.rb
Overview
Responsible for evaluating and handling the config/navigation.rb file.
Instance Attribute Summary collapse
-
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
-
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
-
#id_generator ⇒ Object
Returns the value of attribute id_generator.
-
#primary_navigation ⇒ Object
readonly
Returns the value of attribute primary_navigation.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#selected_class ⇒ Object
Returns the value of attribute selected_class.
Class Method Summary collapse
-
.eval_config(navigation_context = :default) ⇒ Object
Evals the config_file for the given navigation_context.
-
.run(&block) ⇒ Object
Starts processing the configuration.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Sets the config’s default-settings.
-
#items(items_provider = nil, &block) ⇒ Object
This is the main method for specifying the navigation items.
-
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
Constructor Details
#initialize ⇒ Configuration
Sets the config’s default-settings
27 28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
9 10 11 |
# File 'lib/simple_navigation/core/configuration.rb', line 9 def auto_highlight @auto_highlight end |
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
9 10 11 |
# File 'lib/simple_navigation/core/configuration.rb', line 9 def autogenerate_item_ids @autogenerate_item_ids end |
#id_generator ⇒ Object
Returns the value of attribute id_generator.
9 10 11 |
# File 'lib/simple_navigation/core/configuration.rb', line 9 def id_generator @id_generator end |
#primary_navigation ⇒ Object (readonly)
Returns the value of attribute primary_navigation.
10 11 12 |
# File 'lib/simple_navigation/core/configuration.rb', line 10 def @primary_navigation end |
#renderer ⇒ Object
Returns the value of attribute renderer.
9 10 11 |
# File 'lib/simple_navigation/core/configuration.rb', line 9 def renderer @renderer end |
#selected_class ⇒ Object
Returns the value of attribute selected_class.
9 10 11 |
# File 'lib/simple_navigation/core/configuration.rb', line 9 def selected_class @selected_class end |
Class Method Details
.eval_config(navigation_context = :default) ⇒ Object
Evals the config_file for the given navigation_context
15 16 17 |
# File 'lib/simple_navigation/core/configuration.rb', line 15 def eval_config( = :default) SimpleNavigation.context_for_eval.instance_eval(SimpleNavigation.config_files[]) end |
.run(&block) ⇒ Object
Starts processing the configuration
20 21 22 |
# File 'lib/simple_navigation/core/configuration.rb', line 20 def run(&block) block.call Configuration.instance end |
Instance Method Details
#items(items_provider = nil, &block) ⇒ Object
This is the main method for specifying the navigation items. It can be used in two ways:
-
Declaratively specify your items in the config/navigation.rb file using a block. It then yields an SimpleNavigation::ItemContainer for adding navigation items.
-
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.
53 54 55 56 57 58 59 60 61 |
# 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 |
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
64 65 66 |
# File 'lib/simple_navigation/core/configuration.rb', line 64 def loaded? !@primary_navigation.nil? end |