ack_rails_admin_jcrop 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2f7aaffc29570a30e8fa6b2ef6ed85fb267eda0
4
- data.tar.gz: 70aa9d5bf1d36dd87a9ac6eafd7523ee7395339d
3
+ metadata.gz: 3dda7fe91b561d2f47b8db348d74ac936201dfb1
4
+ data.tar.gz: 9cf0765f2b515a8111fe4a9721c77ff1cbb7dfae
5
5
  SHA512:
6
- metadata.gz: 5cfdb44457a1a47d4168573cc0b57011be867fc130bbb599c22eb04a75bdec6a961f85df6beb03d64c6882b8279f8e63e5a2daac1b436fde31b0d3fe0326f686
7
- data.tar.gz: 01c72b6b95acd9705ed5c85011965dad1ba682f417e00278a460a448384a0f1455017be417b48be6bdda56d6da3bd2f4038f9311728e688ebc74233049b7242c
6
+ metadata.gz: 03cfe60e3d081c9930584fd747f61fe244b4f3c72d367fc6bd255a4dc48d4c9dfcb8fffa661d6a3c3570869a3615bdfff152eb920c2c397719fa02f2d51d3c39
7
+ data.tar.gz: 336fa5f79efe08c07936cb60b61d07172af73d32ed8b65eb4c26b01c5f1d9a86ae09652de657639c9286046b4380abe3365941a363bba64788f9be2c6a77fe07
@@ -58,7 +58,7 @@ module RailsAdmin
58
58
  end
59
59
 
60
60
  def update
61
- @object.rails_admin_crop! params
61
+ @object.rails_admin_crop! params.merge(crop_process_before: '+repage', crop_process_after: '+repage')
62
62
 
63
63
  respond_to do |format|
64
64
  format.html { redirect_to_on_success }
@@ -40,10 +40,12 @@ module Paperclip
40
40
  ary.delete_at i+1
41
41
  ary.delete_at i
42
42
  end
43
- repage_before = ['+repage']
44
- crop = ['-crop', crop_params]
45
- repage_after = ['+repage']
46
- repage_before + crop + repage_after + ary
43
+
44
+ process_before = [@attachment.instance.crop_process_before]
45
+ crop = ['-crop', crop_params]
46
+ process_after = [@attachment.instance.crop_process_after]
47
+
48
+ process_before + crop + process_after + ary
47
49
  else
48
50
  super
49
51
  end
@@ -51,7 +53,17 @@ module Paperclip
51
53
 
52
54
  def crop_params
53
55
  target = @attachment.instance
54
- "'#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"
56
+
57
+ w = target.crop_w.to_i
58
+ h = target.crop_h.to_i
59
+ x = target.crop_x.to_i
60
+ y = target.crop_y.to_i
61
+
62
+ x = "+#{x}" if x >= 0
63
+ y = "+#{y}" if y >= 0
64
+ geometry = "#{w}x#{h}#{x}#{y}"
65
+
66
+ geometry
55
67
  end
56
68
  end
57
69
 
@@ -8,7 +8,10 @@ module RailsAdminJcrop
8
8
  end
9
9
 
10
10
  def minimagick_crop(img, w, h, x, y)
11
- geometry = "#{w}x#{h}+#{x}+#{y}"
11
+ x = "+#{x}" if x >= 0
12
+ y = "+#{y}" if y >= 0
13
+ geometry = "#{w}x#{h}#{x}#{y}"
14
+
12
15
  img.crop geometry
13
16
  end
14
17
 
@@ -2,12 +2,14 @@ module RailsAdminJcrop
2
2
  module Orm
3
3
  module Extension
4
4
 
5
- CropFields = [:crop_x, :crop_y, :crop_w, :crop_h, :crop_field]
5
+ CropFields = [:crop_x, :crop_y, :crop_w, :crop_h, :crop_field, :crop_process_before, :crop_process_after]
6
6
 
7
7
  def self.included(base)
8
8
  base.send :attr_accessor, *CropFields
9
9
  end
10
10
 
11
+
12
+
11
13
  def rails_admin_cropping?
12
14
  CropFields.all? {|f| send(f).present?}
13
15
  end
@@ -17,6 +19,30 @@ module RailsAdminJcrop
17
19
  ::RailsAdminJcrop::AssetEngine.crop!(self, self.crop_field) if self.rails_admin_cropping?
18
20
  end
19
21
 
22
+
23
+
24
+
25
+ def auto_rails_admin_jcrop(field)
26
+ if !rails_admin_cropping? and self.try("#{field}_default_crop_params") and self.try("#{field}_updated_at_changed?")
27
+ rails_admin_crop! self.send("#{field}_default_crop_params")
28
+ end
29
+ end
30
+
31
+ def default_crop_params_for_left_top(field, width, height, left_offset = 0, top_offset = 0)
32
+ {
33
+ crop_x: left_offset, crop_y: left_offset, crop_w: width, crop_h: height, crop_field: field,
34
+ crop_process_before: '+repage', crop_process_after: '+repage'
35
+ }
36
+ end
37
+
38
+
39
+ def default_crop_params_for_center(field, width, height, left_offset = 0, top_offset = 0)
40
+ {
41
+ crop_x: left_offset, crop_y: top_offset, crop_w: width, crop_h: height, crop_field: :image,
42
+ crop_process_before: '-gravity Center', crop_process_after: '+repage'
43
+ }
44
+ end
45
+
20
46
  end
21
47
  end
22
48
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminJcrop
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ack_rails_admin_jcrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kiseliev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-20 00:00:00.000000000 Z
12
+ date: 2016-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails_admin