Class: Paperclip::Utils
- Inherits:
-
Object
- Object
- Paperclip::Utils
- Defined in:
- lib/paperclip_utils.rb
Constant Summary collapse
- ALLOWED_CONTENT_TYPES =
['application/pdf', 'image/png', 'image/x-png', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/tif', 'image/tiff', 'image/x-tiff']
Class Method Summary collapse
- .get_processors(content_type, processors: [:thumbnail], fallback_processors: [], allowed_content_types: ALLOWED_CONTENT_TYPES) ⇒ Object
- .get_styles(content_type, styles: {preview: "600x800>", thumb: "100x100>"}, fallback_styles: {}, allowed_content_types: ALLOWED_CONTENT_TYPES) ⇒ Object
Class Method Details
.get_processors(content_type, processors: [:thumbnail], fallback_processors: [], allowed_content_types: ALLOWED_CONTENT_TYPES) ⇒ Object
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 |
# File 'lib/paperclip_utils.rb', line 6 def self.get_processors(content_type, processors: [:thumbnail], fallback_processors: [], allowed_content_types: ALLOWED_CONTENT_TYPES) if processors != [] if processors.is_a?(Array) if processors.include?(:thumbnail) && content_type == 'application/pdf' && !processors.include?(:ghostscript) processors.unshift(:ghostscript) end elsif processors.is_a?(Symbol) processors = [processors] else processors = [] end end if fallback_processors != [] if fallback_processors.is_a?(Array) fallback_processors = fallback_processors elsif fallback_processors.is_a?(Symbol) fallback_processors = [fallback_processors] else fallback_processors = [] end end return (allowed_content_types.include?(content_type) ? processors : fallback_processors) end |
.get_styles(content_type, styles: {preview: "600x800>", thumb: "100x100>"}, fallback_styles: {}, allowed_content_types: ALLOWED_CONTENT_TYPES) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/paperclip_utils.rb', line 32 def self.get_styles(content_type, styles: {preview: "600x800>", thumb: "100x100>"}, fallback_styles: {}, allowed_content_types: ALLOWED_CONTENT_TYPES) if styles.is_a?(Hash) if ['application/pdf','image/tiff','image/tif','image/x-tiff'].include?(content_type) styles.each do |k,v| if v.is_a?(String) styles[k] = [v, :jpg] end end end else styles = {} end return (allowed_content_types.include?(content_type) ? styles : fallback_styles) end |