Sha256: 6ce126a1c2c9eb768ffc15f06041fe06a90af6afa471c69d270d5c5d84852bdd

Contents?: true

Size: 1.37 KB

Versions: 36

Compression:

Stored size: 1.37 KB

Contents

require 'rack/mime'

module Sprockets
  module Mime
    # Returns a `Hash` of registered mime types registered on the
    # environment and those part of `Rack::Mime`.
    #
    # If an `ext` is given, it will lookup the mime type for that extension.
    def mime_types(ext = nil)
      if ext.nil?
        Rack::Mime::MIME_TYPES.merge(@mime_types)
      else
        ext = Sprockets::Utils.normalize_extension(ext)
        @mime_types[ext] || Rack::Mime::MIME_TYPES[ext]
      end
    end

    # Returns a `Hash` of explicitly registered mime types.
    def registered_mime_types
      @mime_types.dup
    end

    if {}.respond_to?(:key)
      def extension_for_mime_type(type)
        mime_types.key(type)
      end
    else
      def extension_for_mime_type(type)
        mime_types.index(type)
      end
    end

    # Register a new mime type.
    def register_mime_type(mime_type, ext)
      ext = Sprockets::Utils.normalize_extension(ext)
      @mime_types[ext] = mime_type
    end

    if defined? Encoding
      # Returns the correct encoding for a given mime type, while falling
      # back on the default external encoding, if it exists.
      def encoding_for_mime_type(type)
        encoding = Encoding::BINARY if type =~ %r{^(image|audio|video)/}
        encoding ||= default_external_encoding if respond_to?(:default_external_encoding)
        encoding
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 5 rubygems

Version Path
sprockets-2.12.5 lib/sprockets/mime.rb
arcabouco-0.2.13 vendor/bundle/gems/sprockets-2.12.4/lib/sprockets/mime.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-2.12.4/lib/sprockets/mime.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/mime.rb
sprockets-2.12.4 lib/sprockets/mime.rb
sprockets-2.12.3 lib/sprockets/mime.rb
sprockets-2.11.3 lib/sprockets/mime.rb
sprockets-2.10.2 lib/sprockets/mime.rb
sprockets-2.9.4 lib/sprockets/mime.rb
sprockets-2.8.3 lib/sprockets/mime.rb
sprockets-2.7.1 lib/sprockets/mime.rb
sprockets-2.6.1 lib/sprockets/mime.rb
sprockets-2.5.1 lib/sprockets/mime.rb
sprockets-2.4.6 lib/sprockets/mime.rb
sprockets-2.12.2 lib/sprockets/mime.rb
sprockets-2.12.1 lib/sprockets/mime.rb
sprockets-2.12.0 lib/sprockets/mime.rb
sprockets-2.11.0 lib/sprockets/mime.rb
sprockets-2.10.1 lib/sprockets/mime.rb
challah-1.0.0 vendor/bundle/gems/sprockets-2.10.0/lib/sprockets/mime.rb