public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added the option to declare an asset_host as an object that responds to call 
(see http://github.com/dhh/asset-hosting-with-minimum-ssl for an example) [DHH]
dhh (author)
Thu Nov 27 08:51:33 -0800 2008
commit  229f959d15e451890db60dbb73f8565079977814
tree    c2ca2865b84f5895458dd71c557a75f07be3d68b
parent  3cc9d1c5ad1639283b43ee2b6099cb4f3b19bf23
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Added the option to declare an asset_host as an object that responds to call (see http://github.com/dhh/asset-hosting-with-minimum-ssl for an example) [DHH]
0
+
0
 * Added support for multiple routes.rb files (useful for plugin engines). This also means that draw will no longer clear the route set, you have to do that by hand (shouldn't make a difference to you unless you're doing some funky stuff) [DHH]
0
 
0
 * Dropped formatted_* routes in favor of just passing in :format as an option. This cuts resource routes generation in half #1359 [aaronbatalion]
...
80
81
82
 
 
 
 
 
 
83
84
85
...
359
360
361
 
362
363
364
...
629
630
631
632
 
 
633
634
635
636
 
 
637
638
639
...
80
81
82
83
84
85
86
87
88
89
90
91
...
365
366
367
368
369
370
371
...
636
637
638
 
639
640
641
642
 
 
643
644
645
646
647
0
@@ -80,6 +80,12 @@ module ActionView
0
     #     end
0
     #   }
0
     #
0
+    # You can also implement a custom asset host object that responds to the call method and tasks one or two parameters just like the proc.
0
+    #
0
+    #   config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
0
+    #     "http://asset%d.example.com", "https://asset1.example.com"
0
+    #   )
0
+    #
0
     # === Using asset timestamps
0
     #
0
     # By default, Rails will append all asset paths with that asset's timestamp. This allows you to set a cache-expiration date for the
0
@@ -359,6 +365,7 @@ module ActionView
0
       # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
0
       # is set to true (which is the case by default for the Rails production environment, but not for the development
0
       # environment). Examples:
0
+      
0
       #
0
       # ==== Examples
0
       #   stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
0
@@ -629,11 +636,12 @@ module ActionView
0
             # Pick an asset host for this source. Returns +nil+ if no host is set,
0
             # the host if no wildcard is set, the host interpolated with the
0
             # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
0
-            # or the value returned from invoking the proc if it's a proc.
0
+            # or the value returned from invoking the proc if it's a proc or the value from
0
+            # invoking call if it's an object responding to call.
0
             def compute_asset_host(source)
0
               if host = ActionController::Base.asset_host
0
-                if host.is_a?(Proc)
0
-                  case host.arity
0
+                if host.is_a?(Proc) || host.respond_to?(:call)
0
+                  case host.is_a?(Proc) ? host.arity : host.method(:call).arity
0
                   when 2
0
                     host.call(source, request)
0
                   else
...
359
360
361
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
363
364
...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
0
@@ -359,6 +359,46 @@ class AssetTagHelperTest < ActionView::TestCase
0
     FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
0
   end
0
 
0
+  def test_caching_javascript_include_tag_when_caching_on_with_2_argument_object_asset_host
0
+    ENV['RAILS_ASSET_ID'] = ''
0
+    ActionController::Base.asset_host = Class.new do
0
+      def call(source, request)
0
+        if request.ssl?
0
+          "#{request.protocol}#{request.host_with_port}"
0
+        else
0
+          "#{request.protocol}assets#{source.length}.example.com"
0
+        end
0
+      end
0
+    end.new
0
+
0
+    ActionController::Base.perform_caching = true
0
+
0
+    assert_equal '/javascripts/vanilla.js'.length, 23
0
+    assert_dom_equal(
0
+      %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
0
+      javascript_include_tag(:all, :cache => 'vanilla')
0
+    )
0
+
0
+    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
0
+
0
+    class << @controller.request
0
+      def protocol() 'https://' end
0
+      def ssl?() true end
0
+    end
0
+
0
+    assert_equal '/javascripts/secure.js'.length, 22
0
+    assert_dom_equal(
0
+      %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
0
+      javascript_include_tag(:all, :cache => 'secure')
0
+    )
0
+
0
+    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
0
+
0
+  ensure
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
0
+  end
0
+
0
   def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
0
     ENV["RAILS_ASSET_ID"] = ""
0
     ActionController::Base.asset_host = 'http://a%d.example.com'

Comments

markethero-pk Thu Nov 27 23:27:53 -0800 2008

This is awesome

tekin Fri Nov 28 09:44:49 -0800 2008

Nice stuff. Have you had any more thoughts on ActionMailer views lacking a request object causing compute_asset_host to bork?

NZKoz Fri Nov 28 11:32:01 -0800 2008

@tekin: I like your patches on the list, just running about a million years behind there. I’ll get to it :)