go_to_param 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/go_to_param.rb +16 -3
- data/lib/go_to_param/version.rb +1 -1
- data/spec/go_to_param_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05ddd7d3e4b2514e5f5136af63f0263f0bde08c9
|
4
|
+
data.tar.gz: 47acd514926425787274fa1452252147007ed803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c7e6949c134e0d72dce393533870c28860e8ea44bb51198e42869eba80c36bfee6dc09cb4dd5f288daec909b0f11f31087cfbde871dbbb56d5bcb24241421cb
|
7
|
+
data.tar.gz: ef121087d69984d484e37a647396076cd528eec877889185abf22f5cdff43bc287611bd4543e5707ce6ad635535d90f0044593dc872a2e8df5c89e95c4802de3
|
data/README.md
CHANGED
@@ -58,7 +58,7 @@ Note that these parameters always become transformed into a query string: if you
|
|
58
58
|
|
59
59
|
### hidden_go_to_tag
|
60
60
|
|
61
|
-
Pass the `go_to` parameter along with a form.
|
61
|
+
Pass the current `go_to` query parameter along with a form. Suitable e.g. if you're redirected from a restricted page to the login form.
|
62
62
|
|
63
63
|
``` erb
|
64
64
|
<h1>Log in</h1>
|
@@ -69,6 +69,21 @@ Pass the `go_to` parameter along with a form.
|
|
69
69
|
</form>
|
70
70
|
```
|
71
71
|
|
72
|
+
### hidden_go_to_here_tag
|
73
|
+
|
74
|
+
Pass the current/requested path as a `go_to` parameter along with a form. Suitable e.g. if you show a login form in a modal.
|
75
|
+
|
76
|
+
``` erb
|
77
|
+
<h1>Log in</h1>
|
78
|
+
|
79
|
+
<form>
|
80
|
+
<%= hidden_go_to_here_tag %>
|
81
|
+
…
|
82
|
+
</form>
|
83
|
+
```
|
84
|
+
|
85
|
+
Accepts additional query parameters just like [`go_to_here_params`](#go_to_here_params).
|
86
|
+
|
72
87
|
### go_to_params
|
73
88
|
|
74
89
|
Pass the `go_to` parameter along with a link.
|
data/lib/go_to_param.rb
CHANGED
@@ -3,7 +3,7 @@ require "go_to_param/version"
|
|
3
3
|
|
4
4
|
module GoToParam
|
5
5
|
def self.included(klass)
|
6
|
-
klass.helper_method :hidden_go_to_tag,
|
6
|
+
klass.helper_method :hidden_go_to_tag, :hidden_go_to_here_tag,
|
7
7
|
:go_to_params, :go_to_here_params,
|
8
8
|
:go_to_path, :go_to_path_or
|
9
9
|
end
|
@@ -12,13 +12,18 @@ module GoToParam
|
|
12
12
|
view_context.hidden_field_tag :go_to, go_to_path
|
13
13
|
end
|
14
14
|
|
15
|
+
def hidden_go_to_here_tag(additional_query_params = {})
|
16
|
+
view_context.hidden_field_tag :go_to, go_to_here_params(additional_query_params)[:go_to]
|
17
|
+
end
|
18
|
+
|
15
19
|
def go_to_params(other_params = {})
|
16
20
|
{ go_to: go_to_path }.merge(other_params)
|
17
21
|
end
|
18
22
|
|
19
23
|
def go_to_here_params(additional_query_params = {})
|
20
|
-
|
21
|
-
|
24
|
+
path = go_to_here_path(additional_query_params)
|
25
|
+
|
26
|
+
if path
|
22
27
|
{ go_to: path }
|
23
28
|
else
|
24
29
|
{}
|
@@ -40,6 +45,14 @@ module GoToParam
|
|
40
45
|
|
41
46
|
private
|
42
47
|
|
48
|
+
def go_to_here_path(additional_query_params = {})
|
49
|
+
if request.get?
|
50
|
+
_go_to_add_query_string_from_hash(request.fullpath, additional_query_params)
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
43
56
|
def go_to_param_value
|
44
57
|
params[:go_to]
|
45
58
|
end
|
data/lib/go_to_param/version.rb
CHANGED
data/spec/go_to_param_spec.rb
CHANGED
@@ -32,6 +32,31 @@ describe GoToParam do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "#hidden_go_to_here_tag" do
|
36
|
+
it "becomes a helper method" do
|
37
|
+
expect(FakeController.helper_methods).to include :hidden_go_to_here_tag
|
38
|
+
end
|
39
|
+
|
40
|
+
it "adds a hidden field tag" do
|
41
|
+
controller.request = double(get?: true, fullpath: "/example")
|
42
|
+
view = double
|
43
|
+
controller.view_context = view
|
44
|
+
|
45
|
+
expect(view).to receive(:hidden_field_tag).with(:go_to, "/example")
|
46
|
+
controller.hidden_go_to_here_tag
|
47
|
+
end
|
48
|
+
|
49
|
+
# Tested in more detail in #go_to_here_params.
|
50
|
+
it "accepts additional query parameters" do
|
51
|
+
controller.request = double(get?: true, fullpath: "/example?a=1")
|
52
|
+
view = double
|
53
|
+
controller.view_context = view
|
54
|
+
|
55
|
+
expect(view).to receive(:hidden_field_tag).with(:go_to, "/example?a=1&b=1+2")
|
56
|
+
controller.hidden_go_to_here_tag(b: "1 2")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
35
60
|
describe "#go_to_params" do
|
36
61
|
it "becomes a helper method" do
|
37
62
|
expect(FakeController.helper_methods).to include :go_to_params
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go_to_param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik N
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|