Module: SimpleNavigation::Helpers
- Defined in:
- lib/simple_navigation/helpers.rb
Overview
View helpers to render the navigation.
Use render_primary_navigation to render your primary navigation with the configured renderer. Use render_sub_navigation to render the sub navigation belonging to the active primary navigation. Use render_navigation to render the primary navigation with the corresponding sub navigation rendered inside primary navigation item which is active.
Examples (using Haml)
#primary_navigation= render_primary_navigation
#sub_navigation= render_sub_navigation
#main_navigation= render_navigation
Instance Method Summary collapse
-
#render_navigation(*args) ⇒ Object
Renders the navigation according to the specified options-hash.
-
#render_primary_navigation(options = {}) ⇒ Object
Renders the primary_navigation with the configured renderer.
-
#render_sub_navigation(options = {}) ⇒ Object
Renders the sub_navigation with the configured renderer.
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. Other possible levels are :primary which only renders the primary_navigation (also see render_primary_navigation) and :secondary which only renders the sub_navigation (see render_sub_navigation). -
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 callrender_navigation(:context => :admin)
the file config/admin_navigation.rb will be loaded and used for rendering the navigation.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simple_navigation/helpers.rb', line 27 def (*args) args = [Hash.new] if args.empty? = {:context => :default, :level => :nested} level, = case args.first when Hash = .merge(args.first) [[:level], [:context]] when Symbol [args[0], .merge(args[1] || {})[:context]] else raise ArgumentError, "Invalid arguments" end SimpleNavigation.load_config() SimpleNavigation::Configuration.eval_config(self, ) case level when :primary SimpleNavigation..render(@current_primary_navigation) when :secondary primary = SimpleNavigation.[@current_primary_navigation] primary..render(@current_secondary_navigation) if primary && primary. when :nested SimpleNavigation..render(@current_primary_navigation, true, @current_secondary_navigation) else raise ArgumentError, "Invalid navigation level: #{level}" end end |
#render_primary_navigation(options = {}) ⇒ Object
Renders the primary_navigation with the configured renderer. Calling render_navigation(:level => :primary) has the same effect.
55 56 57 |
# File 'lib/simple_navigation/helpers.rb', line 55 def ( = {}) (.merge(:level => :primary)) end |
#render_sub_navigation(options = {}) ⇒ Object
Renders the sub_navigation with the configured renderer. Calling render_navigation(:level => :secondary) has the same effect.
60 61 62 |
# File 'lib/simple_navigation/helpers.rb', line 60 def ( = {}) (.merge(:level => :secondary)) end |