Remove other mime type hacks

This commit is contained in:
Joshua Peek
2012-08-20 11:29:22 -05:00
parent f8df871d85
commit 64f3509222
4 changed files with 2 additions and 100 deletions

View File

@@ -1,49 +1,6 @@
require 'mime/types'
require 'yaml'
class MIME::Type
attr_accessor :override
end
# Register additional mime type extensions
#
# Follows same format as mime-types data file
# https://github.com/halostatue/mime-types/blob/master/lib/mime/types.rb.data
File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
# Regexp was cargo culted from mime-types lib
next unless line =~ %r{^
#{MIME::Type::MEDIA_TYPE_RE}
(?:\s@([^\s]+))?
(?:\s:(#{MIME::Type::ENCODING_RE}))?
}x
mediatype = $1
subtype = $2
extensions = $3
encoding = $4
# Lookup existing mime type
mime_type = MIME::Types["#{mediatype}/#{subtype}"].first ||
# Or create a new instance
MIME::Type.new("#{mediatype}/#{subtype}")
if extensions
extensions.split(/,/).each do |extension|
mime_type.extensions << extension
end
end
if encoding
mime_type.encoding = encoding
end
mime_type.override = true
# Kind of hacky, but we need to reindex the mime type after making changes
MIME::Types.add_type_variant(mime_type)
MIME::Types.index_extensions(mime_type)
end
module Linguist
module Mime
# Internal: Look up mime type for extension.
@@ -78,9 +35,6 @@ module Linguist
guesses = ::MIME::Types.type_for(ext_or_mime_type)
end
# Use custom override first
guesses.detect { |type| type.override } ||
# Prefer text mime types over binary
guesses.detect { |type| type.ascii? } ||

View File

@@ -1,38 +0,0 @@
# Additional types to add to MIME::Types
#
# MIME types are used to set the Content-Type of raw binary blobs. All text
# blobs are served as text/plain regardless of their type to ensure they
# open in the browser rather than downloading.
#
# The encoding helps determine whether a file should be treated as plain
# text or binary. By default, a mime type's encoding is base64 (binary).
# These types will show a "View Raw" link. To force a type to render as
# plain text, set it to 8bit for UTF-8. text/* types will be treated as
# text by default.
#
# <type> @<extensions> :<encoding>
#
# type - mediatype/subtype
# extensions - comma seperated extension list
# encoding - base64 (binary), 7bit (ASCII), 8bit (UTF-8), or
# quoted-printable (Printable ASCII).
#
# Follows same format as mime-types data file
# https://github.com/halostatue/mime-types/blob/master/lib/mime/types.rb.data
#
# Any additions or modifications (even trivial) should have corresponding
# test change in `test/test_mime.rb`.
# Please keep this list alphabetized
application/java-archive @ear,war
application/octet-stream @o
application/x-chrome-extension @crx
application/x-supercollider @sc :8bit
application/xslt+xml @xslt :8bit
image/x-icns @icns
text/cache-manifest @manifest
text/plain @cu,cxx
text/x-logtalk @lgt
text/x-nimrod @nim
text/x-ocaml @ml,mli,mll,mly,sig,sml
text/x-scheme @rkt,scm,sls,sps,ss

View File

@@ -30,7 +30,6 @@ class TestBlob < Test::Unit::TestCase
end
def test_mime_type
assert_equal "application/octet-stream", blob("Binary/dog.o").mime_type
assert_equal "application/postscript", blob("Binary/octocat.ai").mime_type
assert_equal "application/x-ruby", blob("Ruby/grit.rb").mime_type
assert_equal "application/x-sh", blob("Shell/script.sh").mime_type
@@ -40,7 +39,6 @@ class TestBlob < Test::Unit::TestCase
end
def test_content_type
assert_equal "application/octet-stream", blob("Binary/dog.o").content_type
assert_equal "application/pdf", blob("Binary/foo.pdf").content_type
assert_equal "audio/ogg", blob("Binary/foo.ogg").content_type
assert_equal "image/png", blob("Binary/foo.png").content_type

View File

@@ -26,11 +26,7 @@ class TestMime < Test::Unit::TestCase
assert_equal 'application/vnd.oasis.opendocument.spreadsheet', Mime.mime_for('.ods')
assert_equal 'application/vnd.oasis.opendocument.text', Mime.mime_for('.odt')
assert_equal 'application/vnd.openxmlformats-officedocument.presentationml.presentation', Mime.mime_for('.pptx')
assert_equal 'application/x-chrome-extension', Mime.mime_for('.crx')
assert_equal 'application/x-debian-package', Mime.mime_for('.deb')
assert_equal 'application/x-java-archive', Mime.mime_for('.ear')
assert_equal 'application/x-java-archive', Mime.mime_for('.jar')
assert_equal 'application/x-java-archive', Mime.mime_for('.war')
assert_equal 'application/x-latex', Mime.mime_for('.latex')
assert_equal 'application/x-perl', Mime.mime_for('.pl')
assert_equal 'application/x-perl', Mime.mime_for('.pm')
@@ -38,23 +34,15 @@ class TestMime < Test::Unit::TestCase
assert_equal 'application/x-ruby', Mime.mime_for('.rb')
assert_equal 'application/x-sh', Mime.mime_for('.sh')
assert_equal 'application/x-shockwave-flash', Mime.mime_for('.swf')
assert_equal 'application/x-supercollider', Mime.mime_for('.sc')
assert_equal 'text/cache-manifest', Mime.mime_for('.manifest')
assert_equal 'text/html', Mime.mime_for('.html')
assert_equal 'text/plain', Mime.mime_for('.c')
assert_equal 'text/plain', Mime.mime_for('.cc')
assert_equal 'text/plain', Mime.mime_for('.cpp')
assert_equal 'text/plain', Mime.mime_for('.cu')
assert_equal 'text/plain', Mime.mime_for('.cxx')
assert_equal 'text/plain', Mime.mime_for('.h')
assert_equal 'text/plain', Mime.mime_for('.hh')
assert_equal 'text/plain', Mime.mime_for('.hpp')
assert_equal 'text/plain', Mime.mime_for('.kt')
assert_equal 'text/x-logtalk', Mime.mime_for('.lgt')
assert_equal 'text/x-nimrod', Mime.mime_for('.nim')
assert_equal 'text/x-ocaml', Mime.mime_for('.ml')
assert_equal 'text/x-ocaml', Mime.mime_for('.sig')
assert_equal 'text/x-ocaml', Mime.mime_for('.sml')
assert_equal 'video/quicktime', Mime.mime_for('.mov')
end
end