simple-navigation 3.4.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -1
- data/VERSION +1 -1
- data/generators/navigation_config/templates/config/navigation.rb +7 -2
- data/lib/simple_navigation/core/configuration.rb +3 -2
- data/lib/simple_navigation/core/item.rb +9 -3
- data/spec/lib/simple_navigation/core/configuration_spec.rb +3 -0
- data/spec/lib/simple_navigation/core/item_spec.rb +11 -10
- data/spec/spec_helper.rb +3 -3
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
*3.5.0
|
2
|
+
|
3
|
+
* Added (configurable) "simple-navigation-active-leaf" class to last selected element and elements that have :highlights_on return true. Thanks to Frank Schumacher (thenoseman).
|
4
|
+
|
1
5
|
*3.4.2
|
2
6
|
|
3
7
|
* Improve Gemfile dependencies with :development and :rails groups.
|
@@ -218,4 +222,4 @@
|
|
218
222
|
|
219
223
|
*1.1.1
|
220
224
|
|
221
|
-
* Change plugin into a GemPlugin
|
225
|
+
* Change plugin into a GemPlugin
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.5.0
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# Configures your navigation
|
2
3
|
SimpleNavigation::Configuration.run do |navigation|
|
3
4
|
# Specify a custom renderer if needed.
|
@@ -8,6 +9,10 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
8
9
|
# Specify the class that will be applied to active navigation items. Defaults to 'selected'
|
9
10
|
# navigation.selected_class = 'your_selected_class'
|
10
11
|
|
12
|
+
# Specify the class that will be applied to the current leaf of
|
13
|
+
# active navigation items. Defaults to 'simple-navigation-active-leaf'
|
14
|
+
# navigation.active_leaf_class = 'your_active_leaf_class'
|
15
|
+
|
11
16
|
# Item keys are normally added to list items as id.
|
12
17
|
# This setting turns that off
|
13
18
|
# navigation.autogenerate_item_ids = false
|
@@ -42,7 +47,7 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
42
47
|
# :method - Specifies the http-method for the generated link - default is :get.
|
43
48
|
# :highlights_on - if autohighlighting is turned off and/or you want to explicitly specify
|
44
49
|
# when the item should be highlighted, you can set a regexp which is matched
|
45
|
-
# against the current URI.
|
50
|
+
# against the current URI. You may also use a proc, or the symbol <tt>:subpath</tt>.
|
46
51
|
#
|
47
52
|
primary.item :key_1, 'name', url, options
|
48
53
|
|
@@ -68,4 +73,4 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
68
73
|
|
69
74
|
end
|
70
75
|
|
71
|
-
end
|
76
|
+
end
|
@@ -6,7 +6,7 @@ module SimpleNavigation
|
|
6
6
|
class Configuration
|
7
7
|
include Singleton
|
8
8
|
|
9
|
-
attr_accessor :renderer, :selected_class, :autogenerate_item_ids, :id_generator, :auto_highlight, :name_generator
|
9
|
+
attr_accessor :renderer, :selected_class, :active_leaf_class, :autogenerate_item_ids, :id_generator, :auto_highlight, :name_generator
|
10
10
|
attr_reader :primary_navigation
|
11
11
|
|
12
12
|
class << self
|
@@ -27,6 +27,7 @@ module SimpleNavigation
|
|
27
27
|
def initialize
|
28
28
|
@renderer = SimpleNavigation.default_renderer || SimpleNavigation::Renderer::List
|
29
29
|
@selected_class = 'selected'
|
30
|
+
@active_leaf_class = 'simple-navigation-active-leaf'
|
30
31
|
@autogenerate_item_ids = true
|
31
32
|
@id_generator = Proc.new {|id| id.to_s }
|
32
33
|
@name_generator = Proc.new {|name| name}
|
@@ -68,4 +69,4 @@ module SimpleNavigation
|
|
68
69
|
|
69
70
|
end
|
70
71
|
|
71
|
-
end
|
72
|
+
end
|
@@ -53,13 +53,19 @@ module SimpleNavigation
|
|
53
53
|
def html_options
|
54
54
|
default_options = self.autogenerate_item_ids? ? {:id => autogenerated_item_id} : {}
|
55
55
|
options = default_options.merge(@html_options)
|
56
|
-
options[:class] = [@html_options[:class], self.selected_class].flatten.compact.join(' ')
|
56
|
+
options[:class] = [@html_options[:class], self.selected_class, self.active_leaf_class].flatten.compact.join(' ')
|
57
57
|
options.delete(:class) if options[:class].nil? || options[:class] == ''
|
58
58
|
options
|
59
59
|
end
|
60
60
|
|
61
|
-
# Returns the configured
|
62
|
-
#
|
61
|
+
# Returns the configured active_leaf_class if the item is the selected leaf,
|
62
|
+
# nil otherwise
|
63
|
+
def active_leaf_class
|
64
|
+
selected_by_condition? ? SimpleNavigation.config.active_leaf_class : nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the configured selected_class if the item is selected,
|
68
|
+
# nil otherwise
|
63
69
|
def selected_class
|
64
70
|
selected? ? SimpleNavigation.config.selected_class : nil
|
65
71
|
end
|
@@ -43,6 +43,9 @@ describe SimpleNavigation::Configuration do
|
|
43
43
|
it "should set the selected_class to 'selected' as default" do
|
44
44
|
@config.selected_class.should == 'selected'
|
45
45
|
end
|
46
|
+
it "should set the active_leaf_class to 'simple-navigation-active-leaf' as default" do
|
47
|
+
@config.active_leaf_class.should == 'simple-navigation-active-leaf'
|
48
|
+
end
|
46
49
|
it "should set autogenerate_item_ids to true as default" do
|
47
50
|
@config.autogenerate_item_ids.should be_true
|
48
51
|
end
|
@@ -197,14 +197,14 @@ describe SimpleNavigation::Item do
|
|
197
197
|
end
|
198
198
|
context 'with item selected' do
|
199
199
|
before(:each) do
|
200
|
-
@item.stub!(:selected? => true)
|
200
|
+
@item.stub!(:selected? => true, :selected_by_condition? => true)
|
201
201
|
end
|
202
|
-
it {@item.html_options[:class].should == 'my_class selected'}
|
202
|
+
it {@item.html_options[:class].should == 'my_class selected simple-navigation-active-leaf'}
|
203
203
|
end
|
204
204
|
|
205
205
|
context 'with item not selected' do
|
206
206
|
before(:each) do
|
207
|
-
@item.stub!(:selected? => false)
|
207
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
208
208
|
end
|
209
209
|
it {@item.html_options[:class].should == 'my_class'}
|
210
210
|
end
|
@@ -217,25 +217,26 @@ describe SimpleNavigation::Item do
|
|
217
217
|
end
|
218
218
|
context 'with item selected' do
|
219
219
|
before(:each) do
|
220
|
-
@item.stub!(:selected? => true)
|
220
|
+
@item.stub!(:selected? => true, :selected_by_condition? => true)
|
221
221
|
end
|
222
|
-
it {@item.html_options[:class].should == 'selected'}
|
222
|
+
it {@item.html_options[:class].should == 'selected simple-navigation-active-leaf'}
|
223
223
|
end
|
224
224
|
|
225
225
|
context 'with item not selected' do
|
226
226
|
before(:each) do
|
227
|
-
@item.stub!(:selected? => false)
|
227
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
228
228
|
end
|
229
229
|
it {@item.html_options[:class].should be_blank}
|
230
230
|
end
|
231
231
|
end
|
232
|
+
|
232
233
|
end
|
233
234
|
|
234
235
|
describe 'id' do
|
235
236
|
context 'with autogenerate_item_ids == true' do
|
236
237
|
before(:each) do
|
237
238
|
@item.stub!(:autogenerate_item_ids? => true)
|
238
|
-
@item.stub!(:selected? => false)
|
239
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
239
240
|
end
|
240
241
|
context 'with id defined in options' do
|
241
242
|
before(:each) do
|
@@ -255,7 +256,7 @@ describe SimpleNavigation::Item do
|
|
255
256
|
context 'with autogenerate_item_ids == false' do
|
256
257
|
before(:each) do
|
257
258
|
@item.stub!(:autogenerate_item_ids? => false)
|
258
|
-
@item.stub!(:selected? => false)
|
259
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
259
260
|
end
|
260
261
|
context 'with id defined in options' do
|
261
262
|
before(:each) do
|
@@ -284,11 +285,11 @@ describe SimpleNavigation::Item do
|
|
284
285
|
@item.stub!(:sub_navigation => @sub_navigation)
|
285
286
|
end
|
286
287
|
it "should return true if subnav is selected" do
|
287
|
-
@sub_navigation.stub!(:selected? => true)
|
288
|
+
@sub_navigation.stub!(:selected? => true, :selected_by_condition? => true)
|
288
289
|
@item.should be_selected_by_subnav
|
289
290
|
end
|
290
291
|
it "should return false if subnav is not selected" do
|
291
|
-
@sub_navigation.stub!(:selected? => false)
|
292
|
+
@sub_navigation.stub!(:selected? => false, :selected_by_condition? => true)
|
292
293
|
@item.should_not be_selected_by_subnav
|
293
294
|
end
|
294
295
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -56,7 +56,7 @@ def containers
|
|
56
56
|
container.dom_id = 'nav_dom_id'
|
57
57
|
container.dom_class = 'nav_dom_class'
|
58
58
|
@items = primary_items.map {|params| SimpleNavigation::Item.new(container, *params)}
|
59
|
-
@items.each {|i| i.stub!(:selected? => false)}
|
59
|
+
@items.each {|i| i.stub!(:selected? => false, :selected_by_condition? => false)}
|
60
60
|
container.instance_variable_set(:@items, @items)
|
61
61
|
sub_container = subnav_container
|
62
62
|
primary_item(:invoices) {|item| item.instance_variable_set(:@sub_navigation, sub_container)}
|
@@ -79,14 +79,14 @@ def select_item(key)
|
|
79
79
|
item.instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}.stub!(:selected? => true)
|
80
80
|
end
|
81
81
|
else
|
82
|
-
primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
|
82
|
+
primary_item(key) {|item| item.stub!(:selected? => true, :selected_by_condition? => true) unless item.frozen?}
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
def subnav_container
|
87
87
|
container = SimpleNavigation::ItemContainer.new(2)
|
88
88
|
items = sub_items.map {|params| SimpleNavigation::Item.new(container, *params)}
|
89
|
-
items.each {|i| i.stub!(:selected? => false)}
|
89
|
+
items.each {|i| i.stub!(:selected? => false, :selected_by_condition? => false)}
|
90
90
|
container.instance_variable_set(:@items, items)
|
91
91
|
container
|
92
92
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 3.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 3.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andi Schacke
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-08-
|
19
|
+
date: 2011-08-15 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|