Module: Redmine::MimeType

Defined in:
lib/redmine/mime_type.rb

Constant Summary

MIME_TYPES =
{
  'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade',
  'text/css' => 'css',
  'text/html' => 'html,htm,xhtml',
  'text/jsp' => 'jsp',
  'text/x-c' => 'c,cpp,cc,h,hh',
  'text/x-java' => 'java',
  'text/x-javascript' => 'js',
  'text/x-html-template' => 'rhtml',
  'text/x-perl' => 'pl,pm',
  'text/x-php' => 'php,php3,php4,php5',
  'text/x-python' => 'py',
  'text/x-ruby' => 'rb,rbw,ruby,rake',
  'text/x-csh' => 'csh',
  'text/x-sh' => 'sh',
  'text/xml' => 'xml,xsd,mxml',
  'text/yaml' => 'yml,yaml',
  'image/gif' => 'gif',
  'image/jpeg' => 'jpg,jpeg,jpe',
  'image/png' => 'png',
  'image/tiff' => 'tiff,tif',
  'image/x-ms-bmp' => 'bmp',
  'image/x-xpixmap' => 'xpm',
}.freeze
EXTENSIONS =
MIME_TYPES.inject({}) do |map, (type, exts)|
  exts.split(',').each {|ext| map[ext.strip] = type}
  map
end

Class Method Summary collapse

Class Method Details

.is_type?(type, name) ⇒ Boolean

return true if mime-type for name is type/* otherwise false

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/redmine/mime_type.rb', line 65

def self.is_type?(type, name)
  main_mimetype = main_mimetype_of(name)
  type.to_s == main_mimetype
end

.main_mimetype_of(name) ⇒ Object



58
59
60
61
# File 'lib/redmine/mime_type.rb', line 58

def self.main_mimetype_of(name)
  mimetype = of(name)
  mimetype.split('/').first if mimetype
end

.of(name) ⇒ Object

returns mime type for name or nil if unknown



52
53
54
55
56
# File 'lib/redmine/mime_type.rb', line 52

def self.of(name)
  return nil unless name
  m = name.to_s.match(/(^|\.)([^\.]+)$/)
  EXTENSIONS[m[2].downcase] if m
end