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

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.primary_navigation.active_item_container_for(level)
end

.configObject

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(navigation_context = :default)
  file_name = navigation_context == :default ? '' : "#{navigation_context.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 current_navigation_for(level)
  self.controller.instance_variable_get(:"@sn_current_navigation_#{level}")
end

.explicit_navigation_argsObject



46
47
48
# File 'lib/simple_navigation.rb', line 46

def explicit_navigation_args
  self.controller.instance_variable_get(:"@sn_current_navigation_args")
end

.handle_explicit_navigationObject

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 handle_explicit_navigation
  if SimpleNavigation.explicit_navigation_args
    begin
      level, navigation = parse_explicit_navigation_args
      self.controller.instance_variable_set(:"@sn_current_navigation_#{level}", navigation)
    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(navigation_context = :default)
  raise "config_file_path is not set!" unless self.config_file_path
  raise "Config file '#{config_file_name(navigation_context)}' does not exists!" unless File.exists?(config_file_name(navigation_context))
  if ::RAILS_ENV == 'production'
    self.config_files[navigation_context] ||= IO.read(config_file_name(navigation_context))
  else
    self.config_files[navigation_context] = IO.read(config_file_name(navigation_context))
  end
end

.primary_navigationObject

Returns the ItemContainer that contains the items for the primary navigation



36
37
38
# File 'lib/simple_navigation.rb', line 36

def primary_navigation
  config.primary_navigation
end