backable 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +100 -0
- data/Rakefile +18 -0
- data/lib/backable.rb +6 -0
- data/lib/backable/controller_concern.rb +64 -0
- data/lib/backable/railtie.rb +14 -0
- data/lib/backable/version.rb +3 -0
- data/lib/backable/view_helpers.rb +37 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 095956144db6fcc903c53b33120af7d25a464f09
|
4
|
+
data.tar.gz: ecabb07f23acf372edd21e54f156dec15ec1f46a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2158b7575b17e601ced19a6002dd82458edf07b33f33bd541fbefd9ff575ef9b25688c3763879dbd7db089bc755aaffee2682dedaf1183ab37b5982583ecf14
|
7
|
+
data.tar.gz: f7cf05592fe9b33acb8fc8a5d4c2522bd36caa47d388b09372d2c83b69a02d9a9c47bb2bb16da2dbb407fb6e466aa1ae1cba48409e3d2f49eacd2df3f97e5b84
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Rick Blommers
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Backable
|
2
|
+
|
3
|
+
A little gem for supporting back history in your applicaton.
|
4
|
+
It uses a simple request-parameter 'back' with every back-path separated with a '|'.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'backable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
$ bundle
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
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`.
|
23
|
+
|
24
|
+
|
25
|
+
### controller
|
26
|
+
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class FooBarsController < ApplicationController
|
30
|
+
|
31
|
+
def index
|
32
|
+
backable_push([:foo_bars]) #< push the back-url. This can be a string url
|
33
|
+
..
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
@foo_bar = FooBar.find(params[:id])
|
38
|
+
if @foo_bar.update(params[:foo_bar])
|
39
|
+
redirect_to backable_back_path, notice: "Data is saved"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Available controller methods:
|
47
|
+
|
48
|
+
| Method | description
|
49
|
+
| ------------------- | ---
|
50
|
+
| backable_push | Pushes the given url to the stack
|
51
|
+
| backable_url_for | url_for replacement which includes the 'back' parameter
|
52
|
+
| backable_back_path | Returns the path to the previous page
|
53
|
+
| |
|
54
|
+
| backable_param | Returns the back parameter for the given stack (internal method)
|
55
|
+
| backable_history | Returns and array of the previous paths
|
56
|
+
| backable_future | Returns the future paths (pushed on the stack in this request)
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
### views
|
61
|
+
|
62
|
+
To make this all work you need to replace all links in your application (link_to) to `backable_link_to`
|
63
|
+
|
64
|
+
```erb
|
65
|
+
<%= backable_link_to( [:edit, @item]) %>
|
66
|
+
```
|
67
|
+
|
68
|
+
To use this with buttons etc.. there's also the `backable_url_for` method
|
69
|
+
|
70
|
+
|
71
|
+
You can simple add a back-button via `backable_link_to_back`. This link goes back to previous page in the stack.
|
72
|
+
|
73
|
+
```erb
|
74
|
+
<%= backable_link_to_back %>
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
To remember your back-stack in forms you should use the `backable_form_item`
|
79
|
+
|
80
|
+
```erb
|
81
|
+
<%= backable_form_item %>
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
Available view-helper methods:
|
86
|
+
|
87
|
+
| Method | description
|
88
|
+
| --------------------- | ---
|
89
|
+
| backable_url_for | url_for replacement which includes the 'back' parameter
|
90
|
+
| backable_back_path | Returns the path to the previous page
|
91
|
+
| backable_form_item | A hidden form element that includes the 'back' parameter
|
92
|
+
| backable_link_to | link_to replacement which includes the 'back' parameter
|
93
|
+
| backable_link_to_back | A link_to call to the previous page (including the text t(backable.back))
|
94
|
+
| |
|
95
|
+
| backable_history | Returns and array of the previous paths
|
96
|
+
| backable_future | Returns the future paths (pushed on the stack in this request)
|
97
|
+
|
98
|
+
|
99
|
+
## License
|
100
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Backable'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
require 'bundler/gem_tasks'
|
data/lib/backable.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Backable
|
2
|
+
module ControllerConcern
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
helper_method :backable_history
|
8
|
+
helper_method :backable_future
|
9
|
+
helper_method :backable_back_path
|
10
|
+
helper_method :backable_url_for
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def backable_param( history=nil)
|
15
|
+
history ||= (backable_history + backable_future)
|
16
|
+
history.map{|bi| bi.to_s }.join("|")
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def backable_history
|
21
|
+
@backable_history ||= begin
|
22
|
+
(params[:back]||"").split('|').map do |v|
|
23
|
+
v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def backable_future
|
30
|
+
@backable_future ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def backable_back_path( fallback=nil )
|
35
|
+
back = backable_history.last
|
36
|
+
fallback = Rails.env.development? ? "http://watbenjedan.nl/" : :back
|
37
|
+
return fallback unless back
|
38
|
+
back_param = backable_param( backable_history[0..-2] )
|
39
|
+
back.index('?') ? "#{back}&back=#{CGI::escape(back_param)}" : "#{back}?back=#{CGI::escape(back_param)}"
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def backable_push(path)
|
44
|
+
path = polymorphic_path(path) if !path.kind_of?( String )
|
45
|
+
backable_future << "#{path}"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def backable_url_for( link_options, extra_options = {} )
|
50
|
+
args = extra_options.merge( back: backable_param )
|
51
|
+
|
52
|
+
# support for strings
|
53
|
+
if link_options.kind_of?( String )
|
54
|
+
url = link_options
|
55
|
+
url << ( link_options.index('?') ? '&' : '?' )
|
56
|
+
url << args.to_query
|
57
|
+
url
|
58
|
+
else
|
59
|
+
polymorphic_url( link_options, args )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Backable
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
initializer "backable.controller_concerns" do
|
5
|
+
ActiveSupport.on_load( :action_controller ){ include Backable::ControllerConcern }
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "backable.view_helpers" do
|
9
|
+
ActiveSupport.on_load( :action_view ){ include Backable::ViewHelpers }
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Backable
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
def backable_form_item
|
5
|
+
hidden_field_tag :back, backable_param
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def backable_link_to(name = nil, options = nil, html_options = nil, &block)
|
10
|
+
if block_given?
|
11
|
+
link_to backable_url_for(name), options, &block
|
12
|
+
else
|
13
|
+
link_to name, backable_url_for(options), html_options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def backable_link_to_back( name = nil, html_options = nil, &block)
|
19
|
+
if block_given?
|
20
|
+
arg1 = backable_back_path
|
21
|
+
arg2 = name
|
22
|
+
else
|
23
|
+
if name.kind_of?(Hash) && !html_options
|
24
|
+
arg1 = t('backable.back')
|
25
|
+
arg2 = backable_back_path
|
26
|
+
arg3 = name
|
27
|
+
else
|
28
|
+
arg1 = name
|
29
|
+
arg2 = backable_back_path
|
30
|
+
arg3 = html_options
|
31
|
+
end
|
32
|
+
end
|
33
|
+
link_to arg1, arg2, arg3, &block
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Blommers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: A rails gem for simplifying back-buttons
|
28
|
+
email:
|
29
|
+
- rick@blommersit.nl
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/backable.rb
|
38
|
+
- lib/backable/controller_concern.rb
|
39
|
+
- lib/backable/railtie.rb
|
40
|
+
- lib/backable/version.rb
|
41
|
+
- lib/backable/view_helpers.rb
|
42
|
+
homepage: https://github.com/gamecreature/backable
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.5.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: A rails gem for simplifying back-buttons
|
66
|
+
test_files: []
|