Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
release v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Apr 13, 2016
1 parent f8c266c commit ba5bc1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 14 additions & 20 deletions lib/paperclip_utils.rb
Expand Up @@ -3,26 +3,26 @@

module Paperclip
class Utils
def self.get_processors(content_type, options={to_processors: [:thumbnail], fallback_processors: [], allowed_content_types: ALLOWED_CONTENT_TYPES})
if options[:to_processors]
if options[:to_processors].is_a?(Array)
processors = options[:to_processors]
def self.get_processors(content_type, to_processors: [:thumbnail], fallback_processors: [], allowed_content_types: ALLOWED_CONTENT_TYPES)
if to_processors
if to_processors.is_a?(Array)
processors = to_processors

if processors.include?(:thumbnail) && content_type == 'application/pdf' && !processors.include?(:ghostscript)
processors.unshift(:ghostscript)
end
elsif options[:to_processors].is_a?(Symbol)
processors = [options[:to_processors]]
elsif to_processors.is_a?(Symbol)
processors = [to_processors]
else
processors = []
end
end

if options[:fallback_processors] != []
if options[:fallback_processors].is_a?(Array)
fallback_processors = options[:fallback_processors]
elsif options[:fallback_processors].is_a?(Symbol)
fallback_processors = [options[:fallback_processors]]
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
Expand All @@ -31,23 +31,17 @@ def self.get_processors(content_type, options={to_processors: [:thumbnail], fall
return (allowed_content_types.include?(content_type) ? processors : fallback_processors)
end

def self.get_styles(content_type, options={to_styles: nil, fallback_styles: {}, allowed_content_types: ALLOWED_CONTENT_TYPES})
to_styles = options[:to_styles]

def self.get_styles(content_type, to_styles: {preview: "800x600>", thumb: "100x100>"}, fallback_styles: {}, allowed_content_types: ALLOWED_CONTENT_TYPES)
if to_styles
if ['application/pdf','image/tiff','image/tif','image/x-tiff'].include?(content_type)
to_styles.each do |k,v|
to_styles[k] = [(v.is_a?(String) ? v : v[0]), :jpg]
end
end
else
if ['application/pdf','image/tiff','image/tif','image/x-tiff'].include?(content_type)
to_styles = {preview: ["800x600>", :jpg], thumb: ["100x100>", :jpg]}
else
to_styles = {preview: "800x600>", thumb: "100x100>"}
end
to_styles = []
end
return (options[:allowed_content_types].include?(content_type) ? to_styles : options[:fallback_styles])
return (allowed_content_types.include?(content_type) ? to_styles : fallback_styles)
end

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']
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip_utils/version.rb
@@ -1,3 +1,3 @@
module PaperclipUtils
VERSION = '1.2.0'
VERSION = '1.2.1'
end

0 comments on commit ba5bc1e

Please sign in to comment.