1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade',
24 'text/html' => 'html,htm,xhtml',
26 'text/x-c' => 'c,cpp,cc,h,hh',
27 'text/x-csharp' => 'cs',
28 'text/x-java' => 'java',
29 'text/x-javascript' => 'js',
30 'text/x-html-template' => 'rhtml',
31 'text/x-perl' => 'pl,pm',
32 'text/x-php' => 'php,php3,php4,php5',
33 'text/x-python' => 'py',
34 'text/x-ruby' => 'rb,rbw,ruby,rake,erb',
35 'text/x-csh' => 'csh',
37 'text/xml' => 'xml,xsd,mxml',
38 'text/yaml' => 'yml,yaml',
41 'image/jpeg' => 'jpg,jpeg,jpe',
43 'image/tiff' => 'tiff,tif',
44 'image/x-ms-bmp' => 'bmp',
45 'image/x-xpixmap' => 'xpm',
46 'application/pdf' => 'pdf',
47 'application/rtf' => 'rtf',
48 'application/msword' => 'doc',
49 'application/vnd.ms-excel' => 'xls',
50 'application/vnd.ms-powerpoint' => 'ppt,pps',
51 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
52 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
53 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
54 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
55 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
56 'application/vnd.oasis.opendocument.text' => 'odt',
57 'application/vnd.oasis.opendocument.presentation' => 'odp',
58 'application/x-7z-compressed' => '7z',
59 'application/x-rar-compressed' => 'rar',
60 'application/x-tar' => 'tar',
61 'application/zip' => 'zip',
62 'application/x-gzip' => 'gz',
65 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
66 exts.split(',').each {|ext| map[ext.strip] = type}
70 # returns mime type for name or nil if unknown
72 return nil unless name
73 m = name.to_s.match(/(^|\.)([^\.]+)$/)
74 EXTENSIONS[m[2].downcase] if m
77 # Returns the css class associated to
78 # the mime type of name
79 def self.css_class_of(name)
81 mime && mime.gsub('/', '-')
84 def self.main_mimetype_of(name)
86 mimetype.split('/').first if mimetype
89 # return true if mime-type for name is type/*
91 def self.is_type?(type, name)
92 main_mimetype = main_mimetype_of(name)
93 type.to_s == main_mimetype