simple-navigation 1.2.2 → 1.3.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/.gitignore +3 -0
- data/CHANGELOG +7 -1
- data/VERSION.yml +2 -2
- data/generators/navigation_config/templates/config/navigation.rb +14 -0
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/configuration.rb +4 -0
- data/lib/simple_navigation/item.rb +8 -1
- data/lib/simple_navigation/item_container.rb +1 -1
- data/lib/simple_navigation/renderer/list.rb +8 -2
- data/simple-navigation.gemspec +76 -0
- data/spec/lib/simple_navigation/configuration_spec.rb +6 -0
- data/spec/lib/simple_navigation/item_spec.rb +35 -9
- data/spec/lib/simple_navigation/renderer/list_spec.rb +24 -0
- data/uninstall.rb +1 -0
- metadata +8 -3
data/.gitignore
ADDED
data/CHANGELOG
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
*
|
1
|
+
*1.3.0
|
2
|
+
|
3
|
+
* render_all_levels-option allows to render all subnavigation independent from the active primary navigation ('full open tree'). Userful for javascript menus. Thanks to Richard Hulse.
|
4
|
+
* ability to turn off automatic generation of dom_ids for the list items (autogenerate_item_ids). Credits again to Richard Hulse.
|
5
|
+
* ability to specify dom_class for primary and secondary lists. Thanks Richard!
|
6
|
+
|
7
|
+
*1.2.2
|
2
8
|
|
3
9
|
* renderers now have access to request_forgery_protection stuff (this allows delete-links as navigation-items)
|
4
10
|
|
data/VERSION.yml
CHANGED
@@ -7,6 +7,15 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
7
7
|
# Specify the class that will be applied to active navigation items. Defaults to 'selected'
|
8
8
|
# navigation.selected_class = 'your_selected_class'
|
9
9
|
|
10
|
+
# Normally only the current sub menu is renderedwhen render_navigation is called
|
11
|
+
# setting this to true render all submenus which is useful for javascript
|
12
|
+
# driven hovering menus like the jquery superfish plugin
|
13
|
+
# navigation.render_all_levels = true
|
14
|
+
|
15
|
+
# Item keys are normally added to list items.
|
16
|
+
# this setting turns that off
|
17
|
+
# navigation.autogenerate_item_ids = false
|
18
|
+
|
10
19
|
# Define the primary navigation
|
11
20
|
navigation.items do |primary|
|
12
21
|
# Add an item to the primary navigation. The following params apply:
|
@@ -28,6 +37,11 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
28
37
|
# thus you can use all the methods and vars you have available in the views.
|
29
38
|
primary.item :key_3, 'Admin', url, :class => 'special', :if => Proc.new { current_user.admin? }
|
30
39
|
primary.item :key_4, 'Account', url, :unless => Proc.new { logged_in? }
|
40
|
+
|
41
|
+
# you can also specify a css id or class to attach to this particular level
|
42
|
+
# works for all levels of the menu
|
43
|
+
# primary.dom_id = 'menu-id'
|
44
|
+
# primary.dom_class = 'menu-class'
|
31
45
|
|
32
46
|
end
|
33
47
|
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/install.rb
ADDED
@@ -8,6 +8,8 @@ module SimpleNavigation
|
|
8
8
|
|
9
9
|
attr_accessor :renderer
|
10
10
|
attr_accessor :selected_class
|
11
|
+
attr_accessor :render_all_levels
|
12
|
+
attr_accessor :autogenerate_item_ids
|
11
13
|
attr_reader :primary_navigation
|
12
14
|
|
13
15
|
class << self
|
@@ -38,6 +40,8 @@ module SimpleNavigation
|
|
38
40
|
def initialize
|
39
41
|
@renderer = SimpleNavigation::Renderer::List
|
40
42
|
@selected_class = 'selected'
|
43
|
+
@render_all_levels = false
|
44
|
+
@autogenerate_item_ids = true
|
41
45
|
end
|
42
46
|
|
43
47
|
# Yields an SimpleNavigation::ItemContainer for adding navigation items
|
@@ -3,6 +3,7 @@ module SimpleNavigation
|
|
3
3
|
# Represents an item in your navigation. Gets generated by the item method in the config-file.
|
4
4
|
class Item
|
5
5
|
attr_reader :key, :name, :url, :sub_navigation, :method
|
6
|
+
attr_writer :html_options
|
6
7
|
|
7
8
|
# see ItemContainer#item
|
8
9
|
def initialize(key, name, url, options, sub_nav_block)
|
@@ -25,7 +26,7 @@ module SimpleNavigation
|
|
25
26
|
# Returns the html-options hash for the item, i.e. the options specified for this item in the config-file.
|
26
27
|
# It also adds the 'selected' class to the list of classes if necessary.
|
27
28
|
def html_options(current_navigation)
|
28
|
-
default_options = {:id => key.to_s}
|
29
|
+
default_options = self.autogenerate_item_ids? ? {:id => key.to_s} : {}
|
29
30
|
options = default_options.merge(@html_options)
|
30
31
|
options[:class] = [@html_options[:class], self.selected_class(current_navigation)].flatten.compact.join(' ')
|
31
32
|
options.delete(:class) if options[:class].blank?
|
@@ -36,6 +37,12 @@ module SimpleNavigation
|
|
36
37
|
selected?(current_navigation) ? SimpleNavigation.config.selected_class : nil
|
37
38
|
end
|
38
39
|
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def autogenerate_item_ids?
|
44
|
+
SimpleNavigation.config.autogenerate_item_ids
|
45
|
+
end
|
39
46
|
|
40
47
|
end
|
41
48
|
end
|
@@ -13,10 +13,16 @@ module SimpleNavigation
|
|
13
13
|
list_content = item_container.items.inject([]) do |list, item|
|
14
14
|
html_options = item.html_options(current_navigation)
|
15
15
|
li_content = link_to(item.name, item.url, :class => item.selected_class(current_navigation), :method => item.method)
|
16
|
-
|
16
|
+
if item.sub_navigation
|
17
|
+
if SimpleNavigation.config.render_all_levels
|
18
|
+
li_content << (item.sub_navigation.render(current_sub_navigation))
|
19
|
+
else
|
20
|
+
li_content << (item.sub_navigation.render(current_sub_navigation)) if include_sub_navigation && item.selected?(current_navigation)
|
21
|
+
end
|
22
|
+
end
|
17
23
|
list << content_tag(:li, li_content, html_options)
|
18
24
|
end
|
19
|
-
content_tag(:ul, list_content, {:id => item_container.dom_id})
|
25
|
+
content_tag(:ul, list_content, {:id => item_container.dom_id, :class => item_container.dom_class})
|
20
26
|
end
|
21
27
|
|
22
28
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{simple-navigation}
|
5
|
+
s.version = "1.3.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Andi Schacke"]
|
9
|
+
s.date = %q{2009-06-16}
|
10
|
+
s.description = %q{Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.}
|
11
|
+
s.email = %q{andreas.schacke@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"CHANGELOG",
|
18
|
+
"CHANGELOG",
|
19
|
+
"README",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"generators/navigation_config/USAGE",
|
23
|
+
"generators/navigation_config/navigation_config_generator.rb",
|
24
|
+
"generators/navigation_config/templates/config/navigation.rb",
|
25
|
+
"init.rb",
|
26
|
+
"install.rb",
|
27
|
+
"lib/simple_navigation.rb",
|
28
|
+
"lib/simple_navigation/configuration.rb",
|
29
|
+
"lib/simple_navigation/controller_methods.rb",
|
30
|
+
"lib/simple_navigation/helpers.rb",
|
31
|
+
"lib/simple_navigation/item.rb",
|
32
|
+
"lib/simple_navigation/item_container.rb",
|
33
|
+
"lib/simple_navigation/renderer/base.rb",
|
34
|
+
"lib/simple_navigation/renderer/list.rb",
|
35
|
+
"rails/init.rb",
|
36
|
+
"simple-navigation.gemspec",
|
37
|
+
"spec/lib/simple_navigation/configuration_spec.rb",
|
38
|
+
"spec/lib/simple_navigation/controller_methods_spec.rb",
|
39
|
+
"spec/lib/simple_navigation/helpers_spec.rb",
|
40
|
+
"spec/lib/simple_navigation/item_container_spec.rb",
|
41
|
+
"spec/lib/simple_navigation/item_spec.rb",
|
42
|
+
"spec/lib/simple_navigation/renderer/base_spec.rb",
|
43
|
+
"spec/lib/simple_navigation/renderer/list_spec.rb",
|
44
|
+
"spec/lib/simple_navigation_spec.rb",
|
45
|
+
"spec/spec_helper.rb",
|
46
|
+
"uninstall.rb"
|
47
|
+
]
|
48
|
+
s.has_rdoc = true
|
49
|
+
s.homepage = %q{http://github.com/andi/simple-navigation}
|
50
|
+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubyforge_project = %q{andi}
|
53
|
+
s.rubygems_version = %q{1.3.1}
|
54
|
+
s.summary = %q{Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.}
|
55
|
+
s.test_files = [
|
56
|
+
"spec/lib/simple_navigation/configuration_spec.rb",
|
57
|
+
"spec/lib/simple_navigation/controller_methods_spec.rb",
|
58
|
+
"spec/lib/simple_navigation/helpers_spec.rb",
|
59
|
+
"spec/lib/simple_navigation/item_container_spec.rb",
|
60
|
+
"spec/lib/simple_navigation/item_spec.rb",
|
61
|
+
"spec/lib/simple_navigation/renderer/base_spec.rb",
|
62
|
+
"spec/lib/simple_navigation/renderer/list_spec.rb",
|
63
|
+
"spec/lib/simple_navigation_spec.rb",
|
64
|
+
"spec/spec_helper.rb"
|
65
|
+
]
|
66
|
+
|
67
|
+
if s.respond_to? :specification_version then
|
68
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
69
|
+
s.specification_version = 2
|
70
|
+
|
71
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
72
|
+
else
|
73
|
+
end
|
74
|
+
else
|
75
|
+
end
|
76
|
+
end
|
@@ -64,6 +64,12 @@ describe SimpleNavigation::Configuration do
|
|
64
64
|
it "should set the selected_class to 'selected' as default" do
|
65
65
|
@config.selected_class.should == 'selected'
|
66
66
|
end
|
67
|
+
it "should set render_all_levels to false as default" do
|
68
|
+
@config.render_all_levels.should be_false
|
69
|
+
end
|
70
|
+
it "should set autogenerate_item_ids to true as default" do
|
71
|
+
@config.autogenerate_item_ids.should be_true
|
72
|
+
end
|
67
73
|
end
|
68
74
|
describe 'items' do
|
69
75
|
before(:each) do
|
@@ -100,21 +100,47 @@ describe SimpleNavigation::Item do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
describe 'id' do
|
103
|
-
context 'with
|
103
|
+
context 'with autogenerate_item_ids == true' do
|
104
104
|
before(:each) do
|
105
|
-
@
|
106
|
-
@item
|
105
|
+
@item = SimpleNavigation::Item.new(:my_key, 'name', 'url', {}, nil)
|
106
|
+
@item.stub!(:autogenerate_item_ids? => true)
|
107
|
+
end
|
108
|
+
context 'with id defined in options' do
|
109
|
+
before(:each) do
|
110
|
+
@item.html_options = {:id => 'my_id'}
|
111
|
+
end
|
112
|
+
it {@item.html_options(:bla)[:id].should == 'my_id'}
|
107
113
|
end
|
108
|
-
it {@item.html_options(:bla)[:id].should == 'my_id'}
|
109
|
-
end
|
110
114
|
|
111
|
-
|
115
|
+
context 'with no id definied in options (using default id)' do
|
116
|
+
before(:each) do
|
117
|
+
@item.html_options = {}
|
118
|
+
end
|
119
|
+
it {@item.html_options(:bla)[:id].should == 'my_key'}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with autogenerate_item_ids == false' do
|
112
124
|
before(:each) do
|
113
|
-
@
|
114
|
-
@item
|
125
|
+
@item = SimpleNavigation::Item.new(:my_key, 'name', 'url', {}, nil)
|
126
|
+
@item.stub!(:autogenerate_item_ids? => false)
|
127
|
+
end
|
128
|
+
context 'with id defined in options' do
|
129
|
+
before(:each) do
|
130
|
+
@item.html_options = {:id => 'my_id'}
|
131
|
+
end
|
132
|
+
it {@item.html_options(:bla)[:id].should == 'my_id'}
|
115
133
|
end
|
116
|
-
|
134
|
+
|
135
|
+
context 'with no id definied in options (using default id)' do
|
136
|
+
before(:each) do
|
137
|
+
@item.html_options = {}
|
138
|
+
end
|
139
|
+
it {@item.html_options(:bla)[:id].should be_nil}
|
140
|
+
end
|
141
|
+
|
117
142
|
end
|
143
|
+
|
118
144
|
end
|
119
145
|
|
120
146
|
end
|
@@ -23,6 +23,7 @@ describe SimpleNavigation::Renderer::List do
|
|
23
23
|
def item_container(items)
|
24
24
|
container = SimpleNavigation::ItemContainer.new
|
25
25
|
container.dom_id = 'nav_dom_id'
|
26
|
+
container.dom_class = 'nav_dom_class'
|
26
27
|
container.instance_variable_set(:@items, items)
|
27
28
|
container
|
28
29
|
end
|
@@ -43,6 +44,9 @@ describe SimpleNavigation::Renderer::List do
|
|
43
44
|
it "the rendered ul-tag should have the specified dom_id" do
|
44
45
|
HTML::Selector.new('ul#nav_dom_id').select(render).should have(1).entries
|
45
46
|
end
|
47
|
+
it "the rendered ul-tag should have the specified class" do
|
48
|
+
HTML::Selector.new('ul.nav_dom_class').select(render).should have(1).entries
|
49
|
+
end
|
46
50
|
it "should render a li tag for each item" do
|
47
51
|
HTML::Selector.new('li').select(render).should have(3).entries
|
48
52
|
end
|
@@ -88,6 +92,26 @@ describe SimpleNavigation::Renderer::List do
|
|
88
92
|
it "should be possible to identify sub items using an html selector (using ids)" do
|
89
93
|
HTML::Selector.new('#invoices #subnav1').select(render(:invoices, true)).should have(1).entries
|
90
94
|
end
|
95
|
+
context 'render_all_levels = false' do
|
96
|
+
before(:each) do
|
97
|
+
SimpleNavigation.config.render_all_levels = false
|
98
|
+
end
|
99
|
+
it "should not render the invoices submenu if the user-primary is active" do
|
100
|
+
HTML::Selector.new('#invoices #subnav1').select(render(:users, true)).should be_empty
|
101
|
+
HTML::Selector.new('#invoices #subnav2').select(render(:users, true)).should be_empty
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'render_all_levels = true' do
|
106
|
+
before(:each) do
|
107
|
+
SimpleNavigation.config.render_all_levels = true
|
108
|
+
end
|
109
|
+
it "should render the invoices submenu even if the user-primary is active" do
|
110
|
+
HTML::Selector.new('#invoices #subnav1').select(render(:users, true)).should have(1).entry
|
111
|
+
HTML::Selector.new('#invoices #subnav2').select(render(:users, true)).should have(1).entry
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
91
115
|
end
|
92
116
|
|
93
117
|
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andi Schacke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-16 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,12 +22,16 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
24
|
files:
|
25
|
+
- .gitignore
|
25
26
|
- CHANGELOG
|
27
|
+
- README
|
26
28
|
- Rakefile
|
27
29
|
- VERSION.yml
|
28
30
|
- generators/navigation_config/USAGE
|
29
31
|
- generators/navigation_config/navigation_config_generator.rb
|
30
32
|
- generators/navigation_config/templates/config/navigation.rb
|
33
|
+
- init.rb
|
34
|
+
- install.rb
|
31
35
|
- lib/simple_navigation.rb
|
32
36
|
- lib/simple_navigation/configuration.rb
|
33
37
|
- lib/simple_navigation/controller_methods.rb
|
@@ -37,6 +41,7 @@ files:
|
|
37
41
|
- lib/simple_navigation/renderer/base.rb
|
38
42
|
- lib/simple_navigation/renderer/list.rb
|
39
43
|
- rails/init.rb
|
44
|
+
- simple-navigation.gemspec
|
40
45
|
- spec/lib/simple_navigation/configuration_spec.rb
|
41
46
|
- spec/lib/simple_navigation/controller_methods_spec.rb
|
42
47
|
- spec/lib/simple_navigation/helpers_spec.rb
|
@@ -46,7 +51,7 @@ files:
|
|
46
51
|
- spec/lib/simple_navigation/renderer/list_spec.rb
|
47
52
|
- spec/lib/simple_navigation_spec.rb
|
48
53
|
- spec/spec_helper.rb
|
49
|
-
-
|
54
|
+
- uninstall.rb
|
50
55
|
has_rdoc: true
|
51
56
|
homepage: http://github.com/andi/simple-navigation
|
52
57
|
post_install_message:
|