public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed asset host to not cache objects [#1419 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
aaronbatalion (author)
Wed Nov 19 15:27:08 -0800 2008
josh (committer)
Wed Nov 19 15:29:09 -0800 2008
commit  d7f4921a9a852da7c1075275eaf73822edb7acff
tree    cc34af3830e5ff89ee57030777e8ff43c99168f6
parent  dbbaccbcda7475766919723dda53c0f92afddc4b
...
151
152
153
154
 
155
156
157
...
314
315
316
317
 
318
319
320
...
411
412
413
414
 
415
416
417
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
...
551
552
553
 
 
 
 
 
 
 
 
554
555
 
556
557
558
...
585
586
587
588
589
590
591
592
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
594
595
596
597
 
598
599
 
600
601
 
 
 
 
 
602
603
604
...
735
736
737
738
 
739
740
741
...
151
152
153
 
154
155
156
157
...
314
315
316
 
317
318
319
320
...
411
412
413
 
414
415
416
417
...
527
528
529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
531
532
...
537
538
539
540
541
542
543
544
545
546
547
548
 
549
550
551
552
...
579
580
581
 
 
 
 
 
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
 
 
598
 
599
600
 
601
602
 
603
604
605
606
607
608
609
610
...
741
742
743
 
744
745
746
747
0
@@ -151,7 +151,7 @@ module ActionView
0
       #   javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr.js
0
       #   javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js
0
       def javascript_path(source)
0
-        JavaScriptTag.create(self, @controller, source).public_path
0
+        JavaScriptTag.new(self, @controller, source).public_path
0
       end
0
       alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
0
 
0
@@ -314,7 +314,7 @@ module ActionView
0
       #   stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style.css
0
       #   stylesheet_path "http://www.railsapplication.com/css/style.js" # => http://www.railsapplication.com/css/style.css
0
       def stylesheet_path(source)
0
-        StylesheetTag.create(self, @controller, source).public_path
0
+        StylesheetTag.new(self, @controller, source).public_path
0
       end
0
       alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
0
 
0
@@ -411,7 +411,7 @@ module ActionView
0
       #   image_path("/icons/edit.png")                              # => /icons/edit.png
0
       #   image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png
0
       def image_path(source)
0
-        ImageTag.create(self, @controller, source).public_path
0
+        ImageTag.new(self, @controller, source).public_path
0
       end
0
       alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
0
 
0
@@ -527,20 +527,6 @@ module ActionView
0
           Cache = {}
0
           CacheGuard = Mutex.new
0
 
0
-          def self.create(template, controller, source, include_host = true)
0
-            CacheGuard.synchronize do
0
-              key = if controller.respond_to?(:request)
0
-                [self, controller.request.protocol,
0
-                 ActionController::Base.asset_host,
0
-                 ActionController::Base.relative_url_root,
0
-                 source, include_host]
0
-              else
0
-                [self, ActionController::Base.asset_host, source, include_host]
0
-              end
0
-              Cache[key] ||= new(template, controller, source, include_host).freeze
0
-            end
0
-          end
0
-
0
           ProtocolRegexp = %r{^[-a-z]+://}.freeze
0
 
0
           def initialize(template, controller, source, include_host = true)
0
@@ -551,8 +537,16 @@ module ActionView
0
             @controller = controller
0
             @source = source
0
             @include_host = include_host
0
+            @cache_key = if controller.respond_to?(:request)
0
+              [controller.request.protocol,
0
+               ActionController::Base.asset_host,
0
+               ActionController::Base.relative_url_root,
0
+               source, include_host]
0
+            else
0
+              [ActionController::Base.asset_host, source, include_host]
0
+            end
0
           end
0
-
0
+          
0
           def public_path
0
             compute_public_path(@source)
0
           end
0
@@ -585,20 +579,32 @@ module ActionView
0
             # roots. Rewrite the asset path for cache-busting asset ids. Include
0
             # asset host, if configured, with the correct request protocol.
0
             def compute_public_path(source)
0
-              source += ".#{extension}" if missing_extension?(source)
0
-              unless source =~ ProtocolRegexp
0
-                source = "/#{directory}/#{source}" unless source[0] == ?/
0
-                source = rewrite_asset_path(source)
0
-                source = prepend_relative_url_root(source)                
0
+              if source =~ ProtocolRegexp
0
+                source += ".#{extension}" if missing_extension?(source)
0
+                source = prepend_asset_host(source)
0
+                source
0
+              else
0
+                CacheGuard.synchronize do
0
+                  Cache[@cache_key] ||= begin
0
+                    source += ".#{extension}" if missing_extension?(source) || file_exists_with_extension?(source)
0
+                    source = "/#{directory}/#{source}" unless source[0] == ?/
0
+                    source = rewrite_asset_path(source)
0
+                    source = prepend_relative_url_root(source)                
0
+                    source = prepend_asset_host(source)
0
+                    source
0
+                  end
0
+                end
0
               end
0
-              source = prepend_asset_host(source)
0
-              source
0
             end
0
-
0
+            
0
             def missing_extension?(source)
0
-              extension && (File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, directory, "#{source}.#{extension}")))
0
+              extension && File.extname(source).blank?
0
             end
0
-
0
+            
0
+            def file_exists_with_extension?(source)
0
+              extension && File.exist?(File.join(ASSETS_DIR, directory, "#{source}.#{extension}"))
0
+            end
0
+            
0
             def prepend_relative_url_root(source)
0
               relative_url_root = ActionController::Base.relative_url_root
0
               if request? && @include_host && source !~ %r{^#{relative_url_root}/}
0
@@ -735,7 +741,7 @@ module ActionView
0
             end
0
 
0
             def tag_sources
0
-              expand_sources.collect { |source| tag_class.create(@template, @controller, source, false) }
0
+              expand_sources.collect { |source| tag_class.new(@template, @controller, source, false) }
0
             end
0
 
0
             def joined_contents

Comments