Skip to content
This repository
Browse code

render_navigation passes block to config.items

  • Loading branch information...
commit f997b1e8d3847f0008f63ff55b816a8823e42c65 1 parent 21123b0
Ronald Chan authored August 28, 2012

Showing 1 changed file with 15 additions and 14 deletions. Show diff stats Hide diff stats

  1. 29  lib/simple_navigation/rendering/helpers.rb
29  lib/simple_navigation/rendering/helpers.rb
@@ -31,8 +31,9 @@ module Helpers
31 31
     #   will be loaded and used for rendering the navigation.
32 32
     # * <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.
33 33
     # * <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).
34  
-    def render_navigation(options={})
35  
-      active_navigation_item_container(options) { |container| container && container.render(options) }
  34
+    def render_navigation(options={},&block)
  35
+      container = active_navigation_item_container(options,&block)
  36
+      container && container.render(options)
36 37
     end
37 38
 
38 39
     # Returns the name of the currently active navigation item belonging to the specified level.
@@ -68,12 +69,11 @@ def active_navigation_item_key(options={})
68 69
     # options
69 70
     def active_navigation_item(options={},value_for_nil = nil)
70 71
       options[:level] = :leaves if options[:level].nil? || options[:level] == :all
71  
-      active_navigation_item_container(options) do |container|
72  
-        if container && (item = container.selected_item)
73  
-          block_given? ? yield(item) : item
74  
-        else
75  
-          value_for_nil
76  
-        end
  72
+      container = active_navigation_item_container(options)
  73
+      if container && (item = container.selected_item)
  74
+        block_given? ? yield(item) : item
  75
+      else
  76
+        value_for_nil
77 77
       end
78 78
     end
79 79
 
@@ -88,20 +88,21 @@ def active_navigation_item(options={},value_for_nil = nil)
88 88
     # * <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.
89 89
     #
90 90
     # Returns <tt>nil</tt> if no active item container can be found
91  
-    def active_navigation_item_container(options={})
  91
+    def active_navigation_item_container(options={},&block)
92 92
       options = SimpleNavigation::Helpers::apply_defaults(options)
93  
-      SimpleNavigation::Helpers::load_config(options,self)
  93
+      SimpleNavigation::Helpers::load_config(options,self,&block)
94 94
       container = SimpleNavigation.active_item_container_for(options[:level])
95  
-      block_given? ? yield(container) : container
96 95
     end
97 96
 
98 97
     class << self
99  
-      def load_config(options,includer)
  98
+      def load_config(options,includer,&block)
100 99
         ctx = options.delete(:context)
101 100
         SimpleNavigation.init_adapter_from includer
102 101
         SimpleNavigation.load_config(ctx)
103  
-        SimpleNavigation::Configuration.eval_config(ctx) 
104  
-        SimpleNavigation.config.items(options[:items]) if options[:items]
  102
+        SimpleNavigation::Configuration.eval_config(ctx)
  103
+        if block_given? || options[:items]
  104
+          SimpleNavigation.config.items(options[:items],&block)
  105
+        end
105 106
         SimpleNavigation.handle_explicit_navigation if SimpleNavigation.respond_to?(:handle_explicit_navigation)
106 107
         raise "no primary navigation defined, either use a navigation config file or pass items directly to render_navigation" unless SimpleNavigation.primary_navigation
107 108
       end

0 notes on commit f997b1e

Please sign in to comment.
Something went wrong with that request. Please try again.