backable 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -7
- data/lib/backable.rb +4 -1
- data/lib/backable/controller_concern.rb +16 -21
- data/lib/backable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 30d039270e6119af14dee85f75a38078f2255e0ac61d1d8c7ed8af17294eb682
|
4
|
+
data.tar.gz: 1bd01076f804be9ebb5198509db200966edbfb2e3127e49efe0e8e52f9b316b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dea9a48262dc152a043fe11ca3f2bb5bf1b8a9702d7380a87bf581a0fc467e004966e6f37c8bc79275c28ba03fb8146bfeba626d2e8ca81bca0a56ec1cdb544
|
7
|
+
data.tar.gz: 38b23d4fa1c25c5b06e6ac4539f7da373f8cf76114eae1406647298806ddc840dd9ce0789b5d2dc7780e4b4f5800964e5a306a3dd4f8dbd4dce0b67b63e75710
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Backable
|
2
2
|
|
3
|
-
A little gem for supporting back history in your applicaton.
|
3
|
+
A little gem for supporting back history in your applicaton.
|
4
4
|
It uses a simple request-parameter 'back' with every back-path separated with a '|'.
|
5
5
|
|
6
6
|
## Installation
|
@@ -19,7 +19,13 @@ $ bundle
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
To use this plugin. You can build up the backable stack via the controller method `backable_push`.
|
22
|
-
To pass the history to the next page remember to use `backable_url_for` instead of `url_for`.
|
22
|
+
To pass the history to the next page remember to use `backable_url_for` instead of `url_for`.
|
23
|
+
|
24
|
+
You can configure the Backable.fallback_url, which is called when nothing is on the stack.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Backable.fallback_url
|
28
|
+
```
|
23
29
|
|
24
30
|
|
25
31
|
### controller
|
@@ -45,12 +51,12 @@ end
|
|
45
51
|
|
46
52
|
Available controller methods:
|
47
53
|
|
48
|
-
| Method | description
|
54
|
+
| Method | description
|
49
55
|
| ------------------- | ---
|
50
56
|
| backable_push | Pushes the given url to the stack
|
51
57
|
| backable_url_for | url_for replacement which includes the 'back' parameter
|
52
58
|
| backable_back_path | Returns the path to the previous page
|
53
|
-
| |
|
59
|
+
| |
|
54
60
|
| backable_param | Returns the back parameter for the given stack (internal method)
|
55
61
|
| backable_history | Returns and array of the previous paths
|
56
62
|
| backable_future | Returns the future paths (pushed on the stack in this request)
|
@@ -84,14 +90,14 @@ To remember your back-stack in forms you should use the `backable_form_item`
|
|
84
90
|
|
85
91
|
Available view-helper methods:
|
86
92
|
|
87
|
-
| Method | description
|
93
|
+
| Method | description
|
88
94
|
| --------------------- | ---
|
89
95
|
| backable_url_for | url_for replacement which includes the 'back' parameter
|
90
96
|
| backable_back_path | Returns the path to the previous page
|
91
|
-
| backable_form_item | A hidden form element that includes the 'back' parameter
|
97
|
+
| backable_form_item | A hidden form element that includes the 'back' parameter
|
92
98
|
| backable_link_to | link_to replacement which includes the 'back' parameter
|
93
99
|
| backable_link_to_back | A link_to call to the previous page (including the text t(backable.back))
|
94
|
-
| |
|
100
|
+
| |
|
95
101
|
| backable_history | Returns and array of the previous paths
|
96
102
|
| backable_future | Returns the future paths (pushed on the stack in this request)
|
97
103
|
|
data/lib/backable.rb
CHANGED
@@ -1,65 +1,60 @@
|
|
1
1
|
module Backable
|
2
2
|
module ControllerConcern
|
3
|
-
|
4
3
|
extend ActiveSupport::Concern
|
5
4
|
|
6
|
-
included do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
included do
|
6
|
+
if respond_to?(:helper_method)
|
7
|
+
helper_method :backable_param
|
8
|
+
helper_method :backable_history
|
9
|
+
helper_method :backable_future
|
10
|
+
helper_method :backable_back_path
|
11
|
+
helper_method :backable_url_for
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
15
|
def backable_param( history=nil)
|
16
16
|
history ||= (backable_history + backable_future)
|
17
|
-
history.map{|bi| bi.to_s }.join("|")
|
17
|
+
history.map{ |bi| bi.to_s }.join("|")
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
20
|
def backable_history
|
22
21
|
@backable_history ||= begin
|
23
|
-
(params[:back]||"").split('|').map do |v|
|
22
|
+
(params[:back] || "").split('|').map do |v|
|
24
23
|
v
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
29
27
|
|
30
28
|
def backable_future
|
31
29
|
@backable_future ||= []
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
32
|
def backable_back_path( fallback=nil )
|
36
33
|
back = backable_history.last
|
37
|
-
fallback =
|
34
|
+
fallback = Backable.fallback_url
|
38
35
|
return fallback unless back
|
39
|
-
|
36
|
+
|
37
|
+
back_param = backable_param( backable_history[0..-2] )
|
40
38
|
back.index('?') ? "#{back}&back=#{CGI::escape(back_param)}" : "#{back}?back=#{CGI::escape(back_param)}"
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
41
|
def backable_push(path)
|
45
42
|
path = polymorphic_path(path) if !path.kind_of?( String )
|
46
|
-
backable_future <<
|
43
|
+
backable_future << path.to_s
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
46
|
def backable_url_for( link_options, extra_options = {} )
|
51
47
|
args = extra_options.merge( back: backable_param )
|
52
48
|
|
53
49
|
# support for strings
|
54
50
|
if link_options.kind_of?( String )
|
55
|
-
url = link_options
|
56
|
-
url << ( link_options.index('?') ? '&' : '?' )
|
51
|
+
url = link_options
|
52
|
+
url << ( link_options.index('?') ? '&' : '?' )
|
57
53
|
url << args.to_query
|
58
54
|
url
|
59
55
|
else
|
60
56
|
polymorphic_url( link_options, args )
|
61
57
|
end
|
62
58
|
end
|
63
|
-
|
64
59
|
end
|
65
60
|
end
|
data/lib/backable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Blommers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.7.8
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: A rails gem for simplifying back-buttons
|