@@ -19,7 +19,7 module Redmine | |||||
19 | module MimeType |
|
19 | module MimeType | |
20 |
|
20 | |||
21 | MIME_TYPES = { |
|
21 | MIME_TYPES = { | |
22 | 'text/plain' => 'txt,tpl,properties', |
|
22 | 'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade', | |
23 | 'text/css' => 'css', |
|
23 | 'text/css' => 'css', | |
24 | 'text/html' => 'html,htm,xhtml', |
|
24 | 'text/html' => 'html,htm,xhtml', | |
25 | 'text/x-c' => 'c,cpp,h', |
|
25 | 'text/x-c' => 'c,cpp,h', | |
@@ -30,25 +30,28 module Redmine | |||||
30 | 'text/x-php' => 'php,php3,php4,php5', |
|
30 | 'text/x-php' => 'php,php3,php4,php5', | |
31 | 'text/x-python' => 'py', |
|
31 | 'text/x-python' => 'py', | |
32 | 'text/x-ruby' => 'rb,rbw,ruby,rake', |
|
32 | 'text/x-ruby' => 'rb,rbw,ruby,rake', | |
|
33 | 'text/x-csh' => 'csh', | |||
33 | 'text/x-sh' => 'sh', |
|
34 | 'text/x-sh' => 'sh', | |
34 | 'text/xml' => 'xml', |
|
35 | 'text/xml' => 'xml,xsd,mxml', | |
35 | 'text/yaml' => 'yml,yaml', |
|
36 | 'text/yaml' => 'yml,yaml', | |
36 | 'image/gif' => 'gif', |
|
37 | 'image/gif' => 'gif', | |
37 | 'image/jpeg' => 'jpg,jpeg,jpe', |
|
38 | 'image/jpeg' => 'jpg,jpeg,jpe', | |
38 | 'image/png' => 'png', |
|
39 | 'image/png' => 'png', | |
39 | 'image/tiff' => 'tiff,tif' |
|
40 | 'image/tiff' => 'tiff,tif', | |
|
41 | 'image/x-ms-bmp' => 'bmp', | |||
|
42 | 'image/x-xpixmap' => 'xpm', | |||
40 | }.freeze |
|
43 | }.freeze | |
41 |
|
44 | |||
42 | EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| |
|
45 | EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| | |
43 | exts.split(',').each {|ext| map[ext] = type} |
|
46 | exts.split(',').each {|ext| map[ext.strip] = type} | |
44 | map |
|
47 | map | |
45 | end |
|
48 | end | |
46 |
|
49 | |||
47 | # returns mime type for name or nil if unknown |
|
50 | # returns mime type for name or nil if unknown | |
48 | def self.of(name) |
|
51 | def self.of(name) | |
49 | return nil unless name |
|
52 | return nil unless name | |
50 | m = name.to_s.match(/\.([^\.]+)$/) |
|
53 | m = name.to_s.match(/(^|\.)([^\.]+)$/) | |
51 |
EXTENSIONS[m[ |
|
54 | EXTENSIONS[m[2].downcase] if m | |
52 | end |
|
55 | end | |
53 |
|
56 | |||
54 | def self.main_mimetype_of(name) |
|
57 | def self.main_mimetype_of(name) |
General Comments 0
You need to be logged in to leave comments.
Login now