Module: SimpleNavigation::Helpers

Defined in:
lib/simple_navigation/helpers.rb

Overview

View helpers to render the navigation.

Use render_navigation as following to render your navigation:

  • call render_navigation without :level option to render your navigation as nested tree.

  • call render_navigation(:level => x) to render a specific navigation level (e.g. :level => 1 to render your primary navigation, :level => 2 to render the sub navigation and so forth)

Examples (using Haml)

#primary_navigation= render_navigation(:level => 1)

#sub_navigation= render_navigation(:level => 2)

#nested_navigation= render_navigation

Please note that render_primary_navigation and render_sub_navigation still work, but have been deprecated and may be removed in a future release.

Instance Method Summary collapse

Instance Method Details

#render_navigation(*args) ⇒ Object

Renders the navigation according to the specified options-hash.

The following options are supported:

  • :level - defaults to :nested which renders the the sub_navigation for an active primary_navigation inside that active primary_navigation item. Specify a specific level to only render that level of navigation (e.g. :level => 1 for primary_navigation etc…).

  • :context - specifies the context for which you would render the navigation. Defaults to :default which loads the default navigation.rb (i.e. config/navigation.rb). If you specify a context then the plugin tries to load the configuration file for that context, e.g. if you call render_navigation(:context => :admin) the file config/admin_navigation.rb will be loaded and used for rendering the navigation.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_navigation/helpers.rb', line 28

def render_navigation(*args)
  args = [Hash.new] if args.empty?
  options = extract_backwards_compatible_options(*args)
  options = {:context => :default, :level => :nested}.merge(options)
  SimpleNavigation.load_config(options[:context])
  SimpleNavigation::Configuration.eval_config(self, options[:context])
  SimpleNavigation.handle_explicit_navigation
  case options[:level]
    when Integer
      active_item_container = SimpleNavigation.active_item_container_for(options[:level])
      active_item_container.render if active_item_container
    when :nested
      SimpleNavigation.primary_navigation.render(true)
    when :all
      SimpleNavigation.primary_navigation.render(true,:all=>true)
    else
      raise ArgumentError, "Invalid navigation level: #{options[:level]}"
  end
end

#render_primary_navigation(options = {}) ⇒ Object

Deprecated. Renders the primary_navigation with the configured renderer. Calling render_navigation(:level => 0) has the same effect.



49
50
51
52
# File 'lib/simple_navigation/helpers.rb', line 49

def render_primary_navigation(options = {})
  ActiveSupport::Deprecation.warn("SimpleNavigation::Helpers.render_primary_navigation has been deprected. Please use render_navigation(:level => 1) instead")
  render_navigation(options.merge(:level => 1))
end

#render_sub_navigation(options = {}) ⇒ Object

Deprecated. Renders the sub_navigation with the configured renderer. Calling render_navigation(:level => 1) has the same effect.



55
56
57
58
# File 'lib/simple_navigation/helpers.rb', line 55

def render_sub_navigation(options = {})
  ActiveSupport::Deprecation.warn("SimpleNavigation::Helpers.render_primary_navigation has been deprected. Please use render_navigation(:level => 2) instead")
  render_navigation(options.merge(:level => 2))
end