Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ doc (contexts) / clarified intention of code
  • Loading branch information
andi committed Aug 10, 2009
1 parent 824e1a4 commit c11f49a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions lib/simple_navigation/helpers.rb
Expand Up @@ -15,13 +15,15 @@ module SimpleNavigation
#
module Helpers

# Renders the navigation according to the specified <tt>level</tt>.
#
# The <tt>level</tt> 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).
# Renders the navigation according to the specified options-hash.
#
# The following options are supported:
# * <tt>level</tt> - 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).
# * <tt>context</tt> - 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 <tt>render_navigation(:context => :admin)</tt> the file config/admin_navigation.rb
# will be loaded and used for rendering the navigation.
#
def render_navigation(*args)
args = [Hash.new] if args.empty?
default_options = {:context => :default, :level => :nested}
Expand Down Expand Up @@ -49,14 +51,14 @@ def render_navigation(*args)
end
end

# Renders the primary_navigation with the configured renderer. Calling render_navigation(:primary) has the same effect.
# Renders the primary_navigation with the configured renderer. Calling render_navigation(:level => :primary) has the same effect.
def render_primary_navigation(options = {})
render_navigation(:primary, options)
render_navigation(options.merge(:level => :primary))
end

# Renders the sub_navigation with the configured renderer. Calling render_navigation(:secondary) has the same effect.
# Renders the sub_navigation with the configured renderer. Calling render_navigation(:level => :secondary) has the same effect.
def render_sub_navigation(options = {})
render_navigation(:secondary, options)
render_navigation(options.merge(:level => :secondary))
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/simple_navigation/helpers_spec.rb
Expand Up @@ -110,14 +110,14 @@ class ControllerMock

describe 'render_primary_navigation' do
it "should delegate to render_navigation(:primary)" do
@controller.should_receive(:render_navigation).with(:primary, {})
@controller.should_receive(:render_navigation).with(:level => :primary)
@controller.render_primary_navigation
end
end

describe 'render_sub_navigation' do
it "should delegate to render_navigation(:secondary)" do
@controller.should_receive(:render_navigation).with(:secondary, {})
@controller.should_receive(:render_navigation).with(:level => :secondary)
@controller.render_sub_navigation
end
end
Expand Down

0 comments on commit c11f49a

Please sign in to comment.