Store mime type lookups in a hash.
git-svn-id: http://svn.redmine.org/redmine/trunk@12484 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e1189c5335
commit
d2f540358f
|
@ -55,13 +55,16 @@ module Redmine
|
||||||
|
|
||||||
# returns mime type for name or nil if unknown
|
# returns mime type for name or nil if unknown
|
||||||
def self.of(name)
|
def self.of(name)
|
||||||
return nil unless name
|
return nil unless name.present?
|
||||||
m = name.to_s.match(/(^|\.)([^\.]+)$/)
|
if m = name.to_s.match(/(^|\.)([^\.]+)$/)
|
||||||
ext = m[2].downcase
|
extension = m[2].downcase
|
||||||
type = nil
|
@known_types ||= Hash.new do |h, ext|
|
||||||
type = EXTENSIONS[ext] if m
|
type = EXTENSIONS[ext]
|
||||||
type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence
|
type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence
|
||||||
type
|
h[ext] = type
|
||||||
|
end
|
||||||
|
@known_types[extension]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the css class associated to
|
# Returns the css class associated to
|
||||||
|
|
Loading…
Reference in New Issue