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
- #active_leaf_class ⇒ Object
-
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
-
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
-
#consider_item_names_as_safe ⇒ Object
Returns the value of attribute consider_item_names_as_safe.
-
#highlight_on_subpath ⇒ Object
Returns the value of attribute highlight_on_subpath.
- #id_generator ⇒ Object
-
#ignore_anchors_on_auto_highlight ⇒ Object
Returns the value of attribute ignore_anchors_on_auto_highlight.
-
#ignore_query_params_on_auto_highlight ⇒ Object
Returns the value of attribute ignore_query_params_on_auto_highlight.
- #name_generator ⇒ Object
-
#primary_navigation ⇒ Object
readonly
Returns the value of attribute primary_navigation.
- #renderer ⇒ Object
- #selected_class ⇒ Object
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
35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#active_leaf_class ⇒ Object
44 45 46 |
# File 'lib/simple_navigation/configuration.rb', line 44 def active_leaf_class @active_leaf_class ||= 'simple-navigation-active-leaf' end |
#auto_highlight ⇒ Object
Returns the value of attribute auto_highlight.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def auto_highlight @auto_highlight end |
#autogenerate_item_ids ⇒ Object
Returns the value of attribute autogenerate_item_ids.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def autogenerate_item_ids @autogenerate_item_ids end |
#consider_item_names_as_safe ⇒ Object
Returns the value of attribute consider_item_names_as_safe.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def consider_item_names_as_safe @consider_item_names_as_safe end |
#highlight_on_subpath ⇒ Object
Returns the value of attribute highlight_on_subpath.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def highlight_on_subpath @highlight_on_subpath end |
#id_generator ⇒ Object
48 49 50 |
# File 'lib/simple_navigation/configuration.rb', line 48 def id_generator @id_generator ||= :to_s.to_proc end |
#ignore_anchors_on_auto_highlight ⇒ Object
Returns the value of attribute ignore_anchors_on_auto_highlight.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def ignore_anchors_on_auto_highlight @ignore_anchors_on_auto_highlight end |
#ignore_query_params_on_auto_highlight ⇒ Object
Returns the value of attribute ignore_query_params_on_auto_highlight.
8 9 10 |
# File 'lib/simple_navigation/configuration.rb', line 8 def ignore_query_params_on_auto_highlight @ignore_query_params_on_auto_highlight end |
#name_generator ⇒ Object
95 96 97 |
# File 'lib/simple_navigation/configuration.rb', line 95 def name_generator @name_generator ||= proc { |name| name } end |
#primary_navigation ⇒ Object
Returns the value of attribute primary_navigation.
15 16 17 |
# File 'lib/simple_navigation/configuration.rb', line 15 def @primary_navigation end |
#renderer ⇒ Object
99 100 101 102 |
# File 'lib/simple_navigation/configuration.rb', line 99 def renderer @renderer ||= SimpleNavigation.default_renderer || SimpleNavigation::Renderer::List end |
#selected_class ⇒ Object
104 105 106 |
# File 'lib/simple_navigation/configuration.rb', line 104 def selected_class @selected_class ||= 'selected' end |
Class Method Details
.eval_config(navigation_context = :default) ⇒ Object
Evals the config_file for the given navigation_context
24 25 26 27 |
# File 'lib/simple_navigation/configuration.rb', line 24 def self.eval_config( = :default) context = SimpleNavigation.config_files[] SimpleNavigation.context_for_eval.instance_eval(context) end |
.run(&block) ⇒ Object
Starts processing the configuration
30 31 32 |
# File 'lib/simple_navigation/configuration.rb', line 30 def self.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.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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. = ItemContainer.new if block block.call else .items = ItemsProvider.new(items_provider).items end end |
#loaded? ⇒ Boolean
Returns true if the config_file has already been evaluated.
91 92 93 |
# File 'lib/simple_navigation/configuration.rb', line 91 def loaded? !.nil? end |