Skip to content
This repository
Browse code

Deprecation: remove deprecated link_to_image and link_image_to method…

…s. Use link_to(image_path(...), url).

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6405 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit dfc1285aad47d33db1004d8e604c093f774f8c37 1 parent d20b943
Jeremy Kemper authored March 13, 2007
2  actionpack/CHANGELOG
... ...
@@ -1,6 +1,6 @@
1 1
 *SVN*
2 2
 
3  
-* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. Privatize deprecated render_partial and render_partial_collection view methods.  [Jeremy Kemper]
  3
+* Deprecation: remove deprecated request, redirect, and dependency methods.  Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. Privatize deprecated render_partial and render_partial_collection view methods. Remove deprecated link_to_image and link_image_to helper methods.  [Jeremy Kemper]
4 4
 
5 5
 * Consistent public/protected/private visibility for chained methods.  #7813 [Dan Manges]
6 6
 
128  actionpack/lib/action_view/helpers/url_helper.rb
@@ -2,19 +2,19 @@
2 2
 
3 3
 module ActionView
4 4
   module Helpers #:nodoc:
5  
-    # Provides a set of methods for making easy links and getting urls that 
6  
-    # depend on the controller and action. This means that you can use the 
  5
+    # Provides a set of methods for making easy links and getting urls that
  6
+    # depend on the controller and action. This means that you can use the
7 7
     # same format for links in the views that you do in the controller.
8 8
     module UrlHelper
9 9
       include JavaScriptHelper
10  
-      
11  
-      # Returns the URL for the set of +options+ provided. This takes the 
12  
-      # same options as url_for in action controller. For a list, see the 
13  
-      # documentation for ActionController::Base#url_for. Note that it'll 
14  
-      # set :only_path => true so you'll get the relative /controller/action 
  10
+
  11
+      # Returns the URL for the set of +options+ provided. This takes the
  12
+      # same options as url_for in action controller. For a list, see the
  13
+      # documentation for ActionController::Base#url_for. Note that it'll
  14
+      # set :only_path => true so you'll get the relative /controller/action
15 15
       # instead of the fully qualified http://example.com/controller/action.
16  
-      #  
17  
-      # When called from a view, url_for returns an HTML escaped url. If you 
  16
+      #
  17
+      # When called from a view, url_for returns an HTML escaped url. If you
18 18
       # need an unescaped url, pass :escape => false in the +options+.
19 19
       def url_for(options = {}, *parameters_for_method_reference)
20 20
         if options.kind_of? Hash
@@ -28,29 +28,29 @@ def url_for(options = {}, *parameters_for_method_reference)
28 28
         escape ? html_escape(url) : url
29 29
       end
30 30
 
31  
-      # Creates a link tag of the given +name+ using a URL created by the set 
32  
-      # of +options+. See the valid options in the documentation for 
33  
-      # ActionController::Base#url_for. It's also possible to pass a string instead 
34  
-      # of an options hash to get a link tag that uses the value of the string as the 
35  
-      # href for the link. If nil is passed as a name, the link itself will become 
  31
+      # Creates a link tag of the given +name+ using a URL created by the set
  32
+      # of +options+. See the valid options in the documentation for
  33
+      # ActionController::Base#url_for. It's also possible to pass a string instead
  34
+      # of an options hash to get a link tag that uses the value of the string as the
  35
+      # href for the link. If nil is passed as a name, the link itself will become
36 36
       # the name.
37 37
       #
38 38
       # The +html_options+ will accept a hash of html attributes for the link tag.
39  
-      # It also accepts 3 modifiers that specialize the link behavior. 
  39
+      # It also accepts 3 modifiers that specialize the link behavior.
40 40
       #
41  
-      # * <tt>:confirm => 'question?'</tt>: This will add a JavaScript confirm 
42  
-      #   prompt with the question specified. If the user accepts, the link is 
  41
+      # * <tt>:confirm => 'question?'</tt>: This will add a JavaScript confirm
  42
+      #   prompt with the question specified. If the user accepts, the link is
43 43
       #   processed normally, otherwise no action is taken.
44  
-      # * <tt>:popup => true || array of window options</tt>: This will force the 
45  
-      #   link to open in a popup window. By passing true, a default browser window 
46  
-      #   will be opened with the URL. You can also specify an array of options 
  44
+      # * <tt>:popup => true || array of window options</tt>: This will force the
  45
+      #   link to open in a popup window. By passing true, a default browser window
  46
+      #   will be opened with the URL. You can also specify an array of options
47 47
       #   that are passed-thru to JavaScripts window.open method.
48 48
       # * <tt>:method => symbol of HTTP verb</tt>: This modifier will dynamically
49  
-      #   create an HTML form and immediately submit the form for processing using 
  49
+      #   create an HTML form and immediately submit the form for processing using
50 50
       #   the HTTP verb specified. Useful for having links perform a POST operation
51 51
       #   in dangerous actions like deleting a record (which search bots can follow
52 52
       #   while spidering your site). Supported verbs are :post, :delete and :put.
53  
-      #   Note that if the user has JavaScript disabled, the request will fall back 
  53
+      #   Note that if the user has JavaScript disabled, the request will fall back
54 54
       #   to using GET. If you are relying on the POST behavior, your should check
55 55
       #   for it in your controllers action by using the request objects methods
56 56
       #   for post?, delete? or put?.
@@ -88,7 +88,7 @@ def link_to(name, options = {}, html_options = nil, *parameters_for_method_refer
88 88
       # the form submission and input element behavior using +html_options+.
89 89
       # This method accepts the <tt>:method</tt> and <tt>:confirm</tt> modifiers
90 90
       # described in the link_to documentation. If no <tt>:method</tt> modifier
91  
-      # is given, it will default to performing a POST operation. You can also 
  91
+      # is given, it will default to performing a POST operation. You can also
92 92
       # disable the button by passing <tt>:disabled => true</tt> in +html_options+.
93 93
       #
94 94
       #   button_to "New", :action => "new"
@@ -133,52 +133,14 @@ def button_to(name, options = {}, html_options = {})
133 133
         name ||= url
134 134
 
135 135
         html_options.merge!("type" => "submit", "value" => name)
136  
-        
137  
-        "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" + 
138  
-          method_tag + tag("input", html_options) + "</div></form>"
139  
-      end
140  
-
141  
-
142  
-      # DEPRECATED. It is reccommended to use the AssetTagHelper::image_tag within
143  
-      # a link_to method to generate a linked image.
144  
-      # 
145  
-      #   link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com")
146  
-      def link_image_to(src, options = {}, html_options = {}, *parameters_for_method_reference)
147  
-        image_options = { "src" => src.include?("/") ? src : "/images/#{src}" }
148  
-        image_options["src"] += ".png" unless image_options["src"].include?(".")
149  
-
150  
-        html_options = html_options.stringify_keys
151  
-        if html_options["alt"]
152  
-          image_options["alt"] = html_options["alt"]
153  
-          html_options.delete "alt"
154  
-        else
155  
-          image_options["alt"] = src.split("/").last.split(".").first.capitalize
156  
-        end
157  
-
158  
-        if html_options["size"]
159  
-          image_options["width"], image_options["height"] = html_options["size"].split("x")
160  
-          html_options.delete "size"
161  
-        end
162  
-
163  
-        if html_options["border"]
164  
-          image_options["border"] = html_options["border"]
165  
-          html_options.delete "border"
166  
-        end
167  
-
168  
-        if html_options["align"]
169  
-          image_options["align"] = html_options["align"]
170  
-          html_options.delete "align"
171  
-        end
172 136
 
173  
-        link_to(tag("img", image_options), options, html_options, *parameters_for_method_reference)
  137
+        "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
  138
+          method_tag + tag("input", html_options) + "</div></form>"
174 139
       end
175 140
 
176  
-      alias_method :link_to_image, :link_image_to
177  
-      deprecate :link_to_image => "use link_to(image_tag(...), url)",
178  
-        :link_image_to => "use link_to(image_tag(...), url)"
179 141
 
180 142
       # Creates a link tag of the given +name+ using a URL created by the set of
181  
-      # +options+ unless the current request uri is the same as the links, in 
  143
+      # +options+ unless the current request uri is the same as the links, in
182 144
       # which case only the name is returned (or the given block is yielded, if
183 145
       # one exists). Refer to the documentation for link_to_unless for block usage.
184 146
       #
@@ -198,7 +160,7 @@ def link_to_unless_current(name, options = {}, html_options = {}, *parameters_fo
198 160
       end
199 161
 
200 162
       # Creates a link tag of the given +name+ using a URL created by the set of
201  
-      # +options+ unless +condition+ is true, in which case only the name is 
  163
+      # +options+ unless +condition+ is true, in which case only the name is
202 164
       # returned. To specialize the default behavior, you can pass a block that
203 165
       # accepts the name or the full argument list for link_to_unless (see the example).
204 166
       #
@@ -208,7 +170,7 @@ def link_to_unless_current(name, options = {}, html_options = {}, *parameters_fo
208 170
       #
209 171
       #   <%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
210 172
       #      link_to(name, { :controller => "accounts", :action => "signup" })
211  
-      #    end %>     
  173
+      #    end %>
212 174
       def link_to_unless(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
213 175
         if condition
214 176
           if block_given?
@@ -218,11 +180,11 @@ def link_to_unless(condition, name, options = {}, html_options = {}, *parameters
218 180
           end
219 181
         else
220 182
           link_to(name, options, html_options, *parameters_for_method_reference)
221  
-        end  
  183
+        end
222 184
       end
223  
-      
  185
+
224 186
       # Creates a link tag of the given +name+ using a URL created by the set of
225  
-      # +options+ if +condition+ is true, in which case only the name is 
  187
+      # +options+ if +condition+ is true, in which case only the name is
226 188
       # returned. To specialize the default behavior, you can pass a block that
227 189
       # accepts the name or the full argument list for link_to_unless (see the examples
228 190
       # in link_to_unless).
@@ -268,7 +230,7 @@ def link_to_if(condition, name, options = {}, html_options = {}, *parameters_for
268 230
       #   mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"  # =>
269 231
       #     <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
270 232
       #
271  
-      #   mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com", 
  233
+      #   mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com",
272 234
       #            :subject => "This is an example email"  # =>
273 235
       #     <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
274 236
       def mail_to(email_address, name = nil, html_options = {})
@@ -333,19 +295,11 @@ def current_page?(options)
333 295
         def convert_options_to_javascript!(html_options)
334 296
           confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
335 297
 
336  
-          # post is deprecated, but if its specified and method is not, assume that method = :post
337  
-          method, post   = html_options.delete("method"), html_options.delete("post")
338  
-          if !method && post
339  
-            ActiveSupport::Deprecation.warn(
340  
-              "Passing :post as a link modifier is deprecated. " +
341  
-              "Use :method => \"post\" instead. :post will be removed in Rails 2.0."
342  
-            )
343  
-            method = :post
344  
-          end
345  
-        
  298
+          method = html_options.delete("method")
  299
+
346 300
           html_options["onclick"] = case
347 301
             when popup && method
348  
-              raise ActionView::ActionViewError, "You can't use :popup and :post in the same link"
  302
+              raise ActionView::ActionViewError, "You can't use :popup and :method in the same link"
349 303
             when confirm && popup
350 304
               "if (#{confirm_javascript_function(confirm)}) { #{popup_javascript_function(popup)} };return false;"
351 305
             when confirm && method
@@ -360,25 +314,25 @@ def convert_options_to_javascript!(html_options)
360 314
               html_options["onclick"]
361 315
           end
362 316
         end
363  
-        
  317
+
364 318
         def confirm_javascript_function(confirm)
365 319
           "confirm('#{escape_javascript(confirm)}')"
366 320
         end
367  
-        
  321
+
368 322
         def popup_javascript_function(popup)
369 323
           popup.is_a?(Array) ? "window.open(this.href,'#{popup.first}','#{popup.last}');" : "window.open(this.href);"
370 324
         end
371  
-        
  325
+
372 326
         def method_javascript_function(method)
373  
-          submit_function = 
  327
+          submit_function =
374 328
             "var f = document.createElement('form'); f.style.display = 'none'; " +
375 329
             "this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;"
376  
-          
  330
+
377 331
           unless method == :post
378 332
             submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "
379 333
             submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);"
380 334
           end
381  
-          
  335
+
382 336
           submit_function << "f.submit();"
383 337
         end
384 338
 
57  actionpack/test/template/url_helper_test.rb
@@ -17,7 +17,7 @@ def url_for(options, *parameters_for_method_reference)
17 17
     @controller = @controller.new
18 18
     @controller.url = "http://www.example.com"
19 19
   end
20  
-  
  20
+
21 21
   def test_url_for_escapes_urls
22 22
     @controller.url = "http://www.example.com?a=b&c=d"
23 23
     assert_equal "http://www.example.com?a=b&amp;c=d", url_for(:a => 'b', :c => 'd')
@@ -59,14 +59,14 @@ def test_button_to_enabled_disabled
59 59
       button_to("Hello", "http://www.example.com", :disabled => true)
60 60
     )
61 61
   end
62  
-  
  62
+
63 63
   def test_button_to_with_method_delete
64 64
     assert_dom_equal(
65 65
       "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"hidden\" name=\"_method\" value=\"delete\" /><input type=\"submit\" value=\"Hello\" /></div></form>",
66 66
       button_to("Hello", "http://www.example.com", :method => :delete)
67 67
     )
68 68
   end
69  
-  
  69
+
70 70
   def test_button_to_with_method_get
71 71
     assert_dom_equal(
72 72
       "<form method=\"get\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
@@ -97,18 +97,18 @@ def test_link_with_nil_html_options
97 97
   def test_link_tag_with_custom_onclick
98 98
     assert_dom_equal "<a href=\"http://www.example.com\" onclick=\"alert('yay!')\">Hello</a>", link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')")
99 99
   end
100  
-  
  100
+
101 101
   def test_link_tag_with_javascript_confirm
102 102
     assert_dom_equal(
103 103
       "<a href=\"http://www.example.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>",
104 104
       link_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
105 105
     )
106 106
     assert_dom_equal(
107  
-      "<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure, can you?');\">Hello</a>", 
  107
+      "<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure, can you?');\">Hello</a>",
108 108
       link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure, can you?")
109 109
     )
110 110
     assert_dom_equal(
111  
-      "<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure,\\n can you?');\">Hello</a>", 
  111
+      "<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure,\\n can you?');\">Hello</a>",
112 112
       link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure,\n can you?")
113 113
     )
114 114
   end
@@ -119,15 +119,15 @@ def test_link_tag_with_popup
119 119
       link_to("Hello", "http://www.example.com", :popup => true)
120 120
     )
121 121
     assert_dom_equal(
122  
-      "<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>", 
  122
+      "<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>",
123 123
       link_to("Hello", "http://www.example.com", :popup => 'true')
124 124
     )
125 125
     assert_dom_equal(
126  
-      "<a href=\"http://www.example.com\" onclick=\"window.open(this.href,'window_name','width=300,height=300');return false;\">Hello</a>", 
  126
+      "<a href=\"http://www.example.com\" onclick=\"window.open(this.href,'window_name','width=300,height=300');return false;\">Hello</a>",
127 127
       link_to("Hello", "http://www.example.com", :popup => ['window_name', 'width=300,height=300'])
128 128
     )
129 129
   end
130  
-  
  130
+
131 131
   def test_link_tag_with_popup_and_javascript_confirm
132 132
     assert_dom_equal(
133 133
       "<a href=\"http://www.example.com\" onclick=\"if (confirm('Fo\\' sho\\'?')) { window.open(this.href); };return false;\">Hello</a>",
@@ -138,16 +138,7 @@ def test_link_tag_with_popup_and_javascript_confirm
138 138
       link_to("Hello", "http://www.example.com", { :popup => ['window_name', 'width=300,height=300'], :confirm => "Are you serious?" })
139 139
     )
140 140
   end
141  
-  
142  
-  def test_link_tag_with_post_is_deprecated
143  
-    assert_deprecated 'post' do
144  
-      assert_dom_equal(
145  
-        "<a href='http://www.example.com' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Hello</a>",
146  
-        link_to("Hello", "http://www.example.com", :post => true)
147  
-      )
148  
-    end
149  
-  end
150  
-  
  141
+
151 142
   def test_link_tag_using_post_javascript
152 143
     assert_dom_equal(
153 144
       "<a href='http://www.example.com' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Hello</a>",
@@ -161,18 +152,18 @@ def test_link_tag_using_delete_javascript
161 152
       link_to("Destroy", "http://www.example.com", :method => :delete)
162 153
     )
163 154
   end
164  
-  
  155
+
165 156
   def test_link_tag_using_post_javascript_and_confirm
166 157
     assert_dom_equal(
167 158
       "<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit(); };return false;\">Hello</a>",
168 159
       link_to("Hello", "http://www.example.com", :method => :post, :confirm => "Are you serious?")
169  
-    )    
  160
+    )
170 161
   end
171  
-  
  162
+
172 163
   def test_link_tag_using_post_javascript_and_popup
173 164
     assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") }
174 165
   end
175  
-  
  166
+
176 167
   def test_link_to_unless
177 168
     assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog")
178 169
     assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_unless(false, "Listing", :action => "list", :controller => "weblog")
@@ -182,12 +173,12 @@ def test_link_to_unless
182 173
     }
183 174
     assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name|
184 175
       "<strong>#{name}</strong>"
185  
-    }    
  176
+    }
186 177
     assert_equal "test", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) {
187 178
       "test"
188  
-    }    
  179
+    }
189 180
   end
190  
-  
  181
+
191 182
   def test_link_to_if
192 183
     assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog")
193 184
     assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_if(true, "Listing", :action => "list", :controller => "weblog")
@@ -222,14 +213,14 @@ def test_mail_to
222 213
   def test_mail_to_with_javascript
223 214
     assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript")
224 215
   end
225  
-  
  216
+
226 217
   def test_mail_with_options
227 218
     assert_dom_equal(
228 219
       %(<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>),
229 220
       mail_to("me@example.com", "My email", :cc => "ccaddress@example.com", :bcc => "bccaddress@example.com", :subject => "This is an example email", :body => "This is the body of the message.")
230 221
     )
231 222
   end
232  
-  
  223
+
233 224
   def test_mail_to_with_img
234 225
     assert_dom_equal %(<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>), mail_to('feedback@example.com', '<img src="/feedback.png" />')
235 226
   end
@@ -257,7 +248,7 @@ def self.controller_path; 'url_helper_with_controller' end
257 248
     def show_url_for
258 249
       render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>"
259 250
     end
260  
-    
  251
+
261 252
     def show_named_route
262 253
       render :inline => "<%= show_named_route_#{params[:kind]} %>"
263 254
     end
@@ -272,26 +263,26 @@ def setup
272 263
     @response   = ActionController::TestResponse.new
273 264
     @controller = UrlHelperController.new
274 265
   end
275  
-  
  266
+
276 267
   def test_url_for_shows_only_path
277 268
     get :show_url_for
278 269
     assert_equal '/url_helper_with_controller/show_url_for', @response.body
279 270
   end
280  
-  
  271
+
281 272
   def test_named_route_shows_host_and_path
282 273
     with_url_helper_routing do
283 274
       get :show_named_route, :kind => 'url'
284 275
       assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
285 276
     end
286 277
   end
287  
-  
  278
+
288 279
   def test_named_route_path_shows_only_path
289 280
     with_url_helper_routing do
290 281
       get :show_named_route, :kind => 'path'
291 282
       assert_equal '/url_helper_with_controller/show_named_route', @response.body
292 283
     end
293 284
   end
294  
-  
  285
+
295 286
   protected
296 287
     def with_url_helper_routing
297 288
       with_routing do |set|

0 notes on commit dfc1285

Please sign in to comment.
Something went wrong with that request. Please try again.