Class: SimpleNavigation::Configuration
- Inherits:
-
Object
- Object
- SimpleNavigation::Configuration
- Includes:
- Singleton
- Defined in:
- lib/simple_navigation/configuration.rb
Overview
Responsible for evaluating and handling the config/navigation.rb file.
Instance Attribute Summary collapse
-
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
-
#primary_navigation ⇒ Object
readonly
Returns the value of attribute primary_navigation.
-
#render_all_levels ⇒ Object
Returns the value of attribute render_all_levels.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#selected_class ⇒ Object
Returns the value of attribute selected_class.
Class Method Summary collapse
-
.eval_config(context, navigation_context = :default) ⇒ Object
Evals the config_file for the given navigation_context inside the specified context (usually a controller or view).
-
.extract_controller_from(context) ⇒ Object
Extracts a controller from the context.
-
.run(&block) ⇒ Object
Starts processing the configuration.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Sets the config’s default-settings.
-
#items(&block) ⇒ Object
Yields an SimpleNavigation::ItemContainer for adding navigation items.
-
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
Constructor Details
#initialize ⇒ Configuration
Sets the config’s default-settings
40 41 42 43 44 45 |
# File 'lib/simple_navigation/configuration.rb', line 40 def initialize @renderer = SimpleNavigation::Renderer::List @selected_class = 'selected' @render_all_levels = false @autogenerate_item_ids = true end |
Instance Attribute Details
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
12 13 14 |
# File 'lib/simple_navigation/configuration.rb', line 12 def autogenerate_item_ids @autogenerate_item_ids end |
#primary_navigation ⇒ Object (readonly)
Returns the value of attribute primary_navigation.
13 14 15 |
# File 'lib/simple_navigation/configuration.rb', line 13 def @primary_navigation end |
#render_all_levels ⇒ Object
Returns the value of attribute render_all_levels.
11 12 13 |
# File 'lib/simple_navigation/configuration.rb', line 11 def render_all_levels @render_all_levels end |
#renderer ⇒ Object
Returns the value of attribute renderer.
9 10 11 |
# File 'lib/simple_navigation/configuration.rb', line 9 def renderer @renderer end |
#selected_class ⇒ Object
Returns the value of attribute selected_class.
10 11 12 |
# File 'lib/simple_navigation/configuration.rb', line 10 def selected_class @selected_class end |
Class Method Details
.eval_config(context, navigation_context = :default) ⇒ Object
Evals the config_file for the given navigation_context inside the specified context (usually a controller or view)
18 19 20 21 |
# File 'lib/simple_navigation/configuration.rb', line 18 def eval_config(context, = :default) context.instance_eval(SimpleNavigation.config_files[]) SimpleNavigation.controller = extract_controller_from context end |
.extract_controller_from(context) ⇒ Object
Extracts a controller from the context.
29 30 31 32 33 34 35 |
# File 'lib/simple_navigation/configuration.rb', line 29 def extract_controller_from(context) if context.respond_to? :controller context.controller else context end end |
.run(&block) ⇒ Object
Starts processing the configuration
24 25 26 |
# File 'lib/simple_navigation/configuration.rb', line 24 def run(&block) block.call Configuration.instance end |
Instance Method Details
#items(&block) ⇒ Object
Yields an SimpleNavigation::ItemContainer for adding navigation items
48 49 50 51 |
# File 'lib/simple_navigation/configuration.rb', line 48 def items(&block) @primary_navigation = ItemContainer.new block.call @primary_navigation end |
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
54 55 56 |
# File 'lib/simple_navigation/configuration.rb', line 54 def loaded? !@primary_navigation.nil? end |