weppos-tabs_on_rails 0.3.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +15 -0
- data/Manifest +1 -1
- data/README.rdoc +29 -22
- data/lib/tabs_on_rails.rb +1 -1
- data/lib/tabs_on_rails/controller_mixin.rb +44 -57
- data/lib/tabs_on_rails/tabs.rb +1 -1
- data/lib/tabs_on_rails/version.rb +3 -3
- data/tabs_on_rails.gemspec +5 -6
- data/test/controller_mixin_helpers_test.rb +3 -10
- data/test/controller_mixin_test.rb +44 -52
- data/test/controller_mixin_with_controller_test.rb +81 -0
- data/test/tabs_builder_test.rb +16 -17
- data/test/test_helper.rb +22 -0
- metadata +6 -6
- data/test/controller_test.rb +0 -76
data/CHANGELOG.rdoc
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
3
|
|
4
|
+
== Release 0.8.0
|
5
|
+
|
6
|
+
* FIXED: Invalid usage of the word namescope instead of namespace.
|
7
|
+
|
8
|
+
* FIXED: :current_tab? not available as helper method (closes #229).
|
9
|
+
|
10
|
+
* FIXED: GitHub now requires the Manifest file to be included in the repos.
|
11
|
+
|
12
|
+
* FIXED: Controller methods should be protected/private (closes #228).
|
13
|
+
|
14
|
+
* CHANGED: Status to Beta and bumped release (closes #227).
|
15
|
+
|
16
|
+
* REMOVED: Deprecated current_tab setter method. Use set_tab instead.
|
17
|
+
|
18
|
+
|
4
19
|
== Release 0.3.0
|
5
20
|
|
6
21
|
* ADDED: Support for namespaces in order to manage concurrent tab menus (closes #144).
|
data/Manifest
CHANGED
@@ -15,7 +15,7 @@ tasks/tabs_on_rails_tasks.rake
|
|
15
15
|
test/builder_test.rb
|
16
16
|
test/controller_mixin_helpers_test.rb
|
17
17
|
test/controller_mixin_test.rb
|
18
|
-
test/
|
18
|
+
test/controller_mixin_with_controller_test.rb
|
19
19
|
test/fixtures/mixin/standard.html.erb
|
20
20
|
test/tabs_builder_test.rb
|
21
21
|
test/tabs_on_rails_test.rb
|
data/README.rdoc
CHANGED
@@ -4,6 +4,14 @@ TabsOnRails is a simple Rails plugin for creating and managing Tabs.
|
|
4
4
|
It provides helpers for creating tabs with a flexible interface.
|
5
5
|
|
6
6
|
|
7
|
+
== Requirements
|
8
|
+
|
9
|
+
* Ruby >= 1.8.6
|
10
|
+
* Rails >= 2.2
|
11
|
+
|
12
|
+
Note. TabsOnRails doesn't work with Rails 2.1 or previous versions (see {Ticket #245}[http://code.simonecarletti.com/issues/show/245]).
|
13
|
+
|
14
|
+
|
7
15
|
== Rails Installation
|
8
16
|
|
9
17
|
=== As a Gem
|
@@ -83,7 +91,7 @@ Taking advantage of Rails filter options, you can restrict a tab to a selected g
|
|
83
91
|
|
84
92
|
class PostsController < ApplicationController
|
85
93
|
set_tab :admin
|
86
|
-
set_tab :posts, :only =>
|
94
|
+
set_tab :posts, :only => %w(index show)
|
87
95
|
end
|
88
96
|
|
89
97
|
class ApplicationController < ActionController::Base
|
@@ -95,11 +103,11 @@ Taking advantage of Rails filter options, you can restrict a tab to a selected g
|
|
95
103
|
end
|
96
104
|
|
97
105
|
|
98
|
-
== Using
|
106
|
+
== Using Namespaces to create Multiple Tabs
|
99
107
|
|
100
|
-
|
108
|
+
Namespaces enable you to create and manage tabs in parallels. The best way to demonstrate namespace usage is with an example.
|
101
109
|
|
102
|
-
Let's assume your application
|
110
|
+
Let's assume your application provides a first level navigation menu with 3 elements: :home, :dashboard, :projects. The relationship between your tabs and your controllers is 1:1 so you should end up with the following source code.
|
103
111
|
|
104
112
|
class HomeController
|
105
113
|
set_tab :home
|
@@ -119,34 +127,33 @@ Let's assume your application provide a first level navigation menu with 3 eleme
|
|
119
127
|
|
120
128
|
The project controller contains 3 actions and you might want to create a second-level navigation menu. This menu should reflect the navigation status of the user in the project page.
|
121
129
|
|
122
|
-
Without namespaces, you wouldn't be able to accomplish this task because you already set the current tab value to :
|
130
|
+
Without namespaces, you wouldn't be able to accomplish this task because you already set the current tab value to :projects. You need to create a parallel navigation menu and uniquely identify it with a custom namespace.
|
123
131
|
Let's call it :navigation.
|
124
132
|
|
125
133
|
class ProjectsController
|
126
134
|
set_tab :projects
|
127
135
|
|
128
136
|
# Create an other tab navigation level
|
129
|
-
set_tab :first, :navigation, :only => %(first)
|
130
|
-
set_tab :second, :navigation, :only => %(second)
|
131
|
-
set_tab :third, :navigation, :only => %(third)
|
137
|
+
set_tab :first, :navigation, :only => %w(first)
|
138
|
+
set_tab :second, :navigation, :only => %w(second)
|
139
|
+
set_tab :third, :navigation, :only => %w(third)
|
132
140
|
|
133
141
|
def first; end
|
134
142
|
def second; end
|
135
143
|
def third; end
|
136
144
|
end
|
137
145
|
|
138
|
-
Voilà! That's all you need to do. And you can create an unlimited number of
|
146
|
+
Voilà! That's all you need to do. And you can create an unlimited number of namespaces as long as you use an unique name to identify them.
|
139
147
|
|
140
|
-
The default
|
148
|
+
The default namespace is called :default. Passing :default as name is the same as don't using any namespace at all. The following lines are equivalent.
|
141
149
|
|
142
|
-
# The following
|
143
150
|
set_tab :projects
|
144
151
|
set_tab :projects, :default
|
145
152
|
|
146
153
|
|
147
|
-
=== Rendering Tabs with
|
154
|
+
=== Rendering Tabs with Namespaces
|
148
155
|
|
149
|
-
To
|
156
|
+
To switch namespace in your template, just pass the :namespace option to the <tt>tabs_tag</tt> helper method.
|
150
157
|
|
151
158
|
<% tabs_tag do |tab| %>
|
152
159
|
<%= tab.home 'Homepage', root_path %>
|
@@ -154,17 +161,17 @@ To swith namescope in your template, just pass the :namescope option to the <tt>
|
|
154
161
|
<%= tab.projects 'Projects', projects_path %>
|
155
162
|
<% end %>
|
156
163
|
|
157
|
-
<% tabs_tag :
|
164
|
+
<% tabs_tag :namespace => :navigation do |tab| %>
|
158
165
|
<%= tab.first 'First', first_project_path %>
|
159
166
|
<%= tab.second 'Second', second_project_path %>
|
160
167
|
<%= tab.third 'Account', third_project_path %>
|
161
168
|
<% end %>
|
162
169
|
|
163
|
-
===
|
170
|
+
=== Namespace scope
|
164
171
|
|
165
|
-
As a bonus feature, the
|
172
|
+
As a bonus feature, the namespace name does need to be unique within current request scope, not necessarily across the entire application.
|
166
173
|
|
167
|
-
Back to the previous example, you can reuse the same
|
174
|
+
Back to the previous example, you can reuse the same namespace in the other controllers. In this way, you can reuse your templates as well.
|
168
175
|
|
169
176
|
class HomeController
|
170
177
|
set_tab :home
|
@@ -173,8 +180,8 @@ Back to the previous example, you can reuse the same namescope in the other cont
|
|
173
180
|
class DashboardController
|
174
181
|
set_tab :dashboard
|
175
182
|
|
176
|
-
set_tab :index, :navigation, :only => %(index)
|
177
|
-
set_tab :common, :navigation, :only => %(foo bar)
|
183
|
+
set_tab :index, :navigation, :only => %w(index)
|
184
|
+
set_tab :common, :navigation, :only => %w(foo bar)
|
178
185
|
|
179
186
|
# ...
|
180
187
|
end
|
@@ -182,9 +189,9 @@ Back to the previous example, you can reuse the same namescope in the other cont
|
|
182
189
|
class ProjectsController
|
183
190
|
set_tab :projects
|
184
191
|
|
185
|
-
set_tab :first, :navigation, :only => %(first)
|
186
|
-
set_tab :second, :navigation, :only => %(second)
|
187
|
-
set_tab :third, :navigation, :only => %(third)
|
192
|
+
set_tab :first, :navigation, :only => %w(first)
|
193
|
+
set_tab :second, :navigation, :only => %w(second)
|
194
|
+
set_tab :third, :navigation, :only => %w(third)
|
188
195
|
|
189
196
|
# ...
|
190
197
|
end
|
data/lib/tabs_on_rails.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# License:: MIT License
|
11
11
|
#
|
12
12
|
#--
|
13
|
-
#
|
13
|
+
#
|
14
14
|
#++
|
15
15
|
|
16
16
|
|
@@ -23,7 +23,7 @@ module TabsOnRails
|
|
23
23
|
base.class_eval do
|
24
24
|
include InstanceMethods
|
25
25
|
helper HelperMethods
|
26
|
-
helper_method :current_tab
|
26
|
+
helper_method :current_tab, :current_tab?
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -57,70 +57,57 @@ module TabsOnRails
|
|
57
57
|
name, namespace = args
|
58
58
|
|
59
59
|
before_filter(options) do |controller|
|
60
|
-
controller.set_tab(name, namespace)
|
60
|
+
controller.instance_eval { set_tab(name, namespace) }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
# This method is deprecated and exists only for compatibility with version 0.2.
|
65
|
-
# Please use <tt>set_tab</tt> method instead.
|
66
|
-
def current_tab(*args)
|
67
|
-
ActiveSupport::Deprecation.warn("Method current_tab is deprecated and will be removed in a future version. Please use set_tab instead.", caller)
|
68
|
-
set_tab(*args)
|
69
|
-
end
|
70
|
-
|
71
64
|
end
|
72
65
|
|
73
66
|
module InstanceMethods
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# set_tab :homepage
|
88
|
-
# set_tab :dashboard, :menu
|
89
|
-
#
|
90
|
-
def set_tab(name, namespace = nil)
|
91
|
-
tab_stack[namespace || :default] = name
|
92
|
-
end
|
67
|
+
protected
|
68
|
+
|
69
|
+
# Sets the value for current tab to given name.
|
70
|
+
# If you need to manage multiple tabs, then you can pass an optional namespace.
|
71
|
+
#
|
72
|
+
# ==== Examples
|
73
|
+
#
|
74
|
+
# set_tab :homepage
|
75
|
+
# set_tab :dashboard, :menu
|
76
|
+
#
|
77
|
+
def set_tab(name, namespace = nil)
|
78
|
+
tab_stack[namespace || :default] = name
|
79
|
+
end
|
93
80
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
81
|
+
# Returns the value for current tab in the default namespace,
|
82
|
+
# or nil if no tab has been set before.
|
83
|
+
# You can pass <tt>namespace</tt> to get the value of current tab for a different namespace.
|
84
|
+
#
|
85
|
+
# ==== Examples
|
86
|
+
#
|
87
|
+
# current_tab # => nil
|
88
|
+
# current_tab :menu # => nil
|
89
|
+
#
|
90
|
+
# set_tab :homepage
|
91
|
+
# set_tab :dashboard, :menu
|
92
|
+
#
|
93
|
+
# current_tab # => :homepage
|
94
|
+
# current_tab :menu # => :dashboard
|
95
|
+
#
|
96
|
+
def current_tab(namespace = nil)
|
97
|
+
tab_stack[namespace || :default]
|
98
|
+
end
|
112
99
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
100
|
+
# Returns whether the current tab in <tt>namespace</tt> matches <tt>name</tt>.
|
101
|
+
def current_tab?(name, namespace = nil)
|
102
|
+
current_tab(namespace).to_s == name.to_s
|
103
|
+
end
|
117
104
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
105
|
+
# Initializes and/or returns the tab stack.
|
106
|
+
# You won't probably need to use this method directly
|
107
|
+
# unless you are trying to hack the plugin architecture.
|
108
|
+
def tab_stack
|
109
|
+
@tab_stack ||= {}
|
110
|
+
end
|
124
111
|
|
125
112
|
end
|
126
113
|
|
data/lib/tabs_on_rails/tabs.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# License:: MIT License
|
11
11
|
#
|
12
12
|
#--
|
13
|
-
#
|
13
|
+
#
|
14
14
|
#++
|
15
15
|
|
16
16
|
|
@@ -18,14 +18,14 @@ module TabsOnRails
|
|
18
18
|
|
19
19
|
module Version
|
20
20
|
MAJOR = 0
|
21
|
-
MINOR =
|
21
|
+
MINOR = 8
|
22
22
|
TINY = 0
|
23
23
|
|
24
24
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
25
25
|
end
|
26
26
|
|
27
27
|
VERSION = Version::STRING
|
28
|
-
STATUS = '
|
28
|
+
STATUS = 'beta'
|
29
29
|
BUILD = ''.match(/(\d+)/).to_a.first
|
30
30
|
|
31
31
|
end
|
data/tabs_on_rails.gemspec
CHANGED
@@ -2,23 +2,22 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tabs_on_rails}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.8.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Simone Carletti"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-06-23}
|
10
10
|
s.description = %q{ TabsOnRails is a simple Ruby on Rails plugin for creating and managing Tabs. It provides helpers for creating tabs with a flexible interface.
|
11
11
|
}
|
12
12
|
s.email = %q{weppos@weppos.net}
|
13
13
|
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "LICENSE.rdoc", "README.rdoc"]
|
14
|
-
s.files = ["CHANGELOG.rdoc", "init.rb", "install.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "LICENSE.rdoc", "rails/init.rb", "Rakefile", "README.rdoc", "tabs_on_rails.gemspec", "tasks/tabs_on_rails_tasks.rake", "test/builder_test.rb", "test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/fixtures/mixin/standard.html.erb", "test/tabs_builder_test.rb", "test/tabs_on_rails_test.rb", "test/test_helper.rb", "uninstall.rb"
|
15
|
-
s.has_rdoc = true
|
14
|
+
s.files = ["CHANGELOG.rdoc", "init.rb", "install.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "LICENSE.rdoc", "Manifest", "rails/init.rb", "Rakefile", "README.rdoc", "tabs_on_rails.gemspec", "tasks/tabs_on_rails_tasks.rake", "test/builder_test.rb", "test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/controller_mixin_with_controller_test.rb", "test/fixtures/mixin/standard.html.erb", "test/tabs_builder_test.rb", "test/tabs_on_rails_test.rb", "test/test_helper.rb", "uninstall.rb"]
|
16
15
|
s.homepage = %q{http://code.simonecarletti.com/tabsonrails}
|
17
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tabs_on_rails", "--main", "README.rdoc"]
|
18
17
|
s.require_paths = ["lib"]
|
19
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
20
19
|
s.summary = %q{A simple Ruby on Rails plugin for creating and managing Tabs.}
|
21
|
-
s.test_files = ["test/builder_test.rb", "test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/
|
20
|
+
s.test_files = ["test/builder_test.rb", "test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/controller_mixin_with_controller_test.rb", "test/tabs_builder_test.rb", "test/tabs_on_rails_test.rb", "test/test_helper.rb"]
|
22
21
|
|
23
22
|
if s.respond_to? :specification_version then
|
24
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -13,6 +13,7 @@ class MockBuilder < TabsOnRails::Tabs::Builder
|
|
13
13
|
|
14
14
|
def tab_for(tab, name, *args)
|
15
15
|
end
|
16
|
+
|
16
17
|
end
|
17
18
|
|
18
19
|
class NilBoundariesBuilder < TabsOnRails::Tabs::Builder
|
@@ -35,10 +36,10 @@ end
|
|
35
36
|
|
36
37
|
|
37
38
|
class ControllerMixinHelpersTest < ActionView::TestCase
|
39
|
+
tests TabsOnRails::ControllerMixin::HelperMethods
|
38
40
|
include ActionView::Helpers::TagHelper
|
39
41
|
include ActionView::Helpers::UrlHelper
|
40
|
-
|
41
|
-
|
42
|
+
|
42
43
|
|
43
44
|
def test_tabs_tag_should_raise_local_jump_error_without_block
|
44
45
|
assert_raise(LocalJumpError) { tabs_tag }
|
@@ -81,12 +82,4 @@ class ControllerMixinHelpersTest < ActionView::TestCase
|
|
81
82
|
assert_dom_equal('<br /><span>Single</span>', content)
|
82
83
|
end
|
83
84
|
|
84
|
-
|
85
|
-
# Deprecated.
|
86
|
-
def test_deprecated_tabs_tag_with_builder
|
87
|
-
assert_deprecated do
|
88
|
-
tabs_tag(NilBoundariesBuilder) {}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
85
|
end
|
@@ -1,98 +1,90 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class ControllerMixinTest < ActiveSupport::TestCase
|
4
|
+
include ControllerTestHelpers
|
5
5
|
|
6
|
+
class MixinController < ActionController::Base
|
7
|
+
end
|
6
8
|
|
7
|
-
class ControllerMixinTest < ActiveSupport::TestCase
|
8
|
-
|
9
9
|
def setup
|
10
|
-
@controller
|
11
|
-
@
|
12
|
-
@
|
10
|
+
@controller = MixinController.new
|
11
|
+
@controller_proxy = ControllerProxy.new(@controller)
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
13
14
|
end
|
14
15
|
|
15
16
|
|
16
17
|
def test_set_tab
|
17
|
-
|
18
|
-
assert_equal(:footab,
|
18
|
+
controller.set_tab :footab
|
19
|
+
assert_equal(:footab, controller.tab_stack[:default])
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_set_tab_with_namespace
|
22
|
-
|
23
|
-
assert_equal(:footab,
|
23
|
+
controller.set_tab :footab, :namespace
|
24
|
+
assert_equal(:footab, controller.tab_stack[:namespace])
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_set_tab_with_default_namespace
|
27
|
-
|
28
|
-
assert_equal(:footab,
|
28
|
+
controller.set_tab :footab, :default
|
29
|
+
assert_equal(:footab, controller.tab_stack[:default])
|
29
30
|
end
|
30
31
|
|
31
32
|
def test_set_tab_with_and_without_namespace
|
32
|
-
|
33
|
-
|
34
|
-
assert_equal(:firsttab,
|
35
|
-
assert_equal(:secondtab,
|
33
|
+
controller.set_tab :firsttab
|
34
|
+
controller.set_tab :secondtab, :custom
|
35
|
+
assert_equal(:firsttab, controller.tab_stack[:default])
|
36
|
+
assert_equal(:secondtab, controller.tab_stack[:custom])
|
36
37
|
end
|
37
38
|
|
38
39
|
|
39
40
|
def test_current_tab
|
40
|
-
|
41
|
-
assert_equal(:mytab,
|
41
|
+
controller.tab_stack[:default] = :mytab
|
42
|
+
assert_equal(:mytab, controller.current_tab)
|
42
43
|
end
|
43
44
|
|
44
45
|
def test_current_tab_with_namespace
|
45
|
-
|
46
|
-
assert_equal(:mytab,
|
46
|
+
controller.tab_stack[:namespace] = :mytab
|
47
|
+
assert_equal(:mytab, controller.current_tab(:namespace))
|
47
48
|
end
|
48
49
|
|
49
50
|
def test_current_tab_with_default_namespace
|
50
|
-
|
51
|
-
assert_equal(:mytab,
|
51
|
+
controller.tab_stack[:default] = :mytab
|
52
|
+
assert_equal(:mytab, controller.current_tab(:default))
|
52
53
|
end
|
53
54
|
|
54
55
|
def test_set_tab_with_and_without_namespace
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal(:firsttab,
|
58
|
-
assert_equal(:secondtab,
|
56
|
+
controller.tab_stack[:default] = :firsttab
|
57
|
+
controller.tab_stack[:custom] = :secondtab
|
58
|
+
assert_equal(:firsttab, controller.current_tab(:default))
|
59
|
+
assert_equal(:secondtab, controller.current_tab(:custom))
|
59
60
|
end
|
60
61
|
|
61
62
|
|
62
63
|
def test_current_tab_question
|
63
|
-
|
64
|
-
assert(
|
65
|
-
assert(
|
64
|
+
controller.tab_stack[:default] = :mytab
|
65
|
+
assert( controller.current_tab?(:mytab))
|
66
|
+
assert(!controller.current_tab?(:yourtab))
|
66
67
|
end
|
67
68
|
|
68
69
|
def test_current_tab_question_with_namespace
|
69
|
-
|
70
|
-
assert(
|
71
|
-
assert(
|
70
|
+
controller.tab_stack[:custom] = :mytab
|
71
|
+
assert( controller.current_tab?(:mytab, :custom))
|
72
|
+
assert(!controller.current_tab?(:yourtab, :custom))
|
72
73
|
end
|
73
74
|
|
74
75
|
def test_current_tab_question_with_default_namespace
|
75
|
-
|
76
|
-
assert(
|
77
|
-
assert(
|
76
|
+
controller.tab_stack[:default] = :mytab
|
77
|
+
assert( controller.current_tab?(:mytab, :default))
|
78
|
+
assert(!controller.current_tab?(:yourtab, :default))
|
78
79
|
end
|
79
80
|
|
80
81
|
def test_current_tab_question_with_and_without_namespace
|
81
|
-
|
82
|
-
|
83
|
-
assert(
|
84
|
-
assert(
|
85
|
-
assert(
|
86
|
-
assert(
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
# Deprecated.
|
91
|
-
def test_deprecated_current_tab_setter
|
92
|
-
assert_deprecated do
|
93
|
-
@controller.current_tab = :footab
|
94
|
-
assert_equal(:footab, @controller.tab_stack[:default])
|
95
|
-
end
|
82
|
+
controller.tab_stack[:default] = :firsttab
|
83
|
+
controller.tab_stack[:custom] = :secondtab
|
84
|
+
assert( controller.current_tab?(:firsttab, :default))
|
85
|
+
assert(!controller.current_tab?(:secondtab, :default))
|
86
|
+
assert( controller.current_tab?(:secondtab, :custom))
|
87
|
+
assert(!controller.current_tab?(:firsttab, :custom))
|
96
88
|
end
|
97
89
|
|
98
|
-
end
|
90
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ControllerMixinWithControllerTest < ActiveSupport::TestCase
|
4
|
+
include ControllerTestHelpers
|
5
|
+
|
6
|
+
class MixinController < ActionController::Base
|
7
|
+
def self.controller_name; "mixin"; end
|
8
|
+
def self.controller_path; "mixin"; end
|
9
|
+
|
10
|
+
layout false
|
11
|
+
|
12
|
+
set_tab :dashboard
|
13
|
+
set_tab :welcome, :only => %w(action_welcome)
|
14
|
+
set_tab :dashboard, :only => %w(action_namespace)
|
15
|
+
set_tab :homepage, :namespace, :only => %w(action_namespace)
|
16
|
+
|
17
|
+
def method_missing(method, *args)
|
18
|
+
if method =~ /^action_(.*)/
|
19
|
+
render :action => (params[:template] || 'standard')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def rescue_action(e) raise end
|
24
|
+
end
|
25
|
+
|
26
|
+
MixinController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
|
27
|
+
|
28
|
+
def setup
|
29
|
+
@controller = MixinController.new
|
30
|
+
@controller_proxy = ControllerProxy.new(@controller)
|
31
|
+
@request = ActionController::TestRequest.new
|
32
|
+
@response = ActionController::TestResponse.new
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_set_tab
|
37
|
+
get :action_dashboard
|
38
|
+
assert_equal(:dashboard, controller.current_tab)
|
39
|
+
assert_equal(:dashboard, controller.current_tab(:default))
|
40
|
+
assert_equal(%Q{<ul>
|
41
|
+
<li><span>Dashboard</span></li>
|
42
|
+
<li><a href="/w">Welcome</a></li>
|
43
|
+
</ul>}, @response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_set_tab_with_only_option
|
47
|
+
get :action_welcome
|
48
|
+
assert_equal(:welcome, controller.current_tab)
|
49
|
+
assert_equal(:welcome, controller.current_tab(:default))
|
50
|
+
assert_equal(%Q{<ul>
|
51
|
+
<li><a href="/d">Dashboard</a></li>
|
52
|
+
<li><span>Welcome</span></li>
|
53
|
+
</ul>}, @response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_set_tab_with_namespace
|
57
|
+
get :action_namespace
|
58
|
+
assert_equal(:dashboard, controller.current_tab)
|
59
|
+
assert_equal(:dashboard, controller.current_tab(:default))
|
60
|
+
assert_equal(:homepage, controller.current_tab(:namespace))
|
61
|
+
assert_equal(%Q{<ul>
|
62
|
+
<li><span>Dashboard</span></li>
|
63
|
+
<li><a href="/w">Welcome</a></li>
|
64
|
+
</ul>}, @response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_current_tab
|
68
|
+
get :action_dashboard
|
69
|
+
assert_equal :dashboard, controller.current_tab
|
70
|
+
assert_equal :dashboard, controller.current_tab(:default)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_current_tab_question
|
74
|
+
get :action_dashboard
|
75
|
+
assert controller.current_tab?(:dashboard)
|
76
|
+
assert controller.current_tab?(:dashboard, :default)
|
77
|
+
assert !controller.current_tab?(:foobar)
|
78
|
+
assert !controller.current_tab?(:foobar, :default)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/test/tabs_builder_test.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
class TabsBuilderTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TabsBuilderTemplate
|
6
|
+
include ActionView::Helpers::TagHelper
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
|
9
|
+
def current_tab(namespace)
|
10
|
+
case namespace
|
11
|
+
when nil, :default
|
12
|
+
:dashboard
|
13
|
+
when :foospace
|
14
|
+
:footab
|
15
|
+
else
|
16
|
+
:elsetab
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
|
-
end
|
18
|
-
|
19
20
|
|
20
|
-
class TabBuilderTest < ActiveSupport::TestCase
|
21
|
-
|
22
21
|
def setup
|
23
|
-
@template =
|
22
|
+
@template = TabsBuilderTemplate.new
|
24
23
|
@builder = TabsOnRails::Tabs::TabsBuilder.new(@template)
|
25
24
|
end
|
26
25
|
|
data/test/test_helper.rb
CHANGED
@@ -28,3 +28,25 @@ ActionController::Routing::Routes.reload rescue nil
|
|
28
28
|
|
29
29
|
# Unit tests for Helpers are based on unit tests created and developed by Rails core team.
|
30
30
|
# See action_pack/test/abstract_unit for more details.
|
31
|
+
|
32
|
+
|
33
|
+
module ControllerTestHelpers
|
34
|
+
private
|
35
|
+
|
36
|
+
def controller
|
37
|
+
@controller_proxy
|
38
|
+
end
|
39
|
+
|
40
|
+
class ControllerProxy
|
41
|
+
def initialize(controller)
|
42
|
+
@controller = controller
|
43
|
+
end
|
44
|
+
def method_missing(method, *args)
|
45
|
+
@controller.instance_eval do
|
46
|
+
m = method(method)
|
47
|
+
m.call(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weppos-tabs_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Carletti
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/tabs_on_rails/version.rb
|
56
56
|
- lib/tabs_on_rails.rb
|
57
57
|
- LICENSE.rdoc
|
58
|
+
- Manifest
|
58
59
|
- rails/init.rb
|
59
60
|
- Rakefile
|
60
61
|
- README.rdoc
|
@@ -63,14 +64,13 @@ files:
|
|
63
64
|
- test/builder_test.rb
|
64
65
|
- test/controller_mixin_helpers_test.rb
|
65
66
|
- test/controller_mixin_test.rb
|
67
|
+
- test/controller_mixin_with_controller_test.rb
|
66
68
|
- test/fixtures/mixin/standard.html.erb
|
67
69
|
- test/tabs_builder_test.rb
|
68
70
|
- test/tabs_on_rails_test.rb
|
69
71
|
- test/test_helper.rb
|
70
72
|
- uninstall.rb
|
71
|
-
|
72
|
-
- test/controller_test.rb
|
73
|
-
has_rdoc: true
|
73
|
+
has_rdoc: false
|
74
74
|
homepage: http://code.simonecarletti.com/tabsonrails
|
75
75
|
post_install_message:
|
76
76
|
rdoc_options:
|
@@ -105,7 +105,7 @@ test_files:
|
|
105
105
|
- test/builder_test.rb
|
106
106
|
- test/controller_mixin_helpers_test.rb
|
107
107
|
- test/controller_mixin_test.rb
|
108
|
-
- test/
|
108
|
+
- test/controller_mixin_with_controller_test.rb
|
109
109
|
- test/tabs_builder_test.rb
|
110
110
|
- test/tabs_on_rails_test.rb
|
111
111
|
- test/test_helper.rb
|
data/test/controller_test.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MixinController < ActionController::Base
|
4
|
-
def self.controller_name; "mixin"; end
|
5
|
-
def self.controller_path; "mixin"; end
|
6
|
-
|
7
|
-
layout false
|
8
|
-
|
9
|
-
set_tab :dashboard
|
10
|
-
set_tab :welcome, :only => %w(action_welcome)
|
11
|
-
set_tab :dashboard, :only => %w(action_namespace)
|
12
|
-
set_tab :homepage, :namespace, :only => %w(action_namespace)
|
13
|
-
|
14
|
-
# Deprecated.
|
15
|
-
current_tab :deprecated, :only => %w(action_current_tab)
|
16
|
-
|
17
|
-
|
18
|
-
def method_missing(method, *args)
|
19
|
-
if method =~ /^action_(.*)/
|
20
|
-
render :action => (params[:template] || 'standard')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def rescue_action(e) raise end
|
25
|
-
end
|
26
|
-
|
27
|
-
MixinController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
|
28
|
-
|
29
|
-
|
30
|
-
class ControllerMixinTest < ActiveSupport::TestCase
|
31
|
-
|
32
|
-
def setup
|
33
|
-
@controller = MixinController.new
|
34
|
-
@request = ActionController::TestRequest.new
|
35
|
-
@response = ActionController::TestResponse.new
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_set_tab
|
39
|
-
get :action_dashboard
|
40
|
-
assert_equal(:dashboard, @controller.current_tab)
|
41
|
-
assert_equal(:dashboard, @controller.current_tab(:default))
|
42
|
-
assert_equal(%Q{<ul>
|
43
|
-
<li><span>Dashboard</span></li>
|
44
|
-
<li><a href="/w">Welcome</a></li>
|
45
|
-
</ul>}, @response.body)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_set_tab_with_only_option
|
49
|
-
get :action_welcome
|
50
|
-
assert_equal(:welcome, @controller.current_tab)
|
51
|
-
assert_equal(:welcome, @controller.current_tab(:default))
|
52
|
-
assert_equal(%Q{<ul>
|
53
|
-
<li><a href="/d">Dashboard</a></li>
|
54
|
-
<li><span>Welcome</span></li>
|
55
|
-
</ul>}, @response.body)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_set_tab_with_namespace
|
59
|
-
get :action_namespace
|
60
|
-
assert_equal(:dashboard, @controller.current_tab)
|
61
|
-
assert_equal(:dashboard, @controller.current_tab(:default))
|
62
|
-
assert_equal(:homepage, @controller.current_tab(:namespace))
|
63
|
-
assert_equal(%Q{<ul>
|
64
|
-
<li><span>Dashboard</span></li>
|
65
|
-
<li><a href="/w">Welcome</a></li>
|
66
|
-
</ul>}, @response.body)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Deprecated
|
70
|
-
def test_deprecate_current_tab
|
71
|
-
get :action_current_tab
|
72
|
-
assert_equal(:deprecated, @controller.current_tab)
|
73
|
-
assert_equal(:deprecated, @controller.current_tab(:default))
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|