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