mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Use same format as mime type lib
This commit is contained in:
@@ -2,27 +2,42 @@ require 'mime/types'
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
# Register additional mime type extensions
|
# Register additional mime type extensions
|
||||||
mime_extensions = YAML.load_file(File.expand_path("../mimes.yml", __FILE__))
|
File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
|
||||||
mime_extensions.each do |mime_type, options|
|
next unless line =~ %r{^
|
||||||
mime = MIME::Types[mime_type].first || MIME::Type.new(mime_type)
|
#{MIME::Type::MEDIA_TYPE_RE}
|
||||||
|
(?:\s@([^\s]+))?
|
||||||
|
(?:\s:(#{MIME::Type::ENCODING_RE}))?
|
||||||
|
}x
|
||||||
|
|
||||||
(options['extensions'] || []).each { |ext| mime.extensions << ext }
|
mediatype = $1
|
||||||
|
subtype = $2
|
||||||
|
extensions = $3
|
||||||
|
encoding = $4
|
||||||
|
|
||||||
(options['exclude_extensions'] || []).each do |ext|
|
mime_type = MIME::Types["#{mediatype}/#{subtype}"].first ||
|
||||||
mime.extensions.delete(ext)
|
MIME::Type.new("#{mediatype}/#{subtype}")
|
||||||
|
|
||||||
|
if extensions
|
||||||
|
extensions.split(/,/).each do |extension|
|
||||||
|
if extension =~ /^-(\w+)/
|
||||||
|
extension = $1
|
||||||
|
mime_type.extensions.delete(extension)
|
||||||
|
|
||||||
MIME::Types.instance_eval do
|
MIME::Types.instance_eval do
|
||||||
@__types__.instance_eval do
|
@__types__.instance_eval do
|
||||||
@extension_index[ext].delete(mime)
|
@extension_index[extension].delete(mime_type)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
mime_type.extensions << extension
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mime.binary = options['binary'] if options.key?('binary')
|
mime_type.encoding = encoding
|
||||||
mime.encoding = options['encoding'] if options.key?('encoding')
|
|
||||||
|
|
||||||
MIME::Types.add_type_variant(mime)
|
MIME::Types.add_type_variant(mime_type)
|
||||||
MIME::Types.index_extensions(mime)
|
MIME::Types.index_extensions(mime_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
|
|||||||
@@ -1,92 +1,26 @@
|
|||||||
# Additional types to add to MIME::Types
|
# Additional types to add to MIME::Types
|
||||||
|
#
|
||||||
|
# <type> @<extensions> :<encoding>
|
||||||
|
#
|
||||||
|
# Follows same format as mime-types data file
|
||||||
|
# https://github.com/halostatue/mime-types/blob/master/lib/mime/types.rb.data
|
||||||
|
|
||||||
application/x-troff-ms:
|
# TODO: Lookup actual types
|
||||||
encoding: 8bit
|
application/octet-stream @a,blend,gem,graffle,ipa,lib,mcz,nib,o,odp,ods,odt,otf,ogv,pfx,pigx,plgx,pptx,psd,sib,spl,sqlite3,swc,ucode,xpi
|
||||||
|
|
||||||
application/netcdf:
|
application/java-archive @ear,war
|
||||||
encoding: 8bit
|
application/netcdf :8bit
|
||||||
|
application/ogg @ogg
|
||||||
application/x-pagemaker:
|
application/postscript :base64
|
||||||
exclude_extensions:
|
application/vnd.adobe.air-application-installer-package+zip @air
|
||||||
- pm
|
application/vnd.mozilla.xul+xml :8bit
|
||||||
|
application/x-chrome-extension @crx
|
||||||
application/x-wais-source:
|
application/x-ms-xbap @xbap :8bit
|
||||||
encoding: 8bit
|
application/x-pagemaker @-pm
|
||||||
|
application/x-shockwave-flash @swf
|
||||||
application/vnd.mozilla.xul+xml:
|
application/x-silverlight-app @xap
|
||||||
encoding: 8bit
|
application/x-troff-ms :8bit
|
||||||
|
application/x-wais-source :8bit
|
||||||
application/vnd.adobe.air-application-installer-package+zip:
|
application/xaml+xml @xaml :8bit
|
||||||
extensions:
|
image/x-icns @icns
|
||||||
- air
|
text/cache-manifest @manifest
|
||||||
|
|
||||||
application/octet-stream:
|
|
||||||
extensions:
|
|
||||||
# TODO: Lookup actual content type for these extensions
|
|
||||||
- a
|
|
||||||
- blend
|
|
||||||
- gem
|
|
||||||
- graffle
|
|
||||||
- ipa
|
|
||||||
- lib
|
|
||||||
- mcz
|
|
||||||
- nib
|
|
||||||
- o
|
|
||||||
- odp
|
|
||||||
- ods
|
|
||||||
- odt
|
|
||||||
- otf
|
|
||||||
- ogv
|
|
||||||
- pfx
|
|
||||||
- pigx
|
|
||||||
- plgx
|
|
||||||
- pptx
|
|
||||||
- psd
|
|
||||||
- sib
|
|
||||||
- spl
|
|
||||||
- sqlite3
|
|
||||||
- swc
|
|
||||||
- ucode
|
|
||||||
- xpi
|
|
||||||
|
|
||||||
application/postscript:
|
|
||||||
encoding: base64
|
|
||||||
|
|
||||||
application/java-archive:
|
|
||||||
extensions:
|
|
||||||
- ear
|
|
||||||
- war
|
|
||||||
|
|
||||||
application/x-chrome-extension:
|
|
||||||
extensions:
|
|
||||||
- crx
|
|
||||||
|
|
||||||
application/x-shockwave-flash:
|
|
||||||
extensions:
|
|
||||||
- swf
|
|
||||||
|
|
||||||
image/x-icns:
|
|
||||||
extensions:
|
|
||||||
- icns
|
|
||||||
|
|
||||||
text/cache-manifest:
|
|
||||||
extensions:
|
|
||||||
- manifest
|
|
||||||
|
|
||||||
application/ogg:
|
|
||||||
extensions:
|
|
||||||
- ogg
|
|
||||||
|
|
||||||
application/x-silverlight-app:
|
|
||||||
extensions:
|
|
||||||
- xap
|
|
||||||
|
|
||||||
application/xaml+xml:
|
|
||||||
encoding: 8bit
|
|
||||||
extensions:
|
|
||||||
- xaml
|
|
||||||
|
|
||||||
application/x-ms-xbap:
|
|
||||||
encoding: 8bit
|
|
||||||
extensions:
|
|
||||||
- xbap
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ class TestMime < Test::Unit::TestCase
|
|||||||
assert !Mime.binary?("application/xaml+xml")
|
assert !Mime.binary?("application/xaml+xml")
|
||||||
assert !Mime.binary?("application/xhtml+xml")
|
assert !Mime.binary?("application/xhtml+xml")
|
||||||
assert !Mime.binary?("application/xml")
|
assert !Mime.binary?("application/xml")
|
||||||
|
assert !Mime.binary?("text/cache-manifest")
|
||||||
assert !Mime.binary?("text/css")
|
assert !Mime.binary?("text/css")
|
||||||
assert !Mime.binary?("text/csv")
|
assert !Mime.binary?("text/csv")
|
||||||
assert !Mime.binary?("text/html")
|
assert !Mime.binary?("text/html")
|
||||||
|
|||||||
Reference in New Issue
Block a user