simple-navigation 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,9 +1,15 @@
1
+ *2.7.0
2
+
3
+ * added new option :highlights_on to item definition in config-file. Specify a regexp which is matched against the current_uri to determine if an item is active or not. Replaces explicit highlighting in controllers.
4
+ * deprecated explicit highlighting in the controllers.
5
+
6
+
1
7
  *2.6.0
2
8
 
3
9
  * added rendering option 'skip_if_empty' to Renderer::List to avoid rendering of empty ul-tags
4
10
  * added breadcrumbs renderer incl. specs. A big thanks to Markus Schirp.
5
11
  * added ability to register a renderer / specify your renderer as symbol in render_navigation
6
- * renderer can be specified in render_navigation. Credits to Andi Badi from Galaxy Cats.
12
+ * renderer can be specified in render_navigation. Credits to Andi Bade from Galaxy Cats.
7
13
 
8
14
  *2.5.4
9
15
 
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
- :minor: 6
3
+ :minor: 7
4
4
  :patch: 0
@@ -28,6 +28,17 @@ SimpleNavigation::Configuration.run do |navigation|
28
28
  # name - will be displayed in the rendered navigation. This can also be a call to your I18n-framework.
29
29
  # url - the address that the generated item links to. You can also use url_helpers (named routes, restful routes helper, url_for etc.)
30
30
  # options - can be used to specify attributes that will be included in the rendered navigation item (e.g. id, class etc.)
31
+ # some special options that can be set:
32
+ # :if - Specifies a proc to call to determine if the item should
33
+ # be rendered (e.g. <tt>:if => Proc.new { current_user.admin? }</tt>). The
34
+ # proc should evaluate to a true or false value and is evaluated in the context of the view.
35
+ # :unless - Specifies a proc to call to determine if the item should not
36
+ # be rendered (e.g. <tt>:unless => Proc.new { current_user.admin? }</tt>). The
37
+ # proc should evaluate to a true or false value and is evaluated in the context of the view.
38
+ # :method - Specified the http-method for the generated link - default is :get.
39
+ # :highlights_on - if autohighlighting is turned off and/or you want to explicitly specify
40
+ # when the item should be highlighted, you can set a regexp which is matched
41
+ # against the current URI.
31
42
  #
32
43
  primary.item :key_1, 'name', url, options
33
44
 
@@ -56,6 +56,7 @@ module SimpleNavigation
56
56
  #
57
57
  # The specified symbol must match the keys for your navigation items in your config/navigation.rb file.
58
58
  def navigation(*args)
59
+ ActiveSupport::Deprecation.warn("Setting the active navigation in the controllers has been deprecated. Please use the new :highlights_on option in the config file for explicit highlighting")
59
60
  self.class_eval do
60
61
  define_method :sn_set_navigation do
61
62
  current_navigation(*args)
@@ -72,6 +73,7 @@ module SimpleNavigation
72
73
  #
73
74
  # The specified symbol must match the keys for your navigation items in your config/navigation.rb file.
74
75
  def current_navigation(*args)
76
+ ActiveSupport::Deprecation.warn("Setting the active navigation in the controllers has been deprecated. Please use the new :highlights_on option in the config file for explicit highlighting")
75
77
  @sn_current_navigation_args = args
76
78
  end
77
79
  end
@@ -2,7 +2,7 @@ module SimpleNavigation
2
2
 
3
3
  # Represents an item in your navigation. Gets generated by the item method in the config-file.
4
4
  class Item
5
- attr_reader :key, :name, :url, :sub_navigation, :method
5
+ attr_reader :key, :name, :url, :sub_navigation, :method, :highlights_on
6
6
  attr_writer :html_options
7
7
 
8
8
  # see ItemContainer#item
@@ -14,6 +14,7 @@ module SimpleNavigation
14
14
  @method = options.delete(:method)
15
15
  @name = name
16
16
  @url = url
17
+ @highlights_on = options.delete(:highlights_on)
17
18
  @html_options = options
18
19
  if sub_nav_block || items
19
20
  @sub_navigation = ItemContainer.new(@container.level + 1)
@@ -63,7 +64,10 @@ module SimpleNavigation
63
64
 
64
65
  # Returns true if the item's url matches the request's current url.
65
66
  def selected_by_url?
66
- if auto_highlight?
67
+ if highlights_on
68
+ raise ArgumentError, ':highlights_on must be a regexp' unless highlights_on.instance_of?(Regexp)
69
+ SimpleNavigation.template.request.request_uri =~ highlights_on
70
+ elsif auto_highlight?
67
71
  !!(root_path_match? || (SimpleNavigation.template && SimpleNavigation.template.current_page?(url)))
68
72
  else
69
73
  false
@@ -22,13 +22,16 @@ module SimpleNavigation
22
22
  # The <tt>url</tt> is the address that the generated item points to. You can also use url_helpers (named routes, restful routes helper, url_for etc.)
23
23
  #
24
24
  # The <tt>options</tt> can be used to specify the following things:
25
- # * <tt>html_attributes</tt> - will be included in the rendered navigation item (e.g. id, class etc.)
25
+ # * <tt>any html_attributes</tt> - will be included in the rendered navigation item (e.g. id, class etc.)
26
26
  # * <tt>:if</tt> - Specifies a proc to call to determine if the item should
27
27
  # be rendered (e.g. <tt>:if => Proc.new { current_user.admin? }</tt>). The
28
28
  # proc should evaluate to a true or false value and is evaluated in the context of the view.
29
29
  # * <tt>:unless</tt> - Specifies a proc to call to determine if the item should not
30
30
  # be rendered (e.g. <tt>:unless => Proc.new { current_user.admin? }</tt>). The
31
31
  # proc should evaluate to a true or false value and is evaluated in the context of the view.
32
+ # * <tt>:method</tt> - Specified the http-method for the generated link - default is :get.
33
+ # * <tt>:highlights_on</tt> - if autohighlighting is turned off and/or you want to explicitly specify
34
+ # when the item should be highlighted, you can set a regexp which is matched againstthe current URI.
32
35
  #
33
36
  # The <tt>block</tt> - if specified - will hold the item's sub_navigation.
34
37
  def item(key, name, url, options={}, &block)
@@ -41,8 +41,10 @@ describe SimpleNavigation::ControllerMethods do
41
41
  describe 'navigation' do
42
42
 
43
43
  def call_navigation(key1, key2=nil)
44
- @controller.class_eval do
45
- navigation key1, key2
44
+ ActiveSupport::Deprecation.silence do
45
+ @controller.class_eval do
46
+ navigation key1, key2
47
+ end
46
48
  end
47
49
  end
48
50
 
@@ -74,11 +76,11 @@ describe SimpleNavigation::ControllerMethods do
74
76
 
75
77
  describe 'current_navigation' do
76
78
  it "should set the sn_current_navigation_args as specified" do
77
- @controller.current_navigation(:first)
79
+ ActiveSupport::Deprecation.silence {@controller.current_navigation(:first)}
78
80
  @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first]
79
81
  end
80
82
  it "should set the sn_current_navigation_args as specified" do
81
- @controller.current_navigation(:first, :second)
83
+ ActiveSupport::Deprecation.silence {@controller.current_navigation(:first, :second)}
82
84
  @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first, :second]
83
85
  end
84
86
  end
@@ -45,7 +45,7 @@ describe SimpleNavigation::Item do
45
45
  end
46
46
  end
47
47
  end
48
- context 'method' do
48
+ context ':method option' do
49
49
  context 'defined' do
50
50
  before(:each) do
51
51
  @options = {:method => :delete}
@@ -65,6 +65,28 @@ describe SimpleNavigation::Item do
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ context ':highlights_on option' do
70
+ context 'defined' do
71
+ before(:each) do
72
+ @highlights_on = stub(:option)
73
+ @options = {:highlights_on => @highlights_on}
74
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
75
+ end
76
+ it 'should set the method as instance_var' do
77
+ @item.highlights_on.should == @highlights_on
78
+ end
79
+ it 'should set the html-options without the method' do
80
+ @item.instance_variable_get(:@html_options).key?(:highlights_on).should be_false
81
+ end
82
+ end
83
+
84
+ context 'undefined' do
85
+ it 'should set the instance-var to nil' do
86
+ @item.highlights_on.should be_nil
87
+ end
88
+ end
89
+ end
68
90
  end
69
91
 
70
92
  describe 'selected?' do
@@ -181,7 +203,7 @@ describe SimpleNavigation::Item do
181
203
  it {@item.html_options[:id].should == 'my_id'}
182
204
  end
183
205
 
184
- context 'with no id definied in options (using default id)' do
206
+ context 'with no id defined in options (using default id)' do
185
207
  before(:each) do
186
208
  @item.html_options = {}
187
209
  end
@@ -257,6 +279,45 @@ describe SimpleNavigation::Item do
257
279
  end
258
280
 
259
281
  describe 'selected_by_url?' do
282
+ context ':highlights_on option is set' do
283
+ before(:each) do
284
+ @item.stub!(:highlights_on => /^\/current/)
285
+ @template = stub(:template, :request => stub(:request, :request_uri => '/current_url'))
286
+ SimpleNavigation.stub!(:template => @template)
287
+ end
288
+ it "should not check for autohighlighting" do
289
+ @item.should_not_receive(:auto_highlight?)
290
+ @item.send(:selected_by_url?)
291
+ end
292
+ context ':highlights_on is a regexp' do
293
+ context 'regexp matches current_url' do
294
+ it {@item.send(:selected_by_url?).should be_true}
295
+ end
296
+ context 'regexp does not match current_url' do
297
+ before(:each) do
298
+ @item.stub!(:highlights_on => /^\/no_match/)
299
+ end
300
+ it {@item.send(:selected_by_url?).should be_false}
301
+ end
302
+ end
303
+ context ':highlights_on is not a regexp' do
304
+ before(:each) do
305
+ @item.stub!(:highlights_on => "not a regexp")
306
+ end
307
+ it "should raise an error" do
308
+ lambda {@item.send(:selected_by_url?).should raise_error(ArgumentError)}
309
+ end
310
+ end
311
+ end
312
+ context ':highlights_on option is not set' do
313
+ before(:each) do
314
+ @item.stub!(:highlights_on => nil)
315
+ end
316
+ it "should check for autohighlighting" do
317
+ @item.should_receive(:auto_highlight?)
318
+ @item.send(:selected_by_url?)
319
+ end
320
+ end
260
321
  context 'auto_highlight is turned on' do
261
322
  before(:each) do
262
323
  @item.stub!(:auto_highlight? => true)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 6
7
+ - 7
8
8
  - 0
9
- version: 2.6.0
9
+ version: 2.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andi Schacke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-19 00:00:00 +02:00
17
+ date: 2010-07-30 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency