Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6187

Show
Ignore:
Timestamp:
02/21/07 15:28:37 (1 year ago)
Author:
david
Message:

Make sure that the filesystem is not involved with asset hosting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb

    r6164 r6187  
    149149          if !File.exists?(joined_javascript_path) 
    150150            File.open(joined_javascript_path, "w+") do |cache| 
    151               javascript_paths = expand_javascript_sources(sources).collect { |source| javascript_path(source) } 
     151              javascript_paths = expand_javascript_sources(sources).collect do |source| 
     152                compute_public_path(source, 'javascripts', 'js', false)  
     153              end 
     154 
    152155              cache.write(join_asset_file_contents(javascript_paths)) 
    153156            end 
     
    241244          if !File.exists?(joined_stylesheet_path) 
    242245            File.open(joined_stylesheet_path, "w+") do |cache| 
    243               stylesheet_paths = expand_stylesheet_sources(sources).collect { |source| stylesheet_path(source) } 
     246              stylesheet_paths = expand_stylesheet_sources(sources).collect do |source| 
     247                compute_public_path(source, 'stylesheets', 'css', false)  
     248              end 
     249 
    244250              cache.write(join_asset_file_contents(stylesheet_paths)) 
    245251            end 
     
    319325        # a single or wildcarded asset host, if configured, with the correct 
    320326        # request protocol. 
    321         def compute_public_path(source, dir, ext
     327        def compute_public_path(source, dir, ext, include_host = true
    322328          source += ".#{ext}" if File.extname(source).blank? 
    323329 
     
    329335            rewrite_asset_path!(source) 
    330336 
    331             host = compute_asset_host(source) 
    332             unless host.blank? or host =~ %r{^[-a-z]+://} 
    333               host = "#{@controller.request.protocol}#{host}" 
     337            if include_host 
     338              host = compute_asset_host(source) 
     339 
     340              unless host.blank? or host =~ %r{^[-a-z]+://} 
     341                host = "#{@controller.request.protocol}#{host}" 
     342              end 
     343 
     344              "#{host}#{source}" 
     345            else 
     346              source 
    334347            end 
    335  
    336             "#{host}#{source}" 
    337348          end 
    338349        end 
  • trunk/actionpack/test/template/asset_tag_helper_test.rb

    r6164 r6187  
    4343  def teardown 
    4444    ActionController::Base.perform_caching = false 
     45    ActionController::Base.asset_host = nil 
    4546    ENV["RAILS_ASSET_ID"] = nil 
    4647  end 
     
    195196  def test_caching_javascript_include_tag_when_caching_on 
    196197    ENV["RAILS_ASSET_ID"] = "" 
     198    ActionController::Base.asset_host = 'http://a%d.example.com' 
    197199    ActionController::Base.perform_caching = true 
    198200     
    199201    assert_dom_equal( 
    200       %(<script src="/javascripts/all.js" type="text/javascript"></script>), 
     202      %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>), 
    201203      javascript_include_tag(:all, :cache => true) 
    202204    ) 
     
    205207     
    206208    assert_dom_equal( 
    207       %(<script src="/javascripts/money.js" type="text/javascript"></script>), 
     209      %(<script src="http://a2.example.com/javascripts/money.js" type="text/javascript"></script>), 
    208210      javascript_include_tag(:all, :cache => "money") 
    209211    ) 
     
    236238  def test_caching_stylesheet_link_tag_when_caching_on 
    237239    ENV["RAILS_ASSET_ID"] = "" 
     240    ActionController::Base.asset_host = 'http://a%d.example.com' 
    238241    ActionController::Base.perform_caching = true 
    239242     
    240243    assert_dom_equal( 
    241       %(<link href="/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" />), 
     244      %(<link href="http://a3.example.com/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" />), 
    242245      stylesheet_link_tag(:all, :cache => true) 
    243246    ) 
     
    246249 
    247250    assert_dom_equal( 
    248       %(<link href="/stylesheets/money.css" media="screen" rel="Stylesheet" type="text/css" />), 
     251      %(<link href="http://a3.example.com/stylesheets/money.css" media="screen" rel="Stylesheet" type="text/css" />), 
    249252      stylesheet_link_tag(:all, :cache => "money") 
    250253    )