papercrop 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of papercrop might be problematic. Click here for more details.

data/README.md CHANGED
@@ -50,6 +50,14 @@ Regardless of the width, the preview box and the cropping area will have the asp
50
50
 
51
51
  If you're rendering it on ajax ensure to call init_papercrop() in js after loading the crop form to make things work properly.
52
52
 
53
+ ### Running the Tests
54
+
55
+ We are using a dummy application to handle some of our test cases. You can find this in the `/test_app` directory and should be able to run this as a regular Rails 4 app _(using the `rails s` command)_ if you're interested in taking a look. You may need to create the mock database for the `test_app` before your tests will start to pass. This means you need to run `rake db:create db:migrate db:test:prepare` from within the `test_app` directory.
56
+
57
+ In order to fully test our gem, we needed to use [Selenium](http://docs.seleniumhq.org/download/). Getting this setup is beyond the scope of this Readme.
58
+
59
+ Once you have everything setup, you should be able `bundle exec rake` from the root directory have everything run. If you've installed Selenium properly, you should see an automated instance of your browser _(eg. Firefox)_ pop up and run through some of the integration tests.
60
+
53
61
  That's all!
54
62
 
55
63
  ### Credits and resources
@@ -1,51 +1,51 @@
1
- var jcrop_api;
2
-
3
- window.init_papercrop = function() {
4
- $("div[id$=_cropbox]").each(function() {
5
-
6
- var attachment = $(this).attr("id").replace("_cropbox", "");
7
- var preview = !!$("#" + attachment + "_crop_preview").length;
8
- var aspect = $("input#" + attachment + "_aspect").val();
9
- var width = $(this).width();
10
-
11
- console.log($(this));
12
-
13
- update_crop = function(coords) {
14
- var preview_width, rx, ry;
15
-
16
- if (preview) {
17
- preview_width = $("#" + attachment + "_crop_preview_wrapper").width();
18
-
19
- rx = preview_width / coords.w;
20
- ry = preview_width / coords.h;
21
-
22
- $("img#" + attachment + "_crop_preview").css({
23
- width : Math.round(rx * $("input[id$='_" + attachment + "_original_w']").val()) + "px",
24
- height : Math.round((ry * $("input[id$='_" + attachment + "_original_h']").val()) / aspect) + "px",
25
- marginLeft : "-" + Math.round(rx * coords.x) + "px",
26
- marginTop : "-" + Math.round((ry * coords.y) / aspect) + "px"
27
- });
28
- }
29
-
30
- $("#" + attachment + "_crop_x").val(Math.round(coords.x));
31
- $("#" + attachment + "_crop_y").val(Math.round(coords.y));
32
- $("#" + attachment + "_crop_w").val(Math.round(coords.w));
33
- $("#" + attachment + "_crop_h").val(Math.round(coords.h));
34
- };
35
-
36
- $(this).find("img").Jcrop({
37
- onChange : update_crop,
38
- onSelect : update_crop,
39
- setSelect : [0, 0, 250, 250],
40
- aspectRatio : aspect,
41
- boxWidth : $("input[id$='_" + attachment + "_box_w']").val()
42
- }, function() {
43
- jcrop_api = this;
1
+ (function ($) {
2
+ window.jcrop_api = null;
3
+
4
+ window.init_papercrop = function() {
5
+ $("div[id$=_cropbox]").each(function() {
6
+
7
+ var attachment = $(this).attr("id").replace("_cropbox", "");
8
+ var preview = !!$("#" + attachment + "_crop_preview").length;
9
+ var aspect = $("input#" + attachment + "_aspect").val();
10
+ var width = $(this).width();
11
+
12
+ update_crop = function(coords) {
13
+ var preview_width, rx, ry;
14
+
15
+ if (preview) {
16
+ preview_width = $("#" + attachment + "_crop_preview_wrapper").width();
17
+
18
+ rx = preview_width / coords.w;
19
+ ry = preview_width / coords.h;
20
+
21
+ $("img#" + attachment + "_crop_preview").css({
22
+ width : Math.round(rx * $("input[id$='_" + attachment + "_original_w']").val()) + "px",
23
+ height : Math.round((ry * $("input[id$='_" + attachment + "_original_h']").val()) / aspect) + "px",
24
+ marginLeft : "-" + Math.round(rx * coords.x) + "px",
25
+ marginTop : "-" + Math.round((ry * coords.y) / aspect) + "px"
26
+ });
27
+ }
28
+
29
+ $("#" + attachment + "_crop_x").val(Math.round(coords.x));
30
+ $("#" + attachment + "_crop_y").val(Math.round(coords.y));
31
+ $("#" + attachment + "_crop_w").val(Math.round(coords.w));
32
+ $("#" + attachment + "_crop_h").val(Math.round(coords.h));
33
+ };
34
+
35
+ $(this).find("img").Jcrop({
36
+ onChange : update_crop,
37
+ onSelect : update_crop,
38
+ setSelect : [0, 0, 250, 250],
39
+ aspectRatio : aspect,
40
+ boxWidth : $("input[id$='_" + attachment + "_box_w']").val()
41
+ }, function() {
42
+ jcrop_api = this;
43
+ });
44
44
  });
45
- });
46
- };
45
+ };
47
46
 
47
+ $(document).ready(function() {
48
+ init_papercrop();
49
+ });
48
50
 
49
- $(document).ready(function() {
50
- init_papercrop();
51
- });
51
+ }(jQuery));
data/lib/papercrop.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'papercrop/engine'
2
2
  require 'papercrop/reg_exp'
3
- require 'papercrop/active_record_extension'
3
+ require 'papercrop/model_extension'
4
4
  require 'papercrop/helpers'
5
5
  require 'paperclip_processors/cropper'
@@ -1,10 +1,5 @@
1
1
  module Papercrop
2
- module ActiveRecordExtension
3
-
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
7
-
2
+ module ModelExtension
8
3
 
9
4
  module ClassMethods
10
5
 
@@ -116,9 +111,22 @@ module Papercrop
116
111
  end
117
112
 
118
113
 
114
+ # ActiveRecord support
119
115
  if defined? ActiveRecord::Base
120
116
  ActiveRecord::Base.class_eval do
121
- include Papercrop::ActiveRecordExtension
122
- include Papercrop::ActiveRecordExtension::InstanceMethods
117
+ extend Papercrop::ModelExtension::ClassMethods
118
+ include Papercrop::ModelExtension::InstanceMethods
123
119
  end
124
- end
120
+ end
121
+
122
+
123
+ # Mongoid support
124
+ if defined? Mongoid::Document
125
+ Mongoid::Document::ClassMethods.module_eval do
126
+ include Papercrop::ModelExtension::ClassMethods
127
+ end
128
+
129
+ Mongoid::Document.module_eval do
130
+ include Papercrop::ModelExtension::InstanceMethods
131
+ end
132
+ end
@@ -19,7 +19,7 @@ describe "Image crop with JS", :js => true do
19
19
  click_button "Crop image"
20
20
 
21
21
  sleep 1
22
- compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).should eq(0.0)
22
+ compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).round(2).should eq(0.0)
23
23
  end
24
24
 
25
25
 
@@ -45,6 +45,6 @@ describe "Image crop with JS", :js => true do
45
45
  click_button "Crop image"
46
46
 
47
47
  sleep 1
48
- compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).should eq(0.0)
48
+ compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).round(2).should eq(0.0)
49
49
  end
50
50
  end
@@ -29,6 +29,6 @@ describe "Image crop" do
29
29
 
30
30
  click_button "Crop image"
31
31
 
32
- compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).should eq(0.0)
32
+ compare_images(CROPPED_IMG_PATH, Landscape.last.picture.path(:medium)).round(2).should eq(0.0)
33
33
  end
34
34
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "Active Record Extension" do
3
+ describe "Model Extension" do
4
4
 
5
5
  before do
6
6
  @landscape = Landscape.new(:name => "Mountains")
@@ -29,8 +29,8 @@ describe "Active Record Extension" do
29
29
  @landscape.picture_crop_w = 400
30
30
  @landscape.picture_crop_h = 300
31
31
  @landscape.save
32
-
33
- compare_images(CROPPED_IMG_PATH, @landscape.picture.path(:medium)).should eq(0.0)
32
+ # Rounding to account for different versions of imagemagick
33
+ compare_images(CROPPED_IMG_PATH, @landscape.picture.path(:medium)).round(2).should eq(0.0)
34
34
  end
35
35
 
36
36
 
@@ -60,7 +60,8 @@ describe "Active Record Extension" do
60
60
 
61
61
 
62
62
  it "registers the post processor" do
63
- @landscape.attachment_definitions[:picture][:processors].should eq([:cropper])
63
+ definitions = Paperclip::AttachmentRegistry.definitions_for(Landscape)
64
+ definitions[:picture][:processors].should eq([:cropper])
64
65
  end
65
66
 
66
67
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papercrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-22 00:00:00.000000000 Z
12
+ date: 2014-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -171,6 +171,22 @@ dependencies:
171
171
  - - ! '>='
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: selenium-webdriver
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
174
190
  description: An easy extension for Paperclip to crop your image uploads using jCrop
175
191
  email: rsantamaria.dev@gmail.com
176
192
  executables: []
@@ -182,9 +198,9 @@ files:
182
198
  - lib/assets/javascripts/papercrop.js
183
199
  - lib/assets/stylesheets/jquery.jcrop.css
184
200
  - lib/paperclip_processors/cropper.rb
185
- - lib/papercrop/active_record_extension.rb
186
201
  - lib/papercrop/engine.rb
187
202
  - lib/papercrop/helpers.rb
203
+ - lib/papercrop/model_extension.rb
188
204
  - lib/papercrop/reg_exp.rb
189
205
  - lib/papercrop.rb
190
206
  - vendor/jcrop-v0.9.10/css/Jcrop.gif
@@ -195,12 +211,13 @@ files:
195
211
  - spec/helpers/form_helpers_spec.rb
196
212
  - spec/integration/papercrop_js_spec.rb
197
213
  - spec/integration/papercrop_spec.rb
198
- - spec/model_extensions/active_record_spec.rb
214
+ - spec/model_extensions/model_extension_spec.rb
199
215
  - spec/model_extensions/reg_exp_spec.rb
200
216
  - spec/spec_helper.rb
201
217
  - spec/support/compare_images.rb
202
218
  homepage: https://github.com/rsantamaria/papercrop
203
- licenses: []
219
+ licenses:
220
+ - MIT
204
221
  post_install_message:
205
222
  rdoc_options: []
206
223
  require_paths:
@@ -211,15 +228,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
228
  - - ! '>='
212
229
  - !ruby/object:Gem::Version
213
230
  version: '0'
231
+ segments:
232
+ - 0
233
+ hash: 3120983817575737500
214
234
  required_rubygems_version: !ruby/object:Gem::Requirement
215
235
  none: false
216
236
  requirements:
217
237
  - - ! '>='
218
238
  - !ruby/object:Gem::Version
219
239
  version: '0'
240
+ segments:
241
+ - 0
242
+ hash: 3120983817575737500
220
243
  requirements: []
221
244
  rubyforge_project:
222
- rubygems_version: 1.8.24
245
+ rubygems_version: 1.8.25
223
246
  signing_key:
224
247
  specification_version: 3
225
248
  summary: Paperclip extension for cropping images
@@ -227,8 +250,7 @@ test_files:
227
250
  - spec/helpers/form_helpers_spec.rb
228
251
  - spec/integration/papercrop_js_spec.rb
229
252
  - spec/integration/papercrop_spec.rb
230
- - spec/model_extensions/active_record_spec.rb
253
+ - spec/model_extensions/model_extension_spec.rb
231
254
  - spec/model_extensions/reg_exp_spec.rb
232
255
  - spec/spec_helper.rb
233
256
  - spec/support/compare_images.rb
234
- has_rdoc: