Mercurial > hg > soundsoftware-site
diff lib/redmine/mime_type.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children |
line wrap: on
line diff
--- a/lib/redmine/mime_type.rb Tue Sep 09 09:28:31 2014 +0100 +++ b/lib/redmine/mime_type.rb Tue Sep 09 09:29:00 2014 +0100 @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require 'mime/types' + module Redmine module MimeType @@ -42,26 +44,8 @@ 'image/png' => 'png', 'image/tiff' => 'tiff,tif', 'image/x-ms-bmp' => 'bmp', - 'image/x-xpixmap' => 'xpm', - 'image/svg+xml'=> 'svg', 'application/javascript' => 'js', 'application/pdf' => 'pdf', - 'application/rtf' => 'rtf', - 'application/msword' => 'doc', - 'application/vnd.ms-excel' => 'xls', - 'application/vnd.ms-powerpoint' => 'ppt,pps', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx', - 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', - 'application/vnd.oasis.opendocument.text' => 'odt', - 'application/vnd.oasis.opendocument.presentation' => 'odp', - 'application/x-7z-compressed' => '7z', - 'application/x-rar-compressed' => 'rar', - 'application/x-tar' => 'tar', - 'application/zip' => 'zip', - 'application/x-gzip' => 'gz', }.freeze EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| @@ -71,9 +55,16 @@ # returns mime type for name or nil if unknown def self.of(name) - return nil unless name - m = name.to_s.match(/(^|\.)([^\.]+)$/) - EXTENSIONS[m[2].downcase] if m + return nil unless name.present? + if m = name.to_s.match(/(^|\.)([^\.]+)$/) + extension = m[2].downcase + @known_types ||= Hash.new do |h, ext| + type = EXTENSIONS[ext] + type ||= MIME::Types.type_for(ext).first.to_s.presence + h[ext] = type + end + @known_types[extension] + end end # Returns the css class associated to