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

Changeset 6162

Show
Ignore:
Timestamp:
02/18/07 07:23:57 (3 years ago)
Author:
bitsweat
Message:

Add request protocol to asset host if not given. Prefer setting asset host as hostname only, no request protocol.

Files:

Legend:

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

    r6161 r6162  
    1111    # linking to them. 
    1212    # 
    13     #   ActionController::Base.asset_host = "http://assets.example.com" 
     13    #   ActionController::Base.asset_host = "assets.example.com" 
    1414    #   image_tag("rails.png") 
    1515    #     => <img src="http://assets.example.com/images/rails.png" alt="Rails" /> 
     
    213213        # Prefix with /dir/ if lacking a leading /. Account for relative URL 
    214214        # roots. Rewrite the asset path for cache-busting asset ids. Include 
    215         # a single or wildcarded asset host if configured. 
     215        # a single or wildcarded asset host, if configured, with the correct 
     216        # request protocol. 
    216217        def compute_public_path(source, dir, ext) 
    217218          source += ".#{ext}" if File.extname(source).blank? 
     
    222223            source = "#{@controller.request.relative_url_root}#{source}" 
    223224            rewrite_asset_path!(source) 
    224             "#{compute_asset_host(source)}#{source}" 
     225 
     226            host = compute_asset_host(source) 
     227            unless host.blank? or host =~ %r{^[-a-z]+://} 
     228              host = "#{@controller.request.protocol}#{host}" 
     229            end 
     230 
     231            "#{host}#{source}" 
    225232          end 
    226233        end 
  • trunk/actionpack/test/template/asset_tag_helper_test.rb

    r6161 r6162  
    190190        "/collaboration/hieraki" 
    191191      end 
     192 
     193      def protocol 
     194        'gopher://' 
     195      end 
    192196    end.new 
    193197     
     
    231235    ActionController::Base.asset_host = nil 
    232236  end 
     237 
     238  def test_asset_host_without_protocol_should_use_request_protocol 
     239    ActionController::Base.asset_host = 'a.example.com' 
     240    assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png') 
     241  ensure 
     242    ActionController::Base.asset_host = nil 
     243  end 
    233244end