public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Reorganized URL generation methods across Controller classes

Organized the #url, #relative_url, and #absolute_url methods
across Merb::AbstractController and Merb::Controller
carllerche (author)
Tue Sep 30 13:54:10 -0700 2008
commit  b085564bc37ed1a46d1a727b533cd4a03097e2ab
tree    b232b0e212afef5bf1caa827ccd7eb141a130984
parent  62bbcc46c28e3921a1efb43b02da4f20b51d080e
...
430
431
432
433
 
434
435
436
...
452
453
454
455
 
456
457
458
459
460
461
 
 
 
 
 
 
 
 
462
463
464
465
 
466
467
468
...
430
431
432
 
433
434
435
436
...
452
453
454
 
455
456
457
 
 
 
 
458
459
460
461
462
463
464
465
466
 
 
 
467
468
469
470
0
@@ -430,7 +430,7 @@ class Merb::AbstractController
0
   # ====
0
   # TODO: Update this documentation
0
   def url(name, *args)
0
-    args << params
0
+    args << {}
0
     Merb::Router.url(name, *args)
0
   end
0
   
0
@@ -452,17 +452,19 @@ class Merb::AbstractController
0
   # ==== Alternatives
0
   # If a hash is used as the first argument, a default route will be
0
   # generated based on it and rparams.
0
-  def absolute_url(name, rparams={})
0
+  def absolute_url(name, *args)
0
     # FIXME: arrgh, why request.protocol returns http://?
0
     # :// is not part of protocol name
0
-    if rparams.is_a?(Hash)
0
-      protocol = rparams.delete(:protocol)
0
-      host = rparams.delete(:host)
0
-    end
0
+    options  = extract_options_from_args!(args) || {}
0
+    protocol = options.delete(:protocol)
0
+    host     = options.delete(:host)
0
+    
0
+    raise ArgumentError, "The :protocol option must be specified" unless protocol
0
+    raise ArgumentError, "The :host option must be specified"     unless host
0
+    
0
+    args << options
0
     
0
-    (protocol || request.protocol) + "://" +
0
-      (host || request.host) +
0
-      url(name, rparams)
0
+    protocol + "://" + host + url(name, *args)
0
   end
0
   
0
   # Generates a URL for a single or nested resource.
...
218
219
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
222
223
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
0
@@ -218,6 +218,33 @@ class Merb::Controller < Merb::AbstractController
0
   # ==== Returns
0
   # Hash:: The parameters from the request object
0
   def params()  request.params  end
0
+    
0
+  # ==== Parameters
0
+  # name<~to_sym, Hash>:: The name of the URL to generate.
0
+  # rparams<Hash>:: Parameters for the route generation.
0
+  #
0
+  # ==== Returns
0
+  # String:: The generated URL.
0
+  #
0
+  # ==== Alternatives
0
+  # If a hash is used as the first argument, a default route will be
0
+  # generated based on it and rparams.
0
+  # ====
0
+  # TODO: Update this documentation
0
+  def url(name, *args)
0
+    args << params
0
+    Merb::Router.url(name, *args)
0
+  end
0
+
0
+  alias_method :relative_url, :url
0
+  
0
+  def absolute_url(*args)
0
+    options  = extract_options_from_args!(args) || {}
0
+    options[:protocol] ||= request.protocol
0
+    options[:host] ||= request.host
0
+    args << options
0
+    super(args.first, *args[1..-1])
0
+  end
0
 
0
   # The results of the controller's render, to be returned to Rack.
0
   #

Comments