redirectr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +6 -5
  2. data/lib/redirectr.rb +96 -106
  3. metadata +21 -41
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Redirectr
1
+ # 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,7 +9,7 @@ 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
+ ## Installation
13
13
 
14
14
  With Rails 3, just at the following to your Gemfile
15
15
 
@@ -19,7 +19,7 @@ and then call
19
19
 
20
20
  bundle install
21
21
 
22
- == Example
22
+ ## Example
23
23
 
24
24
  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
25
 
@@ -44,8 +44,9 @@ and finally, in the 'create' action of your ContactsController:
44
44
  for more detailled examples, see the Rdoc documentation.
45
45
 
46
46
 
47
- == Changelog
47
+ ## Changelog
48
48
 
49
- 0.0.7: Add Rails 2 compatibility (Thanks to Falk Hoppe)
49
+ 0.0.8: Use ActiveSupport::Concern (Thanks to Dimitar Haralanov)
50
+ 0.0.7: Add Rails 3.0 compatibility (Thanks to Falk Hoppe)
50
51
 
51
52
  Copyright (c) 2010 Willem van Kerkhof <wvk@consolving.de>, released under the MIT license
data/lib/redirectr.rb CHANGED
@@ -2,16 +2,14 @@ module Redirectr
2
2
  REFERRER_PARAM_NAME = :referrer
3
3
 
4
4
  module ControllerMethods
5
- def self.included(base)
6
- base.send :include, InstanceMethods
7
- base.send :extend, ClassMethods
5
+ extend ActiveSupport::Concern
8
6
 
9
- base.send :helper_method,
10
- :current_path,
11
- :referrer_or_current_path,
12
- :back_or_default,
13
- :referrer_path,
14
- :referrer_param
7
+ included do
8
+ helper_method :current_path,
9
+ :referrer_or_current_path,
10
+ :back_or_default,
11
+ :referrer_path,
12
+ :referrer_param
15
13
  end
16
14
 
17
15
  module ClassMethods
@@ -29,119 +27,111 @@ module Redirectr
29
27
  end
30
28
  end
31
29
 
32
- module InstanceMethods
33
30
 
34
- # Return the name of the parameter used to pass the referrer path.
35
- # Use this instead of the real param name in creating your own links
36
- # to allow easily changing the name later
37
- # Example:
38
- #
39
- # <%= link_to my_messages_path :filter_by => 'date', referrer_param => current_path %>
40
- #
41
- def referrer_param
42
- Redirectr::REFERRER_PARAM_NAME
43
- end
31
+ # Return the name of the parameter used to pass the referrer path.
32
+ # Use this instead of the real param name in creating your own links
33
+ # to allow easily changing the name later
34
+ # Example:
35
+ #
36
+ # <%= link_to my_messages_path :filter_by => 'date', referrer_param => current_path %>
37
+ #
38
+ def referrer_param
39
+ Redirectr::REFERRER_PARAM_NAME
40
+ end
44
41
 
45
- # Return the path of the current request.
46
- # note that this path does NOT include any query parameters nor the hostname,
47
- # thus allowing you to navigate within the application only. This may be changed
48
- # in the future. If you need a different behaviour now, just overwrite this method
49
- # in your controller.
50
- # Example:
51
- #
52
- # <%= link_to my_messages_path referrer_param => current_path %>
53
- #
54
- def current_path
55
- # maybe we want to use request.env['REQUEST_URI'] in the future...?
56
- request.env['PATH_INFO']
57
- end
42
+ # Return the path of the current request.
43
+ # note that this path does NOT include any query parameters nor the hostname,
44
+ # thus allowing you to navigate within the application only. This may be changed
45
+ # in the future. If you need a different behaviour now, just overwrite this method
46
+ # in your controller.
47
+ # Example:
48
+ #
49
+ # <%= link_to my_messages_path referrer_param => current_path %>
50
+ #
51
+ def current_path
52
+ # maybe we want to use request.env['REQUEST_URI'] in the future...?
53
+ request.env['PATH_INFO']
54
+ end
58
55
 
59
- # Return the referrer or the current path, it the former is not set.
60
- # Useful in cases where there might be a redirect path that has to be
61
- # taken note of but in case it is not present, the current path will be
62
- # redirected back to.
63
- # Example:
64
- #
65
- # <%= link_to my_messages_path referrer_param => referrer_or_current_path %>
66
- #
67
- def referrer_or_current_path
68
- referrer_path.blank? ? current_path : referrer_path
69
- end
56
+ # Return the referrer or the current path, it the former is not set.
57
+ # Useful in cases where there might be a redirect path that has to be
58
+ # taken note of but in case it is not present, the current path will be
59
+ # redirected back to.
60
+ # Example:
61
+ #
62
+ # <%= link_to my_messages_path referrer_param => referrer_or_current_path %>
63
+ #
64
+ def referrer_or_current_path
65
+ referrer_path.blank? ? current_path : referrer_path
66
+ end
70
67
 
71
- # Used in back links, referrer based redirection after actions etc.
72
- # Accepts a default redirect path in case no param[referrer_param]
73
- # is set, default being root_path.
74
- # To set an own default path (per controller), you can overwrite
75
- # the default_path method (see below).
76
- # Example:
77
- #
78
- # class MyController
79
- # def create
80
- # @my = My.create(...)
81
- # redirect_to back_or_default(my_path)
82
- # end
83
- # end
84
- #
85
- # The above example will redirect to the referrer_path if it is defined, otherwise
86
- # it will redirect to the my_path
87
- #
88
- # Example:
89
- #
90
- # class MyController
91
- # def create
92
- # @my = My.create(...)
93
- # redirect_to back_or_default
94
- # end
95
- # end
96
- #
97
- # The above example will redirect to the referrer_path if it is defined, otherwise
98
- # it will redirect to the root_path of the application.
99
- def back_or_default(default = nil)
100
- unless referrer_path.blank?
101
- referrer_path
102
- else
103
- default || default_path
104
- end
68
+ # Used in back links, referrer based redirection after actions etc.
69
+ # Accepts a default redirect path in case no param[referrer_param]
70
+ # is set, default being root_path.
71
+ # To set an own default path (per controller), you can overwrite
72
+ # the default_path method (see below).
73
+ # Example:
74
+ #
75
+ # class MyController
76
+ # def create
77
+ # @my = My.create(...)
78
+ # redirect_to back_or_default(my_path)
79
+ # end
80
+ # end
81
+ #
82
+ # The above example will redirect to the referrer_path if it is defined, otherwise
83
+ # it will redirect to the my_path
84
+ #
85
+ # Example:
86
+ #
87
+ # class MyController
88
+ # def create
89
+ # @my = My.create(...)
90
+ # redirect_to back_or_default
91
+ # end
92
+ # end
93
+ #
94
+ # The above example will redirect to the referrer_path if it is defined, otherwise
95
+ # it will redirect to the root_path of the application.
96
+ def back_or_default(default = nil)
97
+ unless referrer_path.blank?
98
+ referrer_path
99
+ else
100
+ default || default_path
105
101
  end
102
+ end
106
103
 
107
- # to be overwritten by your controllers
108
- def default_path
109
- root_path
110
- end
111
-
112
- # Convenience method for params[referrer_param]
113
- def referrer_path
114
- params[referrer_param]
115
- end
104
+ # to be overwritten by your controllers
105
+ def default_path
106
+ root_path
116
107
  end
117
108
 
109
+ # Convenience method for params[referrer_param]
110
+ def referrer_path
111
+ params[referrer_param]
112
+ end
118
113
  end
119
114
 
120
115
  module Helpers
121
- def self.included(base)
122
- base.send :include, InstanceMethods
123
- end
124
-
125
- module InstanceMethods
126
- # Create a link back to the path specified in the referrer-param.
127
- # title can be either a text string or anything else like an image.
128
- # Remember to call #html_safe on the title argument if it contains
129
- # HTML and you are using Rails 3.
130
- def link_to_back(title, options = {})
131
- link_to title, back_or_default, options
132
- end
116
+ extend ActiveSupport::Concern
133
117
 
134
- # Create a hidden input field containing the referrer or current path.
135
- # Handy for use in forms that are called with a referrer param which
136
- # has to be passed on and respected by the form processing action.
137
- def hidden_referrer_input_tag(options = {})
138
- hidden_field_tag :referrer, referrer_or_current_path, options
139
- end
118
+ # Create a link back to the path specified in the referrer-param.
119
+ # title can be either a text string or anything else like an image.
120
+ # Remember to call #html_safe on the title argument if it contains
121
+ # HTML and you are using Rails 3.
122
+ def link_to_back(title, options = {})
123
+ link_to title, back_or_default, options
140
124
  end
141
125
 
126
+ # Create a hidden input field containing the referrer or current path.
127
+ # Handy for use in forms that are called with a referrer param which
128
+ # has to be passed on and respected by the form processing action.
129
+ def hidden_referrer_input_tag(options = {})
130
+ hidden_field_tag :referrer, referrer_or_current_path, options
131
+ end
142
132
  end # module Helpers
143
133
  end # module Redirectr
144
134
 
145
135
  ActionController::Base.send :include, Redirectr::ControllerMethods
146
136
  ActionView::Helpers.send :include, Redirectr::Helpers
147
- ActionView::Base.send :include, Redirectr::Helpers
137
+ ActionView::Base.send :include, Redirectr::Helpers
metadata CHANGED
@@ -1,69 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redirectr
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Willem van Kerkhof
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-06 00:00:00 +02:00
19
- default_executable:
12
+ date: 2013-03-27 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: Provides Rails-helper methods for referrer-style backlinks and setting redirect URLs after form submussion
14
+ description: Provides Rails-helper methods for referrer-style backlinks and setting
15
+ redirect URLs after form submussion
23
16
  email: wvk@consolving.de
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - README
32
22
  - init.rb
33
23
  - lib/redirectr.rb
34
- has_rdoc: true
35
24
  homepage: http://github.com/wvk/redirectr
36
25
  licenses: []
37
-
38
26
  post_install_message:
39
27
  rdoc_options: []
40
-
41
- require_paths:
28
+ require_paths:
42
29
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
30
+ required_ruby_version: !ruby/object:Gem::Requirement
44
31
  none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- hash: 3
49
- segments:
50
- - 0
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
37
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
61
42
  requirements: []
62
-
63
43
  rubyforge_project:
64
- rubygems_version: 1.5.3
44
+ rubygems_version: 1.8.23
65
45
  signing_key:
66
46
  specification_version: 3
67
47
  summary: Provides Rails-helper methods for referrer-style backlinks
68
48
  test_files: []
69
-
49
+ has_rdoc: