Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to ruby 2.4 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: ruby
rvm:
- 1.9.3
- 1.9.3
- 2.4.1
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'


group :test, :development do
gem 'rails', '~> 3.2'
gem 'rails', if RUBY_VERSION >= '2.4.0' then '~> 4.2' else '~> 3.2' end
gem 'nokogiri', if RUBY_VERSION >= '2.4.0' then '~> 1.7.0' else '~> 1.6.0' end
gem 'sqlite3'
gem 'pothoven-attachment_fu', :path => '.'
gem 'rmagick'
Expand Down
113 changes: 0 additions & 113 deletions Gemfile.lock

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def destroy_file
# Renames the given file before saving
def rename_file
return unless @old_filename && @old_filename != full_filename
if save_attachment? && File.exists?(@old_filename)
if save_attachment? && File.exist?(@old_filename)
FileUtils.rm @old_filename
elsif File.exists?(@old_filename)
elsif File.exist?(@old_filename)
FileUtils.mv @old_filename, full_filename
end
@old_filename = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
def with_image(file, &block)
block.call OSX::CIImage.from(file)
end
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing
Expand All @@ -30,8 +30,8 @@ def process_attachment_with_processing
def resize_image(img, size)
processor = ::RedArtisan::CoreImage::Processor.new(img)
size = size.first if size.is_a?(Array) && size.length == 1
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
if size.is_a?(Fixnum)
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
if size.is_a?(Integer)
processor.fit(size)
else
processor.resize(size[0], size[1])
Expand All @@ -40,7 +40,7 @@ def resize_image(img, size)
new_size = [img.extent.size.width, img.extent.size.height] / size.to_s
processor.resize(new_size[0], new_size[1])
end

processor.render do |result|
self.width = result.extent.size.width if respond_to?(:width)
self.height = result.extent.size.height if respond_to?(:height)
Expand All @@ -52,12 +52,12 @@ def resize_image(img, size)
quality = get_jpeg_quality
properties = { OSX::NSImageCompressionFactor => quality / 100.0 } if quality
result.save(self.temp_path, OSX::NSJPEGFileType, properties)
#
#
# puts "#{self.temp_path} @ #{quality.inspect} -> #{%x(identify -format '%Q' "#{self.temp_path}")}"
#
#
self.size = File.size(self.temp_path)
end
end
end
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/technoweenie/attachment_fu/processors/gd2_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
# Yields a block containing a GD2 Image for the given binary data.
def with_image(file, &block)
Expand All @@ -31,14 +31,14 @@ def process_attachment_with_processing
# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
if size.is_a?(Fixnum)
# Borrowed from image science's #thumbnail method and adapted
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
if size.is_a?(Integer)
# Borrowed from image science's #thumbnail method and adapted
# for this.
scale = size.to_f / (img.width > img.height ? img.width.to_f : img.height.to_f)
img.resize!((img.width * scale).round(1), (img.height * scale).round(1), false)
else
img.resize!(size.first, size.last, false)
img.resize!(size.first, size.last, false)
end
else
w, h = [img.width, img.height] / size.to_s
Expand All @@ -56,4 +56,4 @@ def resize_image(img, size)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def resize_image(img, size)
end

size = size.first if size.is_a?(Array) && size.length == 1
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
if size.is_a?(Fixnum)
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
if size.is_a?(Integer)
img.thumbnail(size, &grab_dimensions)
else
img.resize(size[0], size[1], &grab_dimensions)
Expand All @@ -77,4 +77,4 @@ def resize_image(img, size)
end
end
end
end
end
24 changes: 12 additions & 12 deletions lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
# Yields a block containing an MiniMagick Image for the given binary data.
def with_image(file, &block)
Expand All @@ -23,7 +23,7 @@ def with_image(file, &block)
!binary_data.nil?
end
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing
Expand All @@ -34,7 +34,7 @@ def process_attachment_with_processing
callback_with_args :after_resize, img
end if image?
end

# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1
Expand All @@ -46,9 +46,9 @@ def resize_image(img, size)
if format == 'GIF'
img.format('PNG')
end
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
if size.is_a?(Fixnum)

if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
if size.is_a?(Integer)
size = [size, size]
commands.resize(size.join('x'))
else
Expand All @@ -64,16 +64,16 @@ def resize_image(img, size)
# crop thumbnail, the smart way
elsif size.is_a?(String) and size =~ /c$/
size = size.gsub(/c/, '')

# calculate sizes and aspect ratio
thumb_width, thumb_height = size.split("x")
thumb_width = thumb_width.to_f
thumb_height = thumb_height.to_f

thumb_aspect = thumb_width.to_f / thumb_height.to_f
image_width, image_height = img[:width].to_f, img[:height].to_f
image_aspect = image_width / image_height

# only crop if image is not smaller in both dimensions
unless image_width < thumb_width and image_height < thumb_height
command = calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
Expand All @@ -83,7 +83,7 @@ def resize_image(img, size)
end

# don not resize if image is not as height or width then thumbnail
if image_width < thumb_width or image_height < thumb_height
if image_width < thumb_width or image_height < thumb_height
commands.background('#ffffff')
commands.gravity('center')
commands.extent(size)
Expand Down Expand Up @@ -120,7 +120,7 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei
command = "#{thumb_width}x#{image_height}+#{offset}+0"

# normal thumbnail generation
# calculate height and offset y, width is fixed
# calculate height and offset y, width is fixed
elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
height = image_width / thumb_aspect
offset = (image_height / 2) - (height / 2)
Expand All @@ -139,4 +139,4 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def process_attachment_with_processing

# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
size = [size, size] if size.is_a?(Fixnum)
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Integer)
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
size = [size, size] if size.is_a?(Integer)
img.thumbnail!(*size)
elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
dimensions = size[1..size.size].split("x")
Expand Down
10 changes: 5 additions & 5 deletions test/backends/file_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_should_store_file_attachment_in_filesystem(klass = FileAttachment)
assert_created do
attachment = upload_file :filename => '/files/rails.png'
assert_valid attachment
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
end
attachment
end
Expand All @@ -55,8 +55,8 @@ def test_should_delete_old_file_when_updating(klass = FileAttachment)
attachment.filename = 'rails2.png'
attachment.temp_paths.unshift File.join(FIXTURE_PATH, file)
attachment.save!
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exist?(old_filename), "#{old_filename} still exists"
end
end
end
Expand All @@ -70,8 +70,8 @@ def test_should_delete_old_file_when_renaming(klass = FileAttachment)
assert_not_created do
attachment.filename = 'rails2.png'
attachment.save
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exist?(old_filename), "#{old_filename} still exists"
assert !attachment.reload.size.zero?
assert_equal 'rails2.png', attachment.filename
end
Expand Down
Loading