simple-navigation 3.3.3 → 3.3.4

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.3.4
2
+
3
+ * modified :highlights_on option to accept a Proc (as well as the existing Regexp form). This can be used to provide specific highlighting conditions inline. Thanks to superlou for sparking the idea for the concept.
4
+
1
5
  *3.3.3
2
6
 
3
7
  * Bugfix in Adapters::Sinatra#current_url? (compares unencoded URIs). Thanks to Matthew Gast.
data/README CHANGED
@@ -10,7 +10,7 @@ Documentation:
10
10
  http://wiki.github.com/andi/simple-navigation
11
11
 
12
12
  RDoc:
13
- http://andi.rubyforge.org/simple-navigation
13
+ Please checkout the repository and execute 'rake rdoc'.
14
14
 
15
15
  Online Demo:
16
16
  http://simple-navigation-demo.andischacke.com
@@ -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) 2010 Andi Schacke, released under the MIT license
21
+ Copyright (c) 2011 Andi Schacke, released under the MIT license
22
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.3
1
+ 3.3.4
@@ -45,7 +45,7 @@ module SimpleNavigation
45
45
  # * its url matches the url of the current request (auto highlighting)
46
46
  #
47
47
  def selected?
48
- @selected = @selected || selected_by_config? || selected_by_subnav? || selected_by_url?
48
+ @selected = @selected || selected_by_config? || selected_by_subnav? || selected_by_condition?
49
49
  end
50
50
 
51
51
  # Returns the html-options hash for the item, i.e. the options specified for this item in the config-file.
@@ -76,10 +76,16 @@ module SimpleNavigation
76
76
  end
77
77
 
78
78
  # Returns true if the item's url matches the request's current url.
79
- def selected_by_url?
79
+ def selected_by_condition?
80
80
  if highlights_on
81
- raise ArgumentError, ':highlights_on must be a regexp' unless highlights_on.instance_of?(Regexp)
82
- SimpleNavigation.request_uri =~ highlights_on
81
+ case highlights_on
82
+ when Regexp
83
+ SimpleNavigation.request_uri =~ highlights_on
84
+ when Proc
85
+ highlights_on.call
86
+ else
87
+ raise ArgumentError, ':highlights_on must be a Regexp or Proc'
88
+ end
83
89
  elsif auto_highlight?
84
90
  !!(root_path_match? || SimpleNavigation.current_page?(url_without_anchor))
85
91
  else
@@ -112,4 +118,4 @@ module SimpleNavigation
112
118
  end
113
119
 
114
120
  end
115
- end
121
+ end
@@ -138,7 +138,7 @@ describe SimpleNavigation::Item do
138
138
  it {@item.should be_selected}
139
139
  it "should not evaluate the subnav or urls" do
140
140
  @item.should_not_receive(:selected_by_subnav?)
141
- @item.should_not_receive(:selected_by_url?)
141
+ @item.should_not_receive(:selected_by_condition?)
142
142
  @item.selected?
143
143
  end
144
144
  end
@@ -156,15 +156,15 @@ describe SimpleNavigation::Item do
156
156
  before(:each) do
157
157
  @item.stub!(:selected_by_subnav? => false)
158
158
  end
159
- context 'selected by url' do
159
+ context 'selected by condition' do
160
160
  before(:each) do
161
- @item.stub!(:selected_by_url? => true)
161
+ @item.stub!(:selected_by_condition? => true)
162
162
  end
163
163
  it {@item.should be_selected}
164
164
  end
165
- context 'not selected by url' do
165
+ context 'not selected by condition' do
166
166
  before(:each) do
167
- @item.stub!(:selected_by_url? => false)
167
+ @item.stub!(:selected_by_condition? => false)
168
168
  end
169
169
  it {@item.should_not be_selected}
170
170
  end
@@ -300,7 +300,7 @@ describe SimpleNavigation::Item do
300
300
  end
301
301
  end
302
302
 
303
- describe 'selected_by_url?' do
303
+ describe 'selected_by_condition?' do
304
304
  context ':highlights_on option is set' do
305
305
  before(:each) do
306
306
  @item.stub!(:highlights_on => /^\/current/)
@@ -308,25 +308,39 @@ describe SimpleNavigation::Item do
308
308
  end
309
309
  it "should not check for autohighlighting" do
310
310
  @item.should_not_receive(:auto_highlight?)
311
- @item.send(:selected_by_url?)
311
+ @item.send(:selected_by_condition?)
312
312
  end
313
313
  context ':highlights_on is a regexp' do
314
314
  context 'regexp matches current_url' do
315
- it {@item.send(:selected_by_url?).should be_true}
315
+ it {@item.send(:selected_by_condition?).should be_true}
316
316
  end
317
317
  context 'regexp does not match current_url' do
318
318
  before(:each) do
319
319
  @item.stub!(:highlights_on => /^\/no_match/)
320
320
  end
321
- it {@item.send(:selected_by_url?).should be_false}
321
+ it {@item.send(:selected_by_condition?).should be_false}
322
322
  end
323
323
  end
324
- context ':highlights_on is not a regexp' do
324
+ context ':highlights_on is a lambda' do
325
+ context 'truthy lambda results in selection' do
326
+ before(:each) do
327
+ @item.stub!(:highlights_on => lambda{true})
328
+ end
329
+ it {@item.send(:selected_by_condition?).should be_true}
330
+ end
331
+ context 'falsey lambda results in no selection' do
332
+ before(:each) do
333
+ @item.stub!(:highlights_on => lambda{false})
334
+ end
335
+ it {@item.send(:selected_by_condition?).should be_false}
336
+ end
337
+ end
338
+ context ':highlights_on is not a regexp or a proc' do
325
339
  before(:each) do
326
340
  @item.stub!(:highlights_on => "not a regexp")
327
341
  end
328
342
  it "should raise an error" do
329
- lambda {@item.send(:selected_by_url?).should raise_error(ArgumentError)}
343
+ lambda {@item.send(:selected_by_condition?).should raise_error(ArgumentError)}
330
344
  end
331
345
  end
332
346
  end
@@ -336,7 +350,7 @@ describe SimpleNavigation::Item do
336
350
  end
337
351
  it "should check for autohighlighting" do
338
352
  @item.should_receive(:auto_highlight?)
339
- @item.send(:selected_by_url?)
353
+ @item.send(:selected_by_condition?)
340
354
  end
341
355
  end
342
356
  context 'auto_highlight is turned on' do
@@ -347,7 +361,7 @@ describe SimpleNavigation::Item do
347
361
  before(:each) do
348
362
  @item.stub!(:root_path_match? => true)
349
363
  end
350
- it {@item.send(:selected_by_url?).should be_true}
364
+ it {@item.send(:selected_by_condition?).should be_true}
351
365
  end
352
366
  context 'root path does not match' do
353
367
  before(:each) do
@@ -359,20 +373,20 @@ describe SimpleNavigation::Item do
359
373
  end
360
374
  it "should test with the item's url" do
361
375
  @adapter.should_receive(:current_page?).with('url')
362
- @item.send(:selected_by_url?)
376
+ @item.send(:selected_by_condition?)
363
377
  end
364
378
  it "should remove anchors before testing the item's url" do
365
379
  @item.stub!(:url => 'url#anchor')
366
380
  @adapter.should_receive(:current_page?).with('url')
367
- @item.send(:selected_by_url?)
381
+ @item.send(:selected_by_condition?)
368
382
  end
369
- it {@item.send(:selected_by_url?).should be_true}
383
+ it {@item.send(:selected_by_condition?).should be_true}
370
384
  end
371
385
  context 'no match' do
372
386
  before(:each) do
373
387
  @adapter.stub!(:current_page? => false)
374
388
  end
375
- it {@item.send(:selected_by_url?).should be_false}
389
+ it {@item.send(:selected_by_condition?).should be_false}
376
390
  end
377
391
  end
378
392
  end
@@ -380,7 +394,7 @@ describe SimpleNavigation::Item do
380
394
  before(:each) do
381
395
  @item.stub!(:auto_highlight? => false)
382
396
  end
383
- it {@item.send(:selected_by_url?).should be_false}
397
+ it {@item.send(:selected_by_condition?).should be_false}
384
398
  end
385
399
  end
386
400
 
metadata CHANGED
@@ -1,49 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.3.4
4
5
  prerelease:
5
- version: 3.3.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Andi Schacke
9
9
  - Mark J. Titorenko
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-06-29 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2011-07-11 00:00:00.000000000 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &2152960620 !ruby/object:Gem::Requirement
20
19
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
24
23
  version: 2.0.1
25
24
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
25
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *2152960620
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: &2152959780 !ruby/object:Gem::Requirement
31
30
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
35
34
  version: 2.3.2
36
35
  type: :runtime
37
- version_requirements: *id002
38
- description: With the simple-navigation gem installed you can easily create multilevel navigations for your Rails, Sinatra or Padrino applications. The navigation is defined in a single configuration file. It supports automatic as well as explicit highlighting of the currently active navigation through regular expressions.
36
+ prerelease: false
37
+ version_requirements: *2152959780
38
+ description: With the simple-navigation gem installed you can easily create multilevel
39
+ navigations for your Rails, Sinatra or Padrino applications. The navigation is defined
40
+ in a single configuration file. It supports automatic as well as explicit highlighting
41
+ of the currently active navigation through regular expressions.
39
42
  email: andreas.schacke@gmail.com
40
43
  executables: []
41
-
42
44
  extensions: []
43
-
44
- extra_rdoc_files:
45
+ extra_rdoc_files:
45
46
  - README
46
- files:
47
+ files:
47
48
  - CHANGELOG
48
49
  - README
49
50
  - Rakefile
@@ -91,33 +92,32 @@ files:
91
92
  - spec/lib/simple_navigation/rendering/renderer/text_spec.rb
92
93
  - spec/lib/simple_navigation_spec.rb
93
94
  - spec/spec_helper.rb
95
+ has_rdoc: true
94
96
  homepage: http://github.com/andi/simple-navigation
95
97
  licenses: []
96
-
97
98
  post_install_message:
98
- rdoc_options:
99
+ rdoc_options:
99
100
  - --inline-source
100
101
  - --charset=UTF-8
101
- require_paths:
102
+ require_paths:
102
103
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
104
105
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
115
116
  requirements: []
116
-
117
117
  rubyforge_project: andi
118
- rubygems_version: 1.8.5
118
+ rubygems_version: 1.6.2
119
119
  signing_key:
120
120
  specification_version: 3
121
- summary: simple-navigation is a ruby library for creating navigations (with multiple levels) for your Rails2, Rails3, Sinatra or Padrino application.
121
+ summary: simple-navigation is a ruby library for creating navigations (with multiple
122
+ levels) for your Rails2, Rails3, Sinatra or Padrino application.
122
123
  test_files: []
123
-