Module: SimpleNavigation
- Defined in:
- lib/simple_navigation.rb,
lib/simple_navigation/item.rb,
lib/simple_navigation/helpers.rb,
lib/simple_navigation/configuration.rb,
lib/simple_navigation/renderer/base.rb,
lib/simple_navigation/renderer/list.rb,
lib/simple_navigation/item_container.rb,
lib/simple_navigation/controller_methods.rb
Overview
TODO: add :except and :only options to navigation method
Defined Under Namespace
Modules: ControllerMethods, Helpers, Renderer Classes: Configuration, Item, ItemContainer
Class Method Summary collapse
- .active_item_container_for(level) ⇒ Object
-
.config ⇒ Object
Returns the singleton instance of the SimpleNavigation::Configuration.
-
.config_file_name(navigation_context = :default) ⇒ Object
Returns the path to the config_file for the given navigation_context.
-
.current_navigation_for(level) ⇒ Object
Reads the current navigation for the specified level from the controller.
- .explicit_navigation_args ⇒ Object
-
.handle_explicit_navigation ⇒ Object
If any navigation has been explicitely set in the controller this method evaluates the specified args set in the controller and sets the correct instance variable in the controller.
-
.load_config(navigation_context = :default) ⇒ Object
Reads the config_file for the specified navigation_context and stores it for later evaluation.
-
.primary_navigation ⇒ Object
Returns the ItemContainer that contains the items for the primary navigation.
Class Method Details
.active_item_container_for(level) ⇒ Object
56 57 58 |
# File 'lib/simple_navigation.rb', line 56 def active_item_container_for(level) self..active_item_container_for(level) end |
.config ⇒ Object
Returns the singleton instance of the SimpleNavigation::Configuration
31 32 33 |
# File 'lib/simple_navigation.rb', line 31 def config SimpleNavigation::Configuration.instance end |
.config_file_name(navigation_context = :default) ⇒ Object
Returns the path to the config_file for the given navigation_context
41 42 43 44 |
# File 'lib/simple_navigation.rb', line 41 def config_file_name( = :default) file_name = == :default ? '' : "#{.to_s.underscore}_" File.join(config_file_path, "#{file_name}navigation.rb") end |
.current_navigation_for(level) ⇒ Object
Reads the current navigation for the specified level from the controller. Returns nil if there is no current navigation set for level.
52 53 54 |
# File 'lib/simple_navigation.rb', line 52 def (level) self.controller.instance_variable_get(:"@sn_current_navigation_#{level}") end |
.explicit_navigation_args ⇒ Object
46 47 48 |
# File 'lib/simple_navigation.rb', line 46 def self.controller.instance_variable_get(:"@sn_current_navigation_args") end |
.handle_explicit_navigation ⇒ Object
If any navigation has been explicitely set in the controller this method evaluates the specified args set in the controller and sets the correct instance variable in the controller.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_navigation.rb', line 62 def if SimpleNavigation. begin level, = self.controller.instance_variable_set(:"@sn_current_navigation_#{level}", ) rescue #we do nothing here #TODO: check if this is the right way to handle wrong explicit navigation end end end |
.load_config(navigation_context = :default) ⇒ Object
Reads the config_file for the specified navigation_context and stores it for later evaluation.
20 21 22 23 24 25 26 27 28 |
# File 'lib/simple_navigation.rb', line 20 def load_config( = :default) raise "config_file_path is not set!" unless self.config_file_path raise "Config file '#{config_file_name()}' does not exists!" unless File.exists?(config_file_name()) if ::RAILS_ENV == 'production' self.config_files[] ||= IO.read(config_file_name()) else self.config_files[] = IO.read(config_file_name()) end end |
.primary_navigation ⇒ Object
Returns the ItemContainer that contains the items for the primary navigation
36 37 38 |
# File 'lib/simple_navigation.rb', line 36 def config. end |