annotate .svn/pristine/0c/0c006adf29e0abdbaa9644cee502d6882d303828.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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