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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bcdbdc10ad6e75c56494c44096fcc98e3da7034
4
- data.tar.gz: 1b9a9d937839c56c37a6c172ef424e500f9dbeed
3
+ metadata.gz: 05ddd7d3e4b2514e5f5136af63f0263f0bde08c9
4
+ data.tar.gz: 47acd514926425787274fa1452252147007ed803
5
5
  SHA512:
6
- metadata.gz: ea38bfd2bd3a76343a031e19b6fd106bb856863ed35017fcfefe3609150e3e5e72cd906bf2eb1a3e082ab16dc3a5987dfd6717c6832379872f3d274beed3f901
7
- data.tar.gz: 446c1c4f865e199c74d42cdc3575e1a9adee83962078b7450b8aff67b0fac812ec767ce5380293bee7a57a9d2710d4c2d7ee4047e7ca78f0364c0a73a4b1e4cb
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
- if request.get?
21
- path = _go_to_add_query_string_from_hash(request.fullpath, additional_query_params)
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
@@ -1,3 +1,3 @@
1
1
  module GoToParam
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.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-19 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler