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
-
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
-
#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
-
.context_for_eval ⇒ Object
Returns the context in which the config file should be evaluated.
-
.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
45 46 47 48 49 50 51 |
# File 'lib/simple_navigation/configuration.rb', line 45 def initialize @renderer = SimpleNavigation::Renderer::List @selected_class = 'selected' @render_all_levels = false @autogenerate_item_ids = true @auto_highlight = true end |
Instance Attribute Details
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
9 10 11 |
# File 'lib/simple_navigation/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/configuration.rb', line 9 def autogenerate_item_ids @autogenerate_item_ids end |
#primary_navigation ⇒ Object (readonly)
Returns the value of attribute primary_navigation.
10 11 12 |
# File 'lib/simple_navigation/configuration.rb', line 10 def @primary_navigation end |
#render_all_levels ⇒ Object
Returns the value of attribute render_all_levels.
9 10 11 |
# File 'lib/simple_navigation/configuration.rb', line 9 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.
9 10 11 |
# File 'lib/simple_navigation/configuration.rb', line 9 def selected_class @selected_class end |
Class Method Details
.context_for_eval ⇒ Object
Returns the context in which the config file should be evaluated. This is preferably the template, otherwise te controller
28 29 30 31 |
# File 'lib/simple_navigation/configuration.rb', line 28 def context_for_eval raise 'no context set for evaluation the config file' unless SimpleNavigation.template || SimpleNavigation.controller SimpleNavigation.template || SimpleNavigation.controller end |
.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)
15 16 17 18 19 |
# File 'lib/simple_navigation/configuration.rb', line 15 def eval_config(context, = :default) SimpleNavigation.controller = extract_controller_from context SimpleNavigation.template = SimpleNavigation.controller.instance_variable_get(:@template) context_for_eval.instance_eval(SimpleNavigation.config_files[]) end |
.extract_controller_from(context) ⇒ Object
Extracts a controller from the context.
34 35 36 37 38 39 40 |
# File 'lib/simple_navigation/configuration.rb', line 34 def extract_controller_from(context) if context.respond_to? :controller context.controller else context end end |
.run(&block) ⇒ Object
Starts processing the configuration
22 23 24 |
# File 'lib/simple_navigation/configuration.rb', line 22 def run(&block) block.call Configuration.instance end |
Instance Method Details
#items(&block) ⇒ Object
Yields an SimpleNavigation::ItemContainer for adding navigation items
54 55 56 57 |
# File 'lib/simple_navigation/configuration.rb', line 54 def items(&block) @primary_navigation = ItemContainer.new block.call @primary_navigation end |
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
60 61 62 |
# File 'lib/simple_navigation/configuration.rb', line 60 def loaded? !@primary_navigation.nil? end |