-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
dragonfly.rb
42 lines (36 loc) · 1.22 KB
/
dragonfly.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rails_admin/config/fields/base'
require 'rails_admin/config/fields/types/file_upload'
module RailsAdmin
module Config
module Fields
module Types
# Field type that supports Paperclip file uploads
class Dragonfly < RailsAdmin::Config::Fields::Types::FileUpload
RailsAdmin::Config::Fields::Types.register(self)
register_instance_option :image? do
false unless value
if abstract_model.model.new.respond_to?("#{name}_name")
mime_type = Mime::Type.lookup_by_extension(bindings[:object].send("#{name}_name").to_s.split('.').last)
mime_type.to_s.match?(/^image/)
else
true # Dragonfly really is image oriented
end
end
register_instance_option :delete_method do
"remove_#{name}"
end
register_instance_option :cache_method do
"retained_#{name}"
end
register_instance_option :thumb_method do
'100x100>'
end
def resource_url(thumb = false)
return nil unless (v = value)
thumb ? v.thumb(thumb).try(:url) : v.url
end
end
end
end
end
end