simple-navigation 3.8.0 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *3.9.0
2
+
3
+ * Added ability to pass a block to render_navigation for configuring dynamic navigation items (instead of passing :items). Credits to Ronald Chan.
4
+
1
5
  *3.8.0
2
6
 
3
7
  * Changed the way the context is fetched. Fixes incompatibility with Gretel. Thanks to Ivan Kasatenko.
data/README CHANGED
@@ -18,5 +18,5 @@ Online Demo:
18
18
  Discussion Group for Feedback and Questions
19
19
  http://groups.google.com/group/simple-navigation
20
20
 
21
- Copyright (c) 2011 Andi Schacke, released under the MIT license
21
+ Copyright (c) 2012 Andi Schacke, released under the MIT license
22
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.8.0
1
+ 3.9.0
@@ -31,8 +31,16 @@ module SimpleNavigation
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
+ #
35
+ # Instead of using the <tt>:items</tt> option, a block can be passed to specify the items dynamically
36
+ #
37
+ # render_navigation do |menu|
38
+ # menu.item :posts, "Posts", posts_path
39
+ # end
40
+ #
41
+ def render_navigation(options={},&block)
42
+ container = active_navigation_item_container(options,&block)
43
+ container && container.render(options)
36
44
  end
37
45
 
38
46
  # Returns the name of the currently active navigation item belonging to the specified level.
@@ -68,12 +76,11 @@ module SimpleNavigation
68
76
  # options
69
77
  def active_navigation_item(options={},value_for_nil = nil)
70
78
  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
79
+ container = active_navigation_item_container(options)
80
+ if container && (item = container.selected_item)
81
+ block_given? ? yield(item) : item
82
+ else
83
+ value_for_nil
77
84
  end
78
85
  end
79
86
 
@@ -88,20 +95,21 @@ module SimpleNavigation
88
95
  # * <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
96
  #
90
97
  # Returns <tt>nil</tt> if no active item container can be found
91
- def active_navigation_item_container(options={})
98
+ def active_navigation_item_container(options={},&block)
92
99
  options = SimpleNavigation::Helpers::apply_defaults(options)
93
- SimpleNavigation::Helpers::load_config(options,self)
100
+ SimpleNavigation::Helpers::load_config(options,self,&block)
94
101
  container = SimpleNavigation.active_item_container_for(options[:level])
95
- block_given? ? yield(container) : container
96
102
  end
97
103
 
98
104
  class << self
99
- def load_config(options,includer)
105
+ def load_config(options,includer,&block)
100
106
  ctx = options.delete(:context)
101
107
  SimpleNavigation.init_adapter_from includer
102
108
  SimpleNavigation.load_config(ctx)
103
- SimpleNavigation::Configuration.eval_config(ctx)
104
- SimpleNavigation.config.items(options[:items]) if options[:items]
109
+ SimpleNavigation::Configuration.eval_config(ctx)
110
+ if block_given? || options[:items]
111
+ SimpleNavigation.config.items(options[:items],&block)
112
+ end
105
113
  SimpleNavigation.handle_explicit_navigation if SimpleNavigation.respond_to?(:handle_explicit_navigation)
106
114
  raise "no primary navigation defined, either use a navigation config file or pass items directly to render_navigation" unless SimpleNavigation.primary_navigation
107
115
  end
@@ -170,6 +170,17 @@ describe SimpleNavigation::Helpers do
170
170
  @controller.render_navigation(:items => @items)
171
171
  end
172
172
  end
173
+ context 'block given' do
174
+ it 'should use block' do
175
+ block_executed = 0
176
+ expect do
177
+ @controller.render_navigation do |menu|
178
+ menu.class.should == SimpleNavigation::ItemContainer
179
+ block_executed += 1
180
+ end
181
+ end.to change{block_executed}.by(1)
182
+ end
183
+ end
173
184
  end
174
185
 
175
186
  describe 'no primary navigation defined' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 3.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-19 00:00:00.000000000 Z
13
+ date: 2012-09-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport