module Sprockets::Rails::LegacyAssetUrlHelper - sprockets-rails-2.1.3 Documentation

# module Sprockets::Rails::LegacyAssetUrlHelper

Backports of AssetUrlHelper methods for Rails 2.x and 3.x.

### Constants

ASSET_EXTENSIONS
ASSET_PUBLIC_DIRECTORIES
URI_REGEXP

### Public Instance Methods

asset_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 9
    def asset_path(source, options = {})
      source = source.to_s
      return "" unless source.present?
      return source if source =~ URI_REGEXP

      tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')

      if extname = compute_asset_extname(source, options)
        source = "#{source}#{extname}"
      end

      if source[0] != ?/
        source = compute_asset_path(source, options)
      end

      relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
      if relative_url_root
        source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
      end

      if host = compute_asset_host(source, options)
        source = "#{host}#{source}"
      end

      "#{source}#{tail}"
    end

Also aliased as: path_to_asset
audio_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 118
    def audio_path(source, options = {})
      path_to_asset(source, {:type => :audio}.merge(options))
    end

Also aliased as: path_to_audio
compute_asset_extname(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 42
    def compute_asset_extname(source, options = {})
      return if options[:extname] == false
      extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
      extname if extname && File.extname(source) != extname
    end

compute_asset_host(source = "", options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 62
    def compute_asset_host(source = "", options = {})
      request = self.request if respond_to?(:request)

      if defined? config
        host = config.asset_host
      elsif defined? ActionController::Base.asset_host
        host = ActionController::Base.asset_host
      end

      host ||= request.base_url if request && options[:protocol] == :request
      return unless host

      if host.respond_to?(:call)
        arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
        args = [source]
        args << request if request && (arity > 1 || arity < 0)
        host = host.call(*args)
      elsif host =~ /%d/
        host = host % (Zlib.crc32(source) % 4)
      end

      if host =~ URI_REGEXP
        host
      else
        protocol = options[:protocol] || (request ? :request : :relative)
        case protocol
        when :relative
          "//#{host}"
        when :request
          "#{request.protocol}#{host}"
        else
          "#{protocol}://#{host}"
        end
      end
    end

compute_asset_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 57
    def compute_asset_path(source, options = {})
      dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
      File.join(dir, source)
    end

font_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 123
    def font_path(source, options = {})
      path_to_asset(source, {:type => :font}.merge(options))
    end

Also aliased as: path_to_font
image_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 108
    def image_path(source, options = {})
      path_to_asset(source, {:type => :image}.merge(options))
    end

Also aliased as: path_to_image
javascript_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 98
    def javascript_path(source, options = {})
      path_to_asset(source, {:type => :javascript}.merge(options))
    end

Also aliased as: path_to_javascript
path_to_asset(source, options = {})
Alias for: asset_path
path_to_audio(source, options = {})
Alias for: audio_path
path_to_font(source, options = {})
Alias for: font_path
path_to_image(source, options = {})
Alias for: image_path
path_to_javascript(source, options = {})
Alias for: javascript_path
path_to_stylesheet(source, options = {})
Alias for: stylesheet_path
path_to_video(source, options = {})
Alias for: video_path
stylesheet_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 103
    def stylesheet_path(source, options = {})
      path_to_asset(source, {:type => :stylesheet}.merge(options))
    end

Also aliased as: path_to_stylesheet
video_path(source, options = {}) click to toggle source

    # File lib/sprockets/rails/legacy_asset_url_helper.rb, line 113
    def video_path(source, options = {})
      path_to_asset(source, {:type => :video}.merge(options))
    end

Also aliased as: path_to_video