stateful_link 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.rdoc +11 -3
- data/lib/stateful_link/action_any_of.rb +2 -2
- data/lib/stateful_link/version.rb +1 -1
- data/spec/controllers/action_any_of_spec.rb +7 -1
- metadata +3 -27
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
StatefulLink is a helper that simplifies displaying stateful navigation links. State
|
4
4
|
depends on current controller and action.
|
5
5
|
|
6
|
-
|
6
|
+
= Installation
|
7
7
|
|
8
8
|
Rails3 only Add the following line to your Gemfile:
|
9
9
|
|
10
10
|
gem 'stateful_link'
|
11
11
|
|
12
|
-
|
12
|
+
= Tutorial
|
13
13
|
|
14
14
|
Let we have RESTful PostsController and two navigation links in layout.
|
15
15
|
|
@@ -60,4 +60,12 @@ Solution:
|
|
60
60
|
</li>
|
61
61
|
</ul>
|
62
62
|
|
63
|
-
|
63
|
+
= Examples
|
64
|
+
|
65
|
+
posts/index.html.erb
|
66
|
+
|
67
|
+
<%= "we are in PostsController::index" if action_any_of?("posts#index") %>
|
68
|
+
<%= "we are in PostsController::index" if action_any_of?("#index") %>
|
69
|
+
<%= "action state is active" if action_state("#index") == :active %>
|
70
|
+
<%= "action state is chosen" if action_state("#show", ["#index", "#edit", "#update"]) == :chosen %>
|
71
|
+
<%= "action state is inactive" if action_state("users#index") == :inactive %>
|
@@ -23,7 +23,7 @@ module StatefulLink
|
|
23
23
|
actions.any? do |sub_ca|
|
24
24
|
unless sub_ca.empty?
|
25
25
|
sub_controller, sub_action = extract_controller_and_action(sub_ca)
|
26
|
-
self.controller_path == sub_controller && (self.action_name == sub_action || (sub_action == '' || sub_action == '*'))
|
26
|
+
((self.controller_path == sub_controller) || (sub_controller.blank?)) && (self.action_name == sub_action || (sub_action == '' || sub_action == '*'))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -42,7 +42,7 @@ module StatefulLink
|
|
42
42
|
raise ArgumentError, "Invalid action: #{ca}" if slash_pos.nil?
|
43
43
|
controller = ca[0, slash_pos]
|
44
44
|
action = ca[slash_pos+1..-1] || ""
|
45
|
-
raise ArgumentError, "Invalid action or controller" if
|
45
|
+
raise ArgumentError, "Invalid action or controller" if action.nil?
|
46
46
|
|
47
47
|
[controller, action]
|
48
48
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ApplicationController do
|
4
4
|
it "should extract controller and action" do
|
5
5
|
subject.extract_controller_and_action("friendships#index").should == ['friendships', 'index']
|
6
|
-
subject.extract_controller_and_action("friendships#").should == ['friendships', '']
|
6
|
+
subject.extract_controller_and_action("friendships#").should == ['friendships', '']
|
7
7
|
end
|
8
8
|
|
9
9
|
it "action_any_of should work" do
|
@@ -20,4 +20,10 @@ describe ApplicationController do
|
|
20
20
|
subject.action_state("application#index", "tests#index").should == :active
|
21
21
|
subject.action_state("application#index").should == :active
|
22
22
|
end
|
23
|
+
|
24
|
+
it "action_any_of should work relatively" do
|
25
|
+
get :index
|
26
|
+
subject.action_any_of?("#index").should be_true
|
27
|
+
subject.action_any_of?("#not_index").should be_false
|
28
|
+
end
|
23
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stateful_link
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
5
|
+
version: 0.0.5
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Victor Sokolov
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-04-05 00:00:00 +04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,9 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
|
-
segments:
|
31
|
-
- 3
|
32
24
|
version: "3"
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -40,10 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ~>
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 11
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 4
|
47
35
|
version: "2.4"
|
48
36
|
type: :development
|
49
37
|
version_requirements: *id002
|
@@ -55,9 +43,6 @@ dependencies:
|
|
55
43
|
requirements:
|
56
44
|
- - ">="
|
57
45
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
46
|
version: "0"
|
62
47
|
type: :development
|
63
48
|
version_requirements: *id003
|
@@ -69,9 +54,6 @@ dependencies:
|
|
69
54
|
requirements:
|
70
55
|
- - ">="
|
71
56
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
57
|
version: "0"
|
76
58
|
type: :development
|
77
59
|
version_requirements: *id004
|
@@ -145,23 +127,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
127
|
requirements:
|
146
128
|
- - ">="
|
147
129
|
- !ruby/object:Gem::Version
|
148
|
-
hash: 3
|
149
|
-
segments:
|
150
|
-
- 0
|
151
130
|
version: "0"
|
152
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
132
|
none: false
|
154
133
|
requirements:
|
155
134
|
- - ">="
|
156
135
|
- !ruby/object:Gem::Version
|
157
|
-
hash: 3
|
158
|
-
segments:
|
159
|
-
- 0
|
160
136
|
version: "0"
|
161
137
|
requirements: []
|
162
138
|
|
163
139
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 1.5.3
|
165
141
|
signing_key:
|
166
142
|
specification_version: 3
|
167
143
|
summary: Helper to generate stateful navigation links.
|