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