xebec 2.6.1 → 2.7.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/lib/xebec.rb +13 -0
- data/lib/xebec/nav_bar.rb +5 -2
- data/lib/xebec/nav_bar_renderer.rb +2 -2
- data/lib/xebec/nav_item.rb +4 -3
- data/test/nav_bar_renderer_test.rb +33 -0
- data/test/nav_bar_test.rb +15 -0
- data/xebec.gemspec +1 -1
- metadata +4 -25
data/lib/xebec.rb
CHANGED
@@ -13,6 +13,19 @@ module Xebec
|
|
13
13
|
#
|
14
14
|
# @see Xebec::NavBarRenderer
|
15
15
|
attr_accessor :renderer_class
|
16
|
+
|
17
|
+
# Chooses the behavior of NavBarRenderers when dealing with
|
18
|
+
# the current item. By default, they are rendered in a span
|
19
|
+
# tag; however, if this flag is set to true, they will be
|
20
|
+
# rendered as links (as they would be if they weren't the
|
21
|
+
# current item). Even with this flag set, the current item
|
22
|
+
# will still get the CSS class set by
|
23
|
+
# currently_selected_nav_item_class.
|
24
|
+
#
|
25
|
+
# This setting can be overridden on a per-navbar basis.
|
26
|
+
#
|
27
|
+
# @see Xebec::NavBar#current_is_link
|
28
|
+
attr_accessor :current_is_link
|
16
29
|
|
17
30
|
end
|
18
31
|
self.currently_selected_nav_item_class = :current
|
data/lib/xebec/nav_bar.rb
CHANGED
@@ -10,6 +10,7 @@ module Xebec
|
|
10
10
|
attr_reader :items
|
11
11
|
attr_reader :html_attributes
|
12
12
|
attr_accessor :current
|
13
|
+
attr_accessor :current_is_link
|
13
14
|
|
14
15
|
# Create a new NavBar object.
|
15
16
|
#
|
@@ -21,20 +22,22 @@ module Xebec
|
|
21
22
|
@html_attributes = html_attributes || {}
|
22
23
|
@items = []
|
23
24
|
@current = nil
|
25
|
+
@current_is_link = Xebec.current_is_link
|
24
26
|
end
|
25
27
|
|
26
28
|
# Add a navigation item to this bar.
|
27
29
|
#
|
28
30
|
# @param [String, Symbol] name the name of the item
|
29
31
|
# @param [String, Proc] href the URL of the item; optional
|
32
|
+
# @param [Hash] html_options additional html_options to be passed to link_to
|
30
33
|
#
|
31
34
|
# To customize the link text, set the internationalization key
|
32
35
|
# <tt>navbar.{{nav bar name}}.{{nav item name}}</tt>.
|
33
36
|
#
|
34
37
|
# @see Xebec::NavBarHelper#nav_bar
|
35
38
|
# @see Xebec::NavBarProxy#to_s
|
36
|
-
def nav_item(name, href = nil)
|
37
|
-
items << Xebec::NavItem.new(name, href)
|
39
|
+
def nav_item(name, href = nil, html_options = {})
|
40
|
+
items << Xebec::NavItem.new(name, href, html_options)
|
38
41
|
end
|
39
42
|
|
40
43
|
def empty?
|
@@ -94,10 +94,10 @@ module Xebec
|
|
94
94
|
klass = '' << item.name.to_s
|
95
95
|
klass << " #{Xebec.currently_selected_nav_item_class}" if is_current
|
96
96
|
helper.content_tag(*list_item_tag(item, klass, text, href, is_current)) do
|
97
|
-
if is_current
|
97
|
+
if is_current && !bar.current_is_link
|
98
98
|
helper.content_tag :span, text
|
99
99
|
else
|
100
|
-
helper.link_to text, href
|
100
|
+
helper.link_to text, href, item.html_options
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/lib/xebec/nav_item.rb
CHANGED
@@ -2,18 +2,19 @@ module Xebec
|
|
2
2
|
|
3
3
|
class NavItem
|
4
4
|
|
5
|
-
attr_reader :name, :href
|
5
|
+
attr_reader :name, :href, :html_options
|
6
6
|
|
7
7
|
# Create a new navigation item.
|
8
8
|
#
|
9
9
|
# @param [String, Symbol] name the name of the item
|
10
10
|
# @param [String, Hash, ActiveRecord::Base] href whither the navigation item links;
|
11
11
|
# defaults to the named route, "#{name}_path"
|
12
|
+
# @param [Hash] html_options to be passed to the link_to helper method
|
12
13
|
#
|
13
14
|
# @see ActionView::Helpers::UrlHelper#url_for
|
14
|
-
def initialize(name, href = nil)
|
15
|
+
def initialize(name, href = nil, html_options = {})
|
15
16
|
raise ArgumentError.new("#{name || '<nil>'} is not a valid name for a navigation item") if name.blank?
|
16
|
-
@name, @href = name, href
|
17
|
+
@name, @href, @html_options = name, href, html_options
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
@@ -156,6 +156,19 @@ class NavBarRendererTest < Test::Unit::TestCase
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
159
|
+
|
160
|
+
context 'with a NavBar that has a navigation item with html_options' do
|
161
|
+
setup do
|
162
|
+
@bar.nav_item :foo, 'http://foo.com', :method => :delete
|
163
|
+
end
|
164
|
+
should 'render a navigation bar with the appropriate items' do
|
165
|
+
assert_select_from @renderer.to_s, 'ul' do
|
166
|
+
assert_select 'li.foo' do
|
167
|
+
assert_select 'a[href="http://foo.com"][data-method=delete]', 'Foo'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
159
172
|
|
160
173
|
context 'with a NavBar that has a navigation item that links to the current page' do
|
161
174
|
setup do
|
@@ -182,6 +195,26 @@ class NavBarRendererTest < Test::Unit::TestCase
|
|
182
195
|
assert_select 'li.home.current span', 'Home'
|
183
196
|
end
|
184
197
|
end
|
198
|
+
|
199
|
+
context 'with current_is_link set' do
|
200
|
+
setup do
|
201
|
+
@bar.current_is_link = true
|
202
|
+
end
|
203
|
+
|
204
|
+
should 'render all items as links' do
|
205
|
+
assert_select_from @renderer.to_s, 'ul' do
|
206
|
+
assert_select 'li.home.current', 'Home' do
|
207
|
+
assert_select 'a', 1
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
assert_select_from @renderer.to_s, 'ul' do
|
212
|
+
assert_select 'li.sign_up' do
|
213
|
+
assert_select 'a[href="/sign_up"]', 'Sign Up'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
185
218
|
end
|
186
219
|
|
187
220
|
context "with a NavBar that has a navigation item with an i18n'd title" do
|
data/test/nav_bar_test.rb
CHANGED
@@ -16,6 +16,10 @@ class NavBarTest < Test::Unit::TestCase
|
|
16
16
|
should 'use a specified name' do
|
17
17
|
assert_equal 'fazbot', Xebec::NavBar.new('fazbot').name
|
18
18
|
end
|
19
|
+
|
20
|
+
should 'have current_is_link set to false by default' do
|
21
|
+
assert !@bar.current_is_link
|
22
|
+
end
|
19
23
|
|
20
24
|
should 'be empty by default' do
|
21
25
|
assert @bar.empty?
|
@@ -45,5 +49,16 @@ class NavBarTest < Test::Unit::TestCase
|
|
45
49
|
end
|
46
50
|
|
47
51
|
end
|
52
|
+
|
53
|
+
context 'a NavBar with Xebec.current_is_link set to true' do
|
54
|
+
setup do
|
55
|
+
Xebec.current_is_link = true
|
56
|
+
@bar = Xebec::NavBar.new
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'have_current_is_link set to true by default' do
|
60
|
+
assert @bar.current_is_link
|
61
|
+
end
|
62
|
+
end
|
48
63
|
|
49
64
|
end
|
data/xebec.gemspec
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xebec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 2
|
7
|
-
- 6
|
8
|
-
- 1
|
9
|
-
version: 2.6.1
|
4
|
+
prerelease:
|
5
|
+
version: 2.7.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- James A. Rosen
|
@@ -14,8 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-01-16 00:00:00
|
18
|
-
default_executable:
|
13
|
+
date: 2011-01-16 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: shoulda
|
@@ -25,10 +20,6 @@ dependencies:
|
|
25
20
|
requirements:
|
26
21
|
- - ~>
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 10
|
31
|
-
- 3
|
32
23
|
version: 2.10.3
|
33
24
|
type: :development
|
34
25
|
version_requirements: *id001
|
@@ -40,10 +31,6 @@ dependencies:
|
|
40
31
|
requirements:
|
41
32
|
- - ~>
|
42
33
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 9
|
46
|
-
- 8
|
47
34
|
version: 0.9.8
|
48
35
|
type: :development
|
49
36
|
version_requirements: *id002
|
@@ -55,9 +42,6 @@ dependencies:
|
|
55
42
|
requirements:
|
56
43
|
- - ~>
|
57
44
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 3
|
60
|
-
- 0
|
61
45
|
version: "3.0"
|
62
46
|
type: :development
|
63
47
|
version_requirements: *id003
|
@@ -120,7 +104,6 @@ files:
|
|
120
104
|
- test/title_enhanced_nav_bar_renderer_test.rb
|
121
105
|
- test/web_app_theme_renderer_test.rb
|
122
106
|
- xebec.gemspec
|
123
|
-
has_rdoc: true
|
124
107
|
homepage: http://github.com/jamesarosen/xebec
|
125
108
|
licenses: []
|
126
109
|
|
@@ -139,21 +122,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
122
|
requirements:
|
140
123
|
- - ">="
|
141
124
|
- !ruby/object:Gem::Version
|
142
|
-
segments:
|
143
|
-
- 0
|
144
125
|
version: "0"
|
145
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
127
|
none: false
|
147
128
|
requirements:
|
148
129
|
- - ">="
|
149
130
|
- !ruby/object:Gem::Version
|
150
|
-
segments:
|
151
|
-
- 0
|
152
131
|
version: "0"
|
153
132
|
requirements: []
|
154
133
|
|
155
134
|
rubyforge_project:
|
156
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.8.10
|
157
136
|
signing_key:
|
158
137
|
specification_version: 3
|
159
138
|
summary: Navigation helpers
|