Skip to content

Commit

Permalink
render_navigation passes block to config.items
Browse files Browse the repository at this point in the history
  • Loading branch information
ronalchn committed Aug 28, 2012
1 parent 21123b0 commit f997b1e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/simple_navigation/rendering/helpers.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ module Helpers
# will be loaded and used for rendering the navigation. # will be loaded and used for rendering the navigation.
# * <tt>:items</tt> - you can specify the items directly (e.g. if items are dynamically generated from database). See SimpleNavigation::ItemsProvider for documentation on what to provide as items. # * <tt>:items</tt> - you can specify the items directly (e.g. if items are dynamically generated from database). See SimpleNavigation::ItemsProvider for documentation on what to provide as items.
# * <tt>:renderer</tt> - specify the renderer to be used for rendering the navigation. Either provide the Class or a symbol matching a registered renderer. Defaults to :list (html list renderer). # * <tt>:renderer</tt> - specify the renderer to be used for rendering the navigation. Either provide the Class or a symbol matching a registered renderer. Defaults to :list (html list renderer).
def render_navigation(options={}) def render_navigation(options={},&block)
active_navigation_item_container(options) { |container| container && container.render(options) } container = active_navigation_item_container(options,&block)
container && container.render(options)
end end


# Returns the name of the currently active navigation item belonging to the specified level. # Returns the name of the currently active navigation item belonging to the specified level.
Expand Down Expand Up @@ -68,12 +69,11 @@ def active_navigation_item_key(options={})
# options # options
def active_navigation_item(options={},value_for_nil = nil) def active_navigation_item(options={},value_for_nil = nil)
options[:level] = :leaves if options[:level].nil? || options[:level] == :all options[:level] = :leaves if options[:level].nil? || options[:level] == :all
active_navigation_item_container(options) do |container| container = active_navigation_item_container(options)
if container && (item = container.selected_item) if container && (item = container.selected_item)
block_given? ? yield(item) : item block_given? ? yield(item) : item
else else
value_for_nil value_for_nil
end
end end
end end


Expand All @@ -88,20 +88,21 @@ def active_navigation_item(options={},value_for_nil = nil)
# * <tt>:items</tt> - you can specify the items directly (e.g. if items are dynamically generated from database). See SimpleNavigation::ItemsProvider for documentation on what to provide as items. # * <tt>:items</tt> - you can specify the items directly (e.g. if items are dynamically generated from database). See SimpleNavigation::ItemsProvider for documentation on what to provide as items.
# #
# Returns <tt>nil</tt> if no active item container can be found # Returns <tt>nil</tt> if no active item container can be found
def active_navigation_item_container(options={}) def active_navigation_item_container(options={},&block)
options = SimpleNavigation::Helpers::apply_defaults(options) options = SimpleNavigation::Helpers::apply_defaults(options)
SimpleNavigation::Helpers::load_config(options,self) SimpleNavigation::Helpers::load_config(options,self,&block)
container = SimpleNavigation.active_item_container_for(options[:level]) container = SimpleNavigation.active_item_container_for(options[:level])
block_given? ? yield(container) : container
end end


class << self class << self
def load_config(options,includer) def load_config(options,includer,&block)
ctx = options.delete(:context) ctx = options.delete(:context)
SimpleNavigation.init_adapter_from includer SimpleNavigation.init_adapter_from includer
SimpleNavigation.load_config(ctx) SimpleNavigation.load_config(ctx)
SimpleNavigation::Configuration.eval_config(ctx) SimpleNavigation::Configuration.eval_config(ctx)
SimpleNavigation.config.items(options[:items]) if options[:items] if block_given? || options[:items]
SimpleNavigation.config.items(options[:items],&block)
end
SimpleNavigation.handle_explicit_navigation if SimpleNavigation.respond_to?(:handle_explicit_navigation) SimpleNavigation.handle_explicit_navigation if SimpleNavigation.respond_to?(:handle_explicit_navigation)
raise "no primary navigation defined, either use a navigation config file or pass items directly to render_navigation" unless SimpleNavigation.primary_navigation raise "no primary navigation defined, either use a navigation config file or pass items directly to render_navigation" unless SimpleNavigation.primary_navigation
end end
Expand Down

0 comments on commit f997b1e

Please sign in to comment.