backable 1.0.1 → 1.0.2

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
- SHA1:
3
- metadata.gz: d56bb72b78b644eeee2c5bf950a5c44101c884bc
4
- data.tar.gz: 7389b62e841330f5b310a1d44ee4384c493c9361
2
+ SHA256:
3
+ metadata.gz: 30d039270e6119af14dee85f75a38078f2255e0ac61d1d8c7ed8af17294eb682
4
+ data.tar.gz: 1bd01076f804be9ebb5198509db200966edbfb2e3127e49efe0e8e52f9b316b5
5
5
  SHA512:
6
- metadata.gz: 1a55507f21de70114cd4076e85fef1bfbe1bf1b2026b424cc15ef50f84f79308fb789326ce7536ac92ea1a5420aa347efa9996d980f3ccc7c07da369e69c58a0
7
- data.tar.gz: fe308f06dd1c7aafb3fff27ead55abf011ebddd2790a9aa26e9981cafe24be9e086604ab6adfb4bac97e19e5df318e5d36b528fd6ab14a61dbbaa93724f63590
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
 
@@ -3,4 +3,7 @@ require 'backable/controller_concern'
3
3
  require 'backable/view_helpers'
4
4
 
5
5
  module Backable
6
- end
6
+ mattr_accessor :fallback_url do
7
+ Rails.env.development? ? "http://watbenjedan.nl/" : :back
8
+ end
9
+ end
@@ -1,65 +1,60 @@
1
1
  module Backable
2
2
  module ControllerConcern
3
-
4
3
  extend ActiveSupport::Concern
5
4
 
6
- included do
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
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 = Rails.env.development? ? "http://watbenjedan.nl/" : :back
34
+ fallback = Backable.fallback_url
38
35
  return fallback unless back
39
- back_param = backable_param( backable_history[0..-2] )
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 << "#{path}"
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
@@ -1,3 +1,3 @@
1
1
  module Backable
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
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.1
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: 2016-08-24 00:00:00.000000000 Z
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.5.1
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