Sha256: a69d9d4c2bed3e67ba902798e06797e5c7f73477d4d8c2e082f3a08bd087d9b3

Contents?: true

Size: 1.33 KB

Versions: 55

Compression:

Stored size: 1.33 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

    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

  # Extend Sprockets module to provide global registry
  extend Mime
  @mime_types = {}
end

Version data entries

55 entries across 43 versions & 16 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/mime.rb
sprockets-2.3.3 lib/sprockets/mime.rb
sprockets-2.2.3 lib/sprockets/mime.rb
swipe-rails-0.0.5 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/mime.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/mime.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/mime.rb
challah-1.0.0.beta3 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/mime.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
challah-1.0.0.beta2 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/mime.rb
challah-1.0.0.beta vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/mime.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/mime.rb