redirectr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README +41 -8
  3. data/lib/redirectr.rb +39 -13
  4. metadata +8 -12
  5. data/init.rb +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d2e5bda91ce0407fb196a450cf6adf0fc33aba2
4
+ data.tar.gz: bc3a10bed54b7ff7a3804d2894de0c8cb64d3a2d
5
+ SHA512:
6
+ metadata.gz: 3f6eba38b0be27a841e24ed82381723befad33f545cd6ac603f8da33e91d582afb7b4d826a7e65032d6f48113cc2c8ddd7c77bb8adab01c24e62694f05b3cbca
7
+ data.tar.gz: 9bc23622bb0a245bff831d0c7323149e91da3c44c011d8209cf22a90b9c0ae1c9d07d84ad011492bb6a5631423c3aa399be8763fceb2abebc1b745a4066275df
data/README CHANGED
@@ -1,4 +1,4 @@
1
- # Redirectr
1
+ h1. Redirectr
2
2
 
3
3
  In many web applications, the user triggers actions that result in simple or complex workflows that should, after that workflow is finished, result in the user being redirected to the page where he initially started it. Another example would be a "back"-Link on any page.
4
4
  A simple but completely Un-RESTful way would be to store the "current" page in a cookie each time the user calls an action and redirect to the url stored there if needed.
@@ -9,27 +9,29 @@ Redirectr really does nothing more than provide a simple API for exactly that.
9
9
 
10
10
  Redirectr provides a few Controller and Helper methods that will be included in your ApplicationController and ApplicationHelper, respectively.
11
11
 
12
- ## Installation
12
+ h2. Installation
13
13
 
14
- With Rails 3, just at the following to your Gemfile
14
+ when Using bundler, just at the following to your Gemfile
15
15
 
16
- gem 'redirectr', :git => 'https://github.com/wvk/redirectr.git'
16
+ gem 'redirectr'
17
17
 
18
18
  and then call
19
19
 
20
20
  bundle install
21
21
 
22
- ## Example
22
+ h2. Examples
23
+
24
+ h3. Contact Form
23
25
 
24
26
  Suppose you have an application with a contact form that can be reached via a footer link on every page. After submitting the form, the user should be redirected to the page he was before clicking on the "contact form" link.
25
27
 
26
28
  for the footer link to the contact form:
27
29
 
28
- <%= link_to 'Contact us!', new_contact_path(referrer_param => current_path) %>
30
+ <%= link_to 'Contact us!', new_contact_path(referrer_param => current_url) %>
29
31
 
30
32
  In the 'new contact' view:
31
33
 
32
- <%= form for ... do |f| %>
34
+ <%= form_for ... do |f| %>
33
35
  <%= hidden_referrer_input_tag %>
34
36
  <!-- ... -->
35
37
  <% end %>
@@ -41,11 +43,42 @@ and finally, in the 'create' action of your ContactsController:
41
43
  redirect_to back_or_default
42
44
  end
43
45
 
44
- for more detailled examples, see the Rdoc documentation.
46
+ h3. Custom default_url
47
+
48
+ The above will redirect the user back to the page specified in the referrer param. However, if you want to provide a custom fallback url per controller in case no referrer param is provided, just define the `#default_url` in your controller:
49
+
50
+ class MyController < ApplicationController
51
+ def default_url
52
+ if @record
53
+ my_record_path(@record)
54
+ else
55
+ my_record_index_path
56
+ end
57
+ end
58
+ end
59
+
60
+ h3. Nesting referrers
61
+
62
+ Referrer params can be nested, which is helpful if your workflow involves branching into subworkflows. Thus, it is always possible to pass the referrer_param to another url:
63
+
64
+ <%= link_to 'go back directly', referrer_or_current_url %>
65
+ <%= link_to 'add new Foobar before going back', new_foobar_url(:foobar => {:name => 'My Foo'}, referrer_param => referrer_or_current_url) %>
66
+
67
+ for more detailed examples, see the Rdoc documentation.
68
+
69
+ h2. Contributions
70
+
71
+ Contributions like bugfixes and new ideas are more than welcome. Please just fork this project on github (https://github.com/wvk/redirectr) and send me a pull request with your changes.
72
+
73
+ Thanks so far to:
45
74
 
75
+ * Falk Hoppe for Rails 2.3.x interoperability
76
+ * Dimitar Haralanov for Rails 3.0.x interoperability
77
+ * Raffael Schmid for spotting a typo in the gemspec description ;)
46
78
 
47
79
  ## Changelog
48
80
 
81
+ 0.1.1: deprecate *_path methods; improve Rails 5 compatibility by removing `alias` in view helpers
49
82
  0.1.0: Use absolute URI instead of path in current_path method
50
83
  0.0.8: Use ActiveSupport::Concern (Thanks to Dimitar Haralanov)
51
84
  0.0.7: Add Rails 3.0 compatibility (Thanks to Falk Hoppe)
@@ -1,3 +1,4 @@
1
+
1
2
  module Redirectr
2
3
  REFERRER_PARAM_NAME = :referrer
3
4
 
@@ -5,10 +6,10 @@ module Redirectr
5
6
  extend ActiveSupport::Concern
6
7
 
7
8
  included do
8
- helper_method :current_path,
9
- :referrer_or_current_path,
9
+ helper_method :current_path, :current_url,
10
+ :referrer_or_current_path, :referrer_or_current_url,
10
11
  :back_or_default,
11
- :referrer_path,
12
+ :referrer_path, :referrer_url,
12
13
  :referrer_param
13
14
  end
14
15
 
@@ -39,7 +40,7 @@ module Redirectr
39
40
  Redirectr::REFERRER_PARAM_NAME
40
41
  end
41
42
 
42
- # Return the complete uri of the current request.
43
+ # Return the complete URL of the current request.
43
44
  # Note that this path does include ALL query parameters and the host name,
44
45
  # thus allowing you to navigate back and forth between different hosts. If you
45
46
  # want the pre-0.1.0 behaviour back, just overwrite this method
@@ -48,9 +49,20 @@ module Redirectr
48
49
  #
49
50
  # <%= link_to my_messages_path referrer_param => current_path %>
50
51
  #
51
- def current_path
52
+ def current_url
52
53
  # request.env['PATH_INFO'] # old behaviour
53
- request.env['REQUEST_URI']
54
+ if request.respond_to? :url # for rack >= 2.0.0
55
+ request.url
56
+ elsif request.respond_to? :original_url # for rails >= 4.0.0
57
+ request.original_url
58
+ else
59
+ request.env['REQUEST_URI']
60
+ end
61
+ end
62
+
63
+ # deprecated
64
+ def current_path
65
+ current_url
54
66
  end
55
67
 
56
68
  # Return the referrer or the current path, it the former is not set.
@@ -61,15 +73,20 @@ module Redirectr
61
73
  #
62
74
  # <%= link_to my_messages_path referrer_param => referrer_or_current_path %>
63
75
  #
76
+ def referrer_or_current_url
77
+ referrer_path.blank? ? current_url : referrer_url
78
+ end
79
+
80
+ # deprecated
64
81
  def referrer_or_current_path
65
- referrer_path.blank? ? current_path : referrer_path
82
+ referrer_or_current_url
66
83
  end
67
84
 
68
85
  # Used in back links, referrer based redirection after actions etc.
69
86
  # Accepts a default redirect path in case no param[referrer_param]
70
87
  # is set, default being root_path.
71
88
  # To set an own default path (per controller), you can overwrite
72
- # the default_path method (see below).
89
+ # the default_url method (see below).
73
90
  # Example:
74
91
  #
75
92
  # class MyController
@@ -97,19 +114,29 @@ module Redirectr
97
114
  unless referrer_path.blank?
98
115
  referrer_path
99
116
  else
100
- default || default_path
117
+ default || default_url
101
118
  end
102
119
  end
103
120
 
104
121
  # to be overwritten by your controllers
105
- def default_path
122
+ def default_url
106
123
  root_path
107
124
  end
108
125
 
126
+ # deprecated
127
+ def default_path
128
+ default_url
129
+ end
130
+
109
131
  # Convenience method for params[referrer_param]
110
- def referrer_path
132
+ def referrer_url
111
133
  params[referrer_param]
112
134
  end
135
+
136
+ # deprecated
137
+ def referrer_path
138
+ referrer_url
139
+ end
113
140
  end
114
141
 
115
142
  module Helpers
@@ -127,12 +154,11 @@ module Redirectr
127
154
  # Handy for use in forms that are called with a referrer param which
128
155
  # has to be passed on and respected by the form processing action.
129
156
  def hidden_referrer_input_tag(options = {})
130
- hidden_field_tag :referrer, referrer_or_current_path, options
157
+ hidden_field_tag :referrer, referrer_or_current_url, options
131
158
  end
132
159
  end # module Helpers
133
160
  end # module Redirectr
134
161
 
135
-
136
162
  ActionController::Base.send :include, Redirectr::ControllerMethods
137
163
  ActionView::Helpers.send :include, Redirectr::Helpers
138
164
  ActionView::Base.send :include, Redirectr::Helpers
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redirectr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Willem van Kerkhof
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Provides Rails-helper methods for referrer-style backlinks and setting
15
14
  redirect URLs after form submission
@@ -19,31 +18,28 @@ extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
20
  - README
22
- - init.rb
23
21
  - lib/redirectr.rb
24
22
  homepage: http://github.com/wvk/redirectr
25
23
  licenses: []
24
+ metadata: {}
26
25
  post_install_message:
27
26
  rdoc_options: []
28
27
  require_paths:
29
28
  - lib
30
29
  required_ruby_version: !ruby/object:Gem::Requirement
31
- none: false
32
30
  requirements:
33
- - - ! '>='
31
+ - - ">="
34
32
  - !ruby/object:Gem::Version
35
33
  version: '0'
36
34
  required_rubygems_version: !ruby/object:Gem::Requirement
37
- none: false
38
35
  requirements:
39
- - - ! '>='
36
+ - - ">="
40
37
  - !ruby/object:Gem::Version
41
38
  version: '0'
42
39
  requirements: []
43
40
  rubyforge_project:
44
- rubygems_version: 1.8.23
41
+ rubygems_version: 2.5.2.1
45
42
  signing_key:
46
- specification_version: 3
47
- summary: Provides Rails-helper methods for referrer-style backlinks
43
+ specification_version: 4
44
+ summary: Provides Rails helper methods for referrer-style backlinks
48
45
  test_files: []
49
- has_rdoc:
data/init.rb DELETED
File without changes