Skip to content

Commit 5c059b4

Browse files
committed
Added methods to check an assets MIME type to avoid post processing
1 parent 16f6cbb commit 5c059b4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
- if asset
2-
= image_tag(asset['style_urls'][config[:thumbnail_style]], height: '50px')
2+
= image_tag(asset_thumb(asset), height: '50px')

app/cells/plugins/core/asset_info_cell.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def config
2020
@options[:config] || {}
2121
end
2222

23+
def asset_thumb(asset)
24+
asset['style_urls'] ? asset['style_urls'][config[:thumbnail_style]] : 'https://secure.gravatar.com/avatar/f995c9cc06a8282138cf6c0691396f6d'
25+
end
26+
2327
def asset
2428
data['asset']
2529
end

app/models/asset_field_type.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AssetFieldType < FieldType
1616
validate :validate_asset_content_type, if: :validate_content_type?
1717

1818
def metadata=(metadata_hash)
19-
@metadata = metadata_hash.deep_symbolize_keys
19+
@metadata = format_data(metadata_hash).deep_symbolize_keys
2020
@existing_data = metadata_hash[:existing_data]
2121
Paperclip::HasAttachedFile.define_on(self.class, :asset, existing_metadata)
2222
end
@@ -52,6 +52,15 @@ def mapping
5252

5353
private
5454

55+
def is_image(mime_type)
56+
["image/jpeg", "image/pjpeg", "image/png","application/pdf" ,"image/x-png", "image/gif"].include?(mime_type)
57+
end
58+
59+
def format_data(metadata_hash)
60+
return metadata_hash if is_image(metadata_hash[:content_type])
61+
metadata_hash.reject{|k| k == "processors"}
62+
end
63+
5564
def image?
5665
asset_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}
5766
end

0 commit comments

Comments
 (0)