comparison 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
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'mime/types'
17 19
18 module Redmine 20 module Redmine
19 module MimeType 21 module MimeType
20 22
21 MIME_TYPES = { 23 MIME_TYPES = {
40 'image/gif' => 'gif', 42 'image/gif' => 'gif',
41 'image/jpeg' => 'jpg,jpeg,jpe', 43 'image/jpeg' => 'jpg,jpeg,jpe',
42 'image/png' => 'png', 44 'image/png' => 'png',
43 'image/tiff' => 'tiff,tif', 45 'image/tiff' => 'tiff,tif',
44 'image/x-ms-bmp' => 'bmp', 46 'image/x-ms-bmp' => 'bmp',
45 'image/x-xpixmap' => 'xpm',
46 'image/svg+xml'=> 'svg',
47 'application/javascript' => 'js', 47 'application/javascript' => 'js',
48 'application/pdf' => 'pdf', 48 'application/pdf' => 'pdf',
49 'application/rtf' => 'rtf',
50 'application/msword' => 'doc',
51 'application/vnd.ms-excel' => 'xls',
52 'application/vnd.ms-powerpoint' => 'ppt,pps',
53 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
54 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
55 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
56 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
57 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
58 'application/vnd.oasis.opendocument.text' => 'odt',
59 'application/vnd.oasis.opendocument.presentation' => 'odp',
60 'application/x-7z-compressed' => '7z',
61 'application/x-rar-compressed' => 'rar',
62 'application/x-tar' => 'tar',
63 'application/zip' => 'zip',
64 'application/x-gzip' => 'gz',
65 }.freeze 49 }.freeze
66 50
67 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| 51 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
68 exts.split(',').each {|ext| map[ext.strip] = type} 52 exts.split(',').each {|ext| map[ext.strip] = type}
69 map 53 map
70 end 54 end
71 55
72 # returns mime type for name or nil if unknown 56 # returns mime type for name or nil if unknown
73 def self.of(name) 57 def self.of(name)
74 return nil unless name 58 return nil unless name.present?
75 m = name.to_s.match(/(^|\.)([^\.]+)$/) 59 if m = name.to_s.match(/(^|\.)([^\.]+)$/)
76 EXTENSIONS[m[2].downcase] if m 60 extension = m[2].downcase
61 @known_types ||= Hash.new do |h, ext|
62 type = EXTENSIONS[ext]
63 type ||= MIME::Types.type_for(ext).first.to_s.presence
64 h[ext] = type
65 end
66 @known_types[extension]
67 end
77 end 68 end
78 69
79 # Returns the css class associated to 70 # Returns the css class associated to
80 # the mime type of name 71 # the mime type of name
81 def self.css_class_of(name) 72 def self.css_class_of(name)