diff options
| author | Joshua Peek <josh@joshpeek.com> | 2012-08-20 11:29:22 -0500 |
|---|---|---|
| committer | Joshua Peek <josh@joshpeek.com> | 2012-08-20 11:29:22 -0500 |
| commit | 64f350922255b3572b9062200bc6be326b609315 (patch) | |
| tree | 2b7a44d7d5f96ac2601fb09ea13f55f05d34ce3e /lib | |
| parent | f8df871d85057633714002d9650408dbebd7834e (diff) | |
Remove other mime type hacks
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/linguist/mime.rb | 50 | ||||
| -rw-r--r-- | lib/linguist/mimes.yml | 38 |
2 files changed, 2 insertions, 86 deletions
diff --git a/lib/linguist/mime.rb b/lib/linguist/mime.rb index e280209..59f30ad 100644 --- a/lib/linguist/mime.rb +++ b/lib/linguist/mime.rb @@ -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,11 +35,8 @@ 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? } || + # Prefer text mime types over binary + guesses.detect { |type| type.ascii? } || # Otherwise use the first guess guesses.first diff --git a/lib/linguist/mimes.yml b/lib/linguist/mimes.yml deleted file mode 100644 index a410f4b..0000000 --- a/lib/linguist/mimes.yml +++ /dev/null @@ -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 |
