@@ -5,6 +5,7 gem "jquery-rails", "~> 2.0.2" | |||||
5 | gem "coderay", "~> 1.1.0" |
|
5 | gem "coderay", "~> 1.1.0" | |
6 | gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] |
|
6 | gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] | |
7 | gem "builder", "3.0.0" |
|
7 | gem "builder", "3.0.0" | |
|
8 | gem "mime-types" | |||
8 |
|
9 | |||
9 | # Optional gem for LDAP authentication |
|
10 | # Optional gem for LDAP authentication | |
10 | group :ldap do |
|
11 | group :ldap do |
@@ -15,6 +15,8 | |||||
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
|
18 | require 'mime/types' | |||
|
19 | ||||
18 | module Redmine |
|
20 | module Redmine | |
19 | module MimeType |
|
21 | module MimeType | |
20 |
|
22 | |||
@@ -42,26 +44,8 module Redmine | |||||
42 | 'image/png' => 'png', |
|
44 | 'image/png' => 'png', | |
43 | 'image/tiff' => 'tiff,tif', |
|
45 | 'image/tiff' => 'tiff,tif', | |
44 | 'image/x-ms-bmp' => 'bmp', |
|
46 | 'image/x-ms-bmp' => 'bmp', | |
45 | 'image/x-xpixmap' => 'xpm', |
|
|||
46 | 'image/svg+xml'=> 'svg', |
|
|||
47 | 'application/javascript' => 'js', |
|
47 | 'application/javascript' => 'js', | |
48 | 'application/pdf' => 'pdf', |
|
48 | 'application/pdf' => 'pdf', | |
49 | 'application/rtf' => 'rtf', |
|
|||
50 | 'application/msword' => 'doc', |
|
|||
51 | 'application/vnd.ms-excel' => 'xls', |
|
|||
52 | 'application/vnd.ms-powerpoint' => 'ppt,pps', |
|
|||
53 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', |
|
|||
54 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', |
|
|||
55 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', |
|
|||
56 | 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx', |
|
|||
57 | 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', |
|
|||
58 | 'application/vnd.oasis.opendocument.text' => 'odt', |
|
|||
59 | 'application/vnd.oasis.opendocument.presentation' => 'odp', |
|
|||
60 | 'application/x-7z-compressed' => '7z', |
|
|||
61 | 'application/x-rar-compressed' => 'rar', |
|
|||
62 | 'application/x-tar' => 'tar', |
|
|||
63 | 'application/zip' => 'zip', |
|
|||
64 | 'application/x-gzip' => 'gz', |
|
|||
65 | }.freeze |
|
49 | }.freeze | |
66 |
|
50 | |||
67 | EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| |
|
51 | EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| | |
@@ -73,7 +57,11 module Redmine | |||||
73 | def self.of(name) |
|
57 | def self.of(name) | |
74 | return nil unless name |
|
58 | return nil unless name | |
75 | m = name.to_s.match(/(^|\.)([^\.]+)$/) |
|
59 | m = name.to_s.match(/(^|\.)([^\.]+)$/) | |
76 |
|
|
60 | ext = m[2].downcase | |
|
61 | type = nil | |||
|
62 | type = EXTENSIONS[ext] if m | |||
|
63 | type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence | |||
|
64 | type | |||
77 | end |
|
65 | end | |
78 |
|
66 | |||
79 | # Returns the css class associated to |
|
67 | # Returns the css class associated to |
@@ -58,4 +58,9 class Redmine::MimeTypeTest < ActiveSupport::TestCase | |||||
58 | assert_equal expected, Redmine::MimeType.is_type?(*args) |
|
58 | assert_equal expected, Redmine::MimeType.is_type?(*args) | |
59 | end |
|
59 | end | |
60 | end |
|
60 | end | |
|
61 | ||||
|
62 | def test_should_default_to_mime_type_gem | |||
|
63 | assert !Redmine::MimeType::EXTENSIONS.keys.include?("zip") | |||
|
64 | assert_equal "application/zip", Redmine::MimeType.of("file.zip") | |||
|
65 | end | |||
61 | end |
|
66 | end |
General Comments 0
You need to be logged in to leave comments.
Login now