backpedal 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -0
- data/README.md +28 -0
- data/lib/backpedal.rb +3 -1
- data/lib/backpedal/actions.rb +12 -0
- data/lib/backpedal/{back_link_helper.rb → helpers/back_link_helper.rb} +0 -0
- data/lib/backpedal/helpers/stack_helper.rb +9 -0
- data/lib/backpedal/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ade430b7ab68f84c6ed65337ffa3b1b5cfef1bd44680c444e5ad5cbf3a5ded
|
4
|
+
data.tar.gz: 7181e86b2706a6ae1121c776058780f27aae89d0039096755c0b41c4ca5ac044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '092329a2ed0b7be1f3b9e94602214d40ce03e7968c2587419765f12a4f841805802b89a47a4e6d787f4b7eaab8d4c3cb28ccf2c628b340091d6da8cbf975e470'
|
7
|
+
data.tar.gz: 54b5ae10125122477cdf20fa9265bb89c4d7cff5dc847b1ad7a3e376f96b3f31c9af0538503eb136e462da226c686ae80ad41472ca1a89d72f61e67485635bf4
|
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -45,6 +45,24 @@ Have a specific path in mind? Try this:
|
|
45
45
|
<p> Here is where your users would appear be if you had some </p>
|
46
46
|
```
|
47
47
|
|
48
|
+
Wish to backpedal from the controller? Use the `stepback` method in your controller
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Class PagesController
|
52
|
+
def create
|
53
|
+
@page = Page.new(pages_params)
|
54
|
+
if @page.save
|
55
|
+
flash[:success] = "Yahoo! now to step back one level"
|
56
|
+
stepback
|
57
|
+
else
|
58
|
+
"something else"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Using `stepback` on a multi-step form or wizard, and want to redirect back to before it all began? Tell stepback how many pages you want to stepback with an optional argument: `stepback(3)`
|
65
|
+
|
48
66
|
What if you want a specific controller action to wipe out the navigation stack and restart at the current action? Then set a before_action filter to dissolve the navigation stack.
|
49
67
|
|
50
68
|
```ruby
|
@@ -67,6 +85,16 @@ end
|
|
67
85
|
|
68
86
|
If you add the initializer, it will overwrite the default skipped http verbs(new, edit, destroy). So make sure you include those if you want to skip those controller actions.
|
69
87
|
|
88
|
+
## Debugging
|
89
|
+
|
90
|
+
Are you finding it difficult to keep track of the navigation stack? Use the `stack` helper to print the navigation into any view.
|
91
|
+
|
92
|
+
```erb
|
93
|
+
<%# app/layouts/application.html.erb %>
|
94
|
+
<body>
|
95
|
+
<%= stack %>
|
96
|
+
<%= yield %>
|
97
|
+
```
|
70
98
|
## Contributing
|
71
99
|
|
72
100
|
Bug reports and pull requests are welcome on GitHub at https://github.com/greyoxide/backpedal.
|
data/lib/backpedal.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'backpedal/version'
|
2
2
|
require 'backpedal/builder'
|
3
3
|
require 'backpedal/actions'
|
4
|
-
require 'backpedal/back_link_helper'
|
4
|
+
require 'backpedal/helpers/back_link_helper'
|
5
|
+
require 'backpedal/helpers/stack_helper.rb'
|
5
6
|
|
6
7
|
module Backpedal
|
7
8
|
ActionView::Base.send :include, BackLinkHelper
|
9
|
+
ActionView::Base.send :include, StackHelper
|
8
10
|
ActionController::Base.send :include, Actions
|
9
11
|
end
|
data/lib/backpedal/actions.rb
CHANGED
@@ -26,6 +26,7 @@ module Actions
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def dissolve
|
29
|
+
# Erase the navigation stack and restart it at the current controller action.
|
29
30
|
session[:tree] = request.original_url
|
30
31
|
end
|
31
32
|
|
@@ -36,4 +37,15 @@ module Actions
|
|
36
37
|
tree.delete_if { |x| x = path }
|
37
38
|
session[:tree] = tree.join(",")
|
38
39
|
end
|
40
|
+
|
41
|
+
def stepback(steps = nil)
|
42
|
+
# Redirect to a specific point in the navigation stack from the controller
|
43
|
+
tree = session[:tree].split(",")
|
44
|
+
unless steps == nil
|
45
|
+
target = tree.reverse[steps - 1]
|
46
|
+
else
|
47
|
+
target = tree.last
|
48
|
+
end
|
49
|
+
redirect_to target
|
50
|
+
end
|
39
51
|
end
|
File without changes
|
data/lib/backpedal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backpedal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- greyoxide
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
@@ -55,8 +56,9 @@ files:
|
|
55
56
|
- bin/setup
|
56
57
|
- lib/backpedal.rb
|
57
58
|
- lib/backpedal/actions.rb
|
58
|
-
- lib/backpedal/back_link_helper.rb
|
59
59
|
- lib/backpedal/builder.rb
|
60
|
+
- lib/backpedal/helpers/back_link_helper.rb
|
61
|
+
- lib/backpedal/helpers/stack_helper.rb
|
60
62
|
- lib/backpedal/version.rb
|
61
63
|
homepage: https://github.com/Greyoxide/backpedal
|
62
64
|
licenses:
|
@@ -79,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
81
|
- !ruby/object:Gem::Version
|
80
82
|
version: '0'
|
81
83
|
requirements: []
|
82
|
-
rubygems_version: 3.0.
|
84
|
+
rubygems_version: 3.0.6
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: A Rails gem that gives your users a universal back link across multiple routes.
|