annotate .svn/pristine/e7/e735d81a3ddf113ea34dcc2d3e6455904085deeb.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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