forked from samuelgiles/papercrop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d53d606
commit 4434dfb
Showing
71 changed files
with
1,080 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
.rvmrc | ||
.sass-cache | ||
*.gem | ||
*.swp | ||
**/*.swp | ||
Gemfile.lock | ||
test_app/.bundle | ||
test_app/Gemfile.lock | ||
test_app/db/*.sqlite3 | ||
test_app/log/*.log | ||
test_app/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'http://rubygems.org' | ||
|
||
gemspec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rspec/core' | ||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'papercrop' | ||
s.version = '0.0.2' | ||
s.version = '0.0.5' | ||
s.date = '2012-08-12' | ||
s.summary = "Paperclip extension for cropping images" | ||
s.description = "Paperclip extension for cropping images" | ||
s.description = "An easy extension for Paperclip to crop your image uploads using jCrop" | ||
s.authors = ["Ruben Santamaria"] | ||
s.email = '[email protected]' | ||
s.homepage = 'https://github.com/rsantamaria/papercrop' | ||
|
||
s.files = Dir.glob("{lib,vendor}/**/*") + %w(README.md) | ||
s.test_files = Dir.glob("{spec}/**/*") | ||
s.require_paths = ["lib"] | ||
|
||
s.add_dependency "rails", "~> 3.1" | ||
s.add_dependency "rails", ">= 3.1" | ||
s.add_dependency "jquery-rails" | ||
s.add_dependency "paperclip", "~> 3.1" | ||
s.add_dependency "paperclip", ">= 3.1" | ||
|
||
s.add_development_dependency "rspec-rails", "~> 2.0" | ||
s.add_development_dependency "capybara", ">= 1.1.1" | ||
s.add_development_dependency "rmagick" | ||
s.add_development_dependency "sass" | ||
s.add_development_dependency "sqlite3" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "spec_helper" | ||
|
||
describe "Image crop with JS", :js => true do | ||
|
||
after do | ||
Landscape.destroy_all | ||
end | ||
|
||
|
||
it "crops an image with javascript" do | ||
visit landscapes_path | ||
|
||
click_link "New Landscape" | ||
|
||
fill_in "Name", :with => "Mountains" | ||
find("#landscape_picture").native.send_keys(File.expand_path("../../../test_app/test/fixtures/matterhorn.jpg", __FILE__)) | ||
click_button "Create Landscape" | ||
|
||
sleep 2 | ||
page.execute_script("jcrop_api.setSelect([300, 200, 700, 500])") | ||
page.execute_script('if ($("#picture_crop_y").val() == "199"){$("#picture_crop_y").val("200")}') | ||
page.execute_script('if ($("#picture_crop_w").val() == "399"){$("#picture_crop_w").val("400")}') | ||
|
||
click_button "Crop image" | ||
|
||
sleep 1 | ||
compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).should eq(0.0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "spec_helper" | ||
|
||
describe "Image crop" do | ||
|
||
after do | ||
Landscape.destroy_all | ||
end | ||
|
||
|
||
it "crops an image" do | ||
visit landscapes_path | ||
|
||
click_link "New Landscape" | ||
|
||
fill_in "Name", :with => "Mountains" | ||
attach_file "Picture", "test_app/test/fixtures/matterhorn.jpg" | ||
click_button "Create Landscape" | ||
|
||
page.should have_css("#picture_crop_preview_wrapper") | ||
page.should have_css("#picture_crop_preview") | ||
page.should have_css("#picture_cropbox") | ||
|
||
page.should have_css("#landscape_picture_original_w") | ||
|
||
find("#landscape_picture_original_w").value.should eq("1024.0") | ||
find("#landscape_picture_original_h").value.should eq("768.0") | ||
find("#landscape_picture_box_w").value.should eq("600") | ||
find("#picture_aspect").value.should eq((4.0 / 3.0).to_s) | ||
|
||
find("#picture_crop_x").set "300.0" | ||
find("#picture_crop_y").set "200.0" | ||
find("#picture_crop_w").set "400" | ||
find("#picture_crop_h").set "300" | ||
|
||
click_button "Crop image" | ||
|
||
compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).should eq(0.0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require "spec_helper" | ||
|
||
describe "Active Record Extension" do | ||
|
||
before do | ||
@landscape = Landscape.new(:name => "Mountains") | ||
@landscape.picture = open("test_app/test/fixtures/matterhorn.jpg") | ||
@landscape.save | ||
end | ||
|
||
|
||
after do | ||
@landscape.destroy | ||
end | ||
|
||
|
||
it "includes accessors to the model" do | ||
%w{crop_x crop_y crop_w crop_h original_w original_h box_w aspect}.each do |m| | ||
@landscape.should respond_to(:"picture_#{m}") | ||
@landscape.should respond_to(:"picture_#{m}=") | ||
end | ||
end | ||
|
||
|
||
it "registers the post processor" do | ||
@landscape.attachment_definitions[:picture][:processors].should eq([:cropper]) | ||
end | ||
|
||
|
||
it "defines an after update callback" do | ||
@landscape._update_callbacks.map do |e| | ||
e.instance_values['filter'].should eq(:reprocess_to_crop_picture_attachment) | ||
end | ||
end | ||
|
||
|
||
it "returns image properties" do | ||
@landscape.picture_aspect.should eq(4.0 / 3.0) | ||
|
||
@landscape.image_geometry(:picture).width.should eq(1024.0) | ||
@landscape.image_geometry(:picture).height.should eq(768.0) | ||
end | ||
|
||
|
||
it "knows when to crop" do | ||
@landscape.cropping?(:picture).should be(false) | ||
@landscape.picture_crop_x = 0.0 | ||
@landscape.picture_crop_y = 0.0 | ||
@landscape.picture_crop_w = 400 | ||
@landscape.picture_crop_h = 300 | ||
@landscape.cropping?(:picture).should be(true) | ||
end | ||
|
||
|
||
it "crops images" do | ||
@landscape.picture_crop_x = 300.0 | ||
@landscape.picture_crop_y = 200.0 | ||
@landscape.picture_crop_w = 400 | ||
@landscape.picture_crop_h = 300 | ||
@landscape.save | ||
|
||
compare_images(CROPPED_IMG_PATH, @landscape.picture.path(:medium)).should eq(0.0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This file is copied to spec/ when you run 'rails generate rspec:install' | ||
ENV["RAILS_ENV"] = 'test' | ||
require File.expand_path("../../test_app/config/environment", __FILE__) | ||
require 'rspec/rails' | ||
require 'rspec/autorun' | ||
|
||
# Requires supporting ruby files with custom matchers and macros, etc, | ||
# in spec/support/ and its subdirectories. | ||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} | ||
|
||
# Previously cropped image. Used for comparing test cropped images with RMagick | ||
CROPPED_IMG_PATH = "test_app/test/fixtures/test_img.jpg" | ||
|
||
RSpec.configure do |config| | ||
# ## Mock Framework | ||
# | ||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: | ||
# | ||
# config.mock_with :mocha | ||
# config.mock_with :flexmock | ||
# config.mock_with :rr | ||
|
||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures | ||
config.fixture_path = "#{::Rails.root}/spec/fixtures" | ||
|
||
# If you're not using ActiveRecord, or you'd prefer not to run each of your | ||
# examples within a transaction, remove the following line or assign false | ||
# instead of true. | ||
config.use_transactional_fixtures = true | ||
|
||
# If true, the base class of anonymous controllers will be inferred | ||
# automatically. This will be the default behavior in future versions of | ||
# rspec-rails. | ||
config.infer_base_class_for_anonymous_controllers = false | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
config.order = "random" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "RMagick" | ||
|
||
def compare_images(test_image_path, cropped_image_path) | ||
test_img = Magick::Image::read(test_image_path).first | ||
target_img = Magick::Image::read(cropped_image_path).first | ||
|
||
test_img.compare_channel(target_img, Magick::MeanAbsoluteErrorMetric).second | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rails', '3.2.8' | ||
|
||
gem 'jquery-rails' | ||
gem 'execjs' | ||
gem 'therubyracer' | ||
gem 'sqlite3' | ||
gem 'paperclip' | ||
|
||
gem 'papercrop', :path => ".." | ||
|
||
group :assets do | ||
gem 'sass-rails', '~> 3.2.3' | ||
gem 'coffee-rails', '~> 3.2.1' | ||
gem 'uglifier', '>= 1.0.3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env rake | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require File.expand_path('../config/application', __FILE__) | ||
|
||
TestApp::Application.load_tasks |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This is a manifest file that'll be compiled into application.js, which will include all the files | ||
// listed below. | ||
// | ||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | ||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | ||
// | ||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | ||
// the compiled file. | ||
// | ||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD | ||
// GO AFTER THE REQUIRES BELOW. | ||
// | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require jquery.jcrop | ||
//= require papercrop | ||
//= require_tree . |
Oops, something went wrong.