Module: Svn::MimeType

Defined in:
lib/Svn/mime_type.rb

Constant Summary collapse

MIME_TYPES =
{
'text/css' => 'css',
'text/html' => 'html,htm,xhtml',
'text/x-html-template' => 'rhtml',
'text/x-ruby' => 'rb,rbw,ruby,rake,erb',
'text/x-sh' => 'sh',
'text/csv' => 'csv',
'image/gif' => 'gif',
'image/jpeg' => 'jpg,jpeg,jpe',
'image/png' => 'png',
'image/tiff' => 'tiff,tif',
'image/x-ms-bmp' => 'bmp',
'image/x-xpixmap' => 'xpm',
'image/svg+xml'=> 'svg',
'application/javascript' => 'js',
'application/vnd.ms-powerpoint' => 'ppt,pps',
'application/x-tar' => 'tar',
'application/zip' => 'zip',
'application/x-gzip' => 'gz',
}.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

.css_class_of(name) ⇒ Object

Returns the css class associated to the mime type of name



39
40
41
42
# File 'lib/Svn/mime_type.rb', line 39

def self.css_class_of(name)
	mime = of(name)
	mime && mime.gsub('/', '-')
end

.is_type?(type, name) ⇒ Boolean

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

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/Svn/mime_type.rb', line 51

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

.main_mimetype_of(name) ⇒ Object



44
45
46
47
# File 'lib/Svn/mime_type.rb', line 44

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



31
32
33
34
35
# File 'lib/Svn/mime_type.rb', line 31

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