comparison .svn/pristine/05/05d8cde4a4e9772f7dcbafb481eff20153ca4409.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
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.
8 #
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.
13 #
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.
17
18 module Redmine
19 module MimeType
20
21 MIME_TYPES = {
22 'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade',
23 'text/css' => 'css',
24 'text/html' => 'html,htm,xhtml',
25 'text/jsp' => 'jsp',
26 'text/x-c' => 'c,cpp,cc,h,hh',
27 'text/x-csharp' => 'cs',
28 'text/x-java' => 'java',
29 'text/x-html-template' => 'rhtml',
30 'text/x-perl' => 'pl,pm',
31 'text/x-php' => 'php,php3,php4,php5',
32 'text/x-python' => 'py',
33 'text/x-ruby' => 'rb,rbw,ruby,rake,erb',
34 'text/x-csh' => 'csh',
35 'text/x-sh' => 'sh',
36 'text/xml' => 'xml,xsd,mxml',
37 'text/yaml' => 'yml,yaml',
38 'text/csv' => 'csv',
39 'text/x-po' => 'po',
40 'image/gif' => 'gif',
41 'image/jpeg' => 'jpg,jpeg,jpe',
42 'image/png' => 'png',
43 'image/tiff' => 'tiff,tif',
44 'image/x-ms-bmp' => 'bmp',
45 'image/x-xpixmap' => 'xpm',
46 'image/svg+xml'=> 'svg',
47 'application/javascript' => 'js',
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
66
67 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
68 exts.split(',').each {|ext| map[ext.strip] = type}
69 map
70 end
71
72 # returns mime type for name or nil if unknown
73 def self.of(name)
74 return nil unless name
75 m = name.to_s.match(/(^|\.)([^\.]+)$/)
76 EXTENSIONS[m[2].downcase] if m
77 end
78
79 # Returns the css class associated to
80 # the mime type of name
81 def self.css_class_of(name)
82 mime = of(name)
83 mime && mime.gsub('/', '-')
84 end
85
86 def self.main_mimetype_of(name)
87 mimetype = of(name)
88 mimetype.split('/').first if mimetype
89 end
90
91 # return true if mime-type for name is type/*
92 # otherwise false
93 def self.is_type?(type, name)
94 main_mimetype = main_mimetype_of(name)
95 type.to_s == main_mimetype
96 end
97 end
98 end