annotate .svn/pristine/1c/1c28b35075b5e9d9a0869f79fc45dbaf27ac97ad.svn-base @ 1628:9c5f8e24dadc live tip

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