##// END OF EJS Templates
Added a few extensions/mimetypes....
Jean-Philippe Lang -
r1114:6d109258c909
parent child
Show More
@@ -1,66 +1,69
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 module MimeType
20 20
21 21 MIME_TYPES = {
22 'text/plain' => 'txt,tpl,properties',
22 'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade',
23 23 'text/css' => 'css',
24 24 'text/html' => 'html,htm,xhtml',
25 25 'text/x-c' => 'c,cpp,h',
26 26 'text/x-java' => 'java',
27 27 'text/x-javascript' => 'js',
28 28 'text/x-html-template' => 'rhtml',
29 29 'text/x-perl' => 'pl,pm',
30 30 'text/x-php' => 'php,php3,php4,php5',
31 31 'text/x-python' => 'py',
32 32 'text/x-ruby' => 'rb,rbw,ruby,rake',
33 'text/x-csh' => 'csh',
33 34 'text/x-sh' => 'sh',
34 'text/xml' => 'xml',
35 'text/xml' => 'xml,xsd,mxml',
35 36 'text/yaml' => 'yml,yaml',
36 37 'image/gif' => 'gif',
37 38 'image/jpeg' => 'jpg,jpeg,jpe',
38 39 'image/png' => 'png',
39 'image/tiff' => 'tiff,tif'
40 'image/tiff' => 'tiff,tif',
41 'image/x-ms-bmp' => 'bmp',
42 'image/x-xpixmap' => 'xpm',
40 43 }.freeze
41 44
42 45 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
43 exts.split(',').each {|ext| map[ext] = type}
46 exts.split(',').each {|ext| map[ext.strip] = type}
44 47 map
45 48 end
46 49
47 50 # returns mime type for name or nil if unknown
48 51 def self.of(name)
49 52 return nil unless name
50 m = name.to_s.match(/\.([^\.]+)$/)
51 EXTENSIONS[m[1]] if m
53 m = name.to_s.match(/(^|\.)([^\.]+)$/)
54 EXTENSIONS[m[2].downcase] if m
52 55 end
53 56
54 57 def self.main_mimetype_of(name)
55 58 mimetype = of(name)
56 59 mimetype.split('/').first if mimetype
57 60 end
58 61
59 62 # return true if mime-type for name is type/*
60 63 # otherwise false
61 64 def self.is_type?(type, name)
62 65 main_mimetype = main_mimetype_of(name)
63 66 type.to_s == main_mimetype
64 67 end
65 68 end
66 69 end
General Comments 0
You need to be logged in to leave comments. Login now