Sha256: bd88a74b3dbf0653af2ae42c0508bfe7edca0f6c4ec61d56b4b7b40818f7ee7d

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

module Hanko
  module AssetUrlHelper
    URI_REGEXP = %r{^(?:[-a-z]+://|cid:|data:|//)}i

    def asset_path(source, options = {})
      source = source.to_s
      return "" if source.empty?
      return source if URI_REGEXP === source

      if index = source.index(/[?#]/)
        source, tail = source[0, index], source[index..-1]
      end

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

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

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

      if host = compute_asset_host(source, options)
        source = File.join(host, source)
      end

      "#{source}#{tail}"
    end
    alias_method :path_to_asset, :asset_path

    def compute_asset_path(source, options = {})
      fingerprint = options.delete(:fingerprint)

      source = super
      return source unless fingerprint

      asset_id = Hanko::Fingerprint.pon(config.assets_dir, source)
      if asset_id.empty?
        source
      else
        "#{source}?#{asset_id}"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hanko-0.2.2 lib/hanko/asset_url_helper.rb
hanko-0.2.1 lib/hanko/asset_url_helper.rb
hanko-0.2.0 lib/hanko/asset_url_helper.rb
hanko-0.1.6 lib/hanko/asset_url_helper.rb
hanko-0.1.5 lib/hanko/asset_url_helper.rb
hanko-0.1.4 lib/hanko/asset_url_helper.rb
hanko-0.1.3 lib/hanko/asset_url_helper.rb
hanko-0.1.2 lib/hanko/asset_url_helper.rb
hanko-0.1.1 lib/hanko/asset_url_helper.rb