Project

General

Profile

Patch #3782 ยป new_mime_types.patch

Support more mime-types - Babar O'Cap, 2009-09-21 17:43

View differences:

lib/redmine/mime_type.rb
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.
......
43 43
      'image/x-ms-bmp' => 'bmp',
44 44
      'image/x-xpixmap' => 'xpm',
45 45
      'application/pdf' => 'pdf',
46
      'application/msword' => 'doc',
47
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
48
      'application/x-msexcel' => 'xls',
49
      'application/vnd.ms-excel' => 'xls',
50
      'application/excel' => 'xls',
51
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
52
      'application/powerpoint' => 'ppt,pps',
53
      'application/vnd.ms-powerpoint' => 'ppt,pps',
54
      'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
55
      'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
56
      'application/rtf' => 'rtf',
57
      'text/csv' => 'csv',
58
      'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
59
      'application/vnd.oasis.opendocument.text' => 'odt',
60
      'application/vnd.oasis.opendocument.presentation' => 'odp',
61
      'application/x-7z-compressed' => '7z',
62
      'application/x-rar-compressed' => 'rar',
63
      'application/x-tar' => 'tar',
46 64
      'application/zip' => 'zip',
47 65
      'application/x-gzip' => 'gz',
48 66
    }.freeze
49
    
67

  
50 68
    EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
51 69
      exts.split(',').each {|ext| map[ext.strip] = type}
52 70
      map
53 71
    end
54
    
72

  
55 73
    # returns mime type for name or nil if unknown
56 74
    def self.of(name)
57 75
      return nil unless name
58 76
      m = name.to_s.match(/(^|\.)([^\.]+)$/)
59 77
      EXTENSIONS[m[2].downcase] if m
60 78
    end
61
    
79

  
62 80
    # Returns the css class associated to
63 81
    # the mime type of name
64 82
    def self.css_class_of(name)
65 83
      mime = of(name)
66 84
      mime && mime.gsub('/', '-')
67 85
    end
68
    
86

  
69 87
    def self.main_mimetype_of(name)
70 88
      mimetype = of(name)
71 89
      mimetype.split('/').first if mimetype
72 90
    end
73
    
91

  
74 92
    # return true if mime-type for name is type/*
75 93
    # otherwise false
76 94
    def self.is_type?(type, name)
77 95
      main_mimetype = main_mimetype_of(name)
78 96
      type.to_s == main_mimetype
79
    end  
97
    end
80 98
  end
81 99
end
    (1-1/1)