lady_josephine 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/app/controllers/lady_josephine/images_controller.rb +9 -1
  4. data/app/uploader/lady_josephine/base_uploader.rb +20 -0
  5. data/app/uploader/lady_josephine/image_uploader.rb +8 -32
  6. data/lib/lady_josephine/version.rb +1 -1
  7. data/lib/lady_josephine.rb +19 -0
  8. data/spec/controllers/lady_josephine/images_controller_spec.rb +6 -0
  9. data/spec/dummy/log/test.log +2982 -0
  10. data/spec/dummy/public/storage/test/lady_josephine/image/file/1/thumbnail_depressed-cat.jpg +0 -0
  11. data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w1000_depressed-cat.jpg +0 -0
  12. data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w2000_depressed-cat.jpg +0 -0
  13. data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w300_depressed-cat.jpg +0 -0
  14. data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w600_depressed-cat.jpg +0 -0
  15. data/spec/dummy/public/uploads/tmp/1458297625-14767-2478/depressed-cat.jpg +0 -0
  16. data/spec/dummy/public/uploads/tmp/1458297625-14767-5632/depressed-cat.jpg +0 -0
  17. data/spec/dummy/public/uploads/tmp/1458297625-14767-6955/depressed-cat.jpg +0 -0
  18. data/spec/dummy/public/uploads/tmp/1458297625-14767-7681/depressed-cat.jpg +0 -0
  19. data/spec/dummy/public/uploads/tmp/1458297650-14955-0391/depressed-cat.jpg +0 -0
  20. data/spec/dummy/public/uploads/tmp/1458297650-14955-0678/w600_depressed-cat.jpg +0 -0
  21. data/spec/dummy/public/uploads/tmp/1458297650-14955-2981/depressed-cat.jpg +0 -0
  22. data/spec/dummy/public/uploads/tmp/1458297650-14955-3843/depressed-cat.jpg +0 -0
  23. data/spec/dummy/public/uploads/tmp/1458297650-14955-4815/w600_depressed-cat.jpg +0 -0
  24. data/spec/dummy/public/uploads/tmp/1458297650-14955-5314/w600_depressed-cat.jpg +0 -0
  25. data/spec/dummy/public/uploads/tmp/1458297650-14955-6911/w600_depressed-cat.jpg +0 -0
  26. data/spec/dummy/public/uploads/tmp/1458297650-14955-8584/depressed-cat.jpg +0 -0
  27. data/spec/dummy/public/uploads/tmp/1458297683-15123-1076/w600_depressed-cat.jpg +0 -0
  28. data/spec/dummy/public/uploads/tmp/1458297683-15123-1603/w600_depressed-cat.jpg +0 -0
  29. data/spec/dummy/public/uploads/tmp/1458297683-15123-2185/depressed-cat.jpg +0 -0
  30. data/spec/dummy/public/uploads/tmp/1458297683-15123-2208/w600_depressed-cat.jpg +0 -0
  31. data/spec/dummy/public/uploads/tmp/1458297683-15123-4253/depressed-cat.jpg +0 -0
  32. data/spec/dummy/public/uploads/tmp/1458297683-15123-5822/depressed-cat.jpg +0 -0
  33. data/spec/dummy/public/uploads/tmp/1458297684-15123-6302/w600_depressed-cat.jpg +0 -0
  34. data/spec/dummy/public/uploads/tmp/1458297684-15123-7185/depressed-cat.jpg +0 -0
  35. data/spec/dummy/public/uploads/tmp/1458297837-15423-0221/w600_depressed-cat.jpg +0 -0
  36. data/spec/dummy/public/uploads/tmp/1458297837-15423-4034/depressed-cat.jpg +0 -0
  37. data/spec/dummy/public/uploads/tmp/1458297941-15648-3378/w600_depressed-cat.jpg +0 -0
  38. data/spec/dummy/public/uploads/tmp/1458297941-15648-7747/depressed-cat.jpg +0 -0
  39. data/spec/dummy/public/uploads/tmp/1458298031-15804-3719/w600_depressed-cat.jpg +0 -0
  40. data/spec/dummy/public/uploads/tmp/1458298031-15804-6451/depressed-cat.jpg +0 -0
  41. data/spec/dummy/public/uploads/tmp/1458298080-15891-3288/w600_depressed-cat.jpg +0 -0
  42. data/spec/dummy/public/uploads/tmp/1458298080-15891-8575/depressed-cat.jpg +0 -0
  43. data/spec/dummy/public/uploads/tmp/1458298150-16006-2061/w2000_depressed-cat.jpg +0 -0
  44. data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/depressed-cat.jpg +0 -0
  45. data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/thumbnail_depressed-cat.jpg +0 -0
  46. data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/w1000_depressed-cat.jpg +0 -0
  47. data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/w300_depressed-cat.jpg +0 -0
  48. data/spec/dummy/public/uploads/tmp/1458298150-16006-7424/w600_depressed-cat.jpg +0 -0
  49. data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/depressed-cat.jpg +0 -0
  50. data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/thumbnail_depressed-cat.jpg +0 -0
  51. data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/w1000_depressed-cat.jpg +0 -0
  52. data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/w300_depressed-cat.jpg +0 -0
  53. data/spec/dummy/public/uploads/tmp/1458298244-16154-2402/w600_depressed-cat.jpg +0 -0
  54. data/spec/dummy/public/uploads/tmp/1458298244-16154-9561/w2000_depressed-cat.jpg +0 -0
  55. data/spec/dummy/public/uploads/tmp/1458298289-16330-3415/depressed-cat.jpg +0 -0
  56. data/spec/dummy/public/uploads/tmp/1458298289-16330-4694/w600_depressed-cat.jpg +0 -0
  57. data/spec/helper/lady_josephine/sir_trevor_helper_spec.rb +1 -1
  58. metadata +88 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60a6a3687ea48331847dc71805138f3b6538caff
4
- data.tar.gz: cc3f703f2ee2a6e7fdddc163a22802aa372b0442
3
+ metadata.gz: 311475881a67cedf75b8623723f7fc0cdfd5da33
4
+ data.tar.gz: 0dd20039fc936bd66dd66daa8368a7ba164d9ed5
5
5
  SHA512:
6
- metadata.gz: 7a3ff2974e150f88c654102fbd83740f1d892044309be6f4afbf59f8d069e5384156233c273493a6eae6458167ab86af4f0e0e0d054c5c3d1c73ec1b71af395b
7
- data.tar.gz: debb9ad919884f916f89537a27e5671ecbb4735f0f52eca743125d4943616d67559b754ca97498ab0f096932d8b8abd4878b093a6c6f87e10d4eab12097bd9e9
6
+ metadata.gz: 9ea074bbde1e4caaa604ccf74edadfa34e56858dbcdd7ad6c919a82737a629cd823759c2799c7772a63b09b75e4b43ad46bbdc829972910df149911a4c250b7d
7
+ data.tar.gz: 5ec432b9ceb41339aacfd834912c0ca121b99c165b08128afc94fbebc4f9cd5ab8f08cb4c108019ba4ba7b3811d695889e153c4ac9cc7eb4a8c2b0792192f249
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 Bodo Tasche
1
+ Copyright (c) 2016 by Bitcrowd GmbH - http://bitcrowd.net
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -5,7 +5,7 @@ module LadyJosephine
5
5
  image = Image.from_params image_params
6
6
 
7
7
  if image && image.save
8
- response = {file: {url: image.file.url}}
8
+ response = {file: {url: image.file.url}, versions: sizes_hash(image.file)}
9
9
  render json: response.as_json, status: 200
10
10
  elsif image
11
11
  render json: image.file.errors, status: 500
@@ -25,5 +25,13 @@ module LadyJosephine
25
25
  params
26
26
  end
27
27
 
28
+ def sizes_hash(image)
29
+ result = {}
30
+ image.versions.each do |version, metadata|
31
+ result[version] = metadata.url
32
+ end
33
+ result
34
+ end
35
+
28
36
  end
29
37
  end
@@ -43,5 +43,25 @@ module LadyJosephine
43
43
  img
44
44
  end
45
45
  end
46
+
47
+ def compress_to_fill(width, height, percentage = 70)
48
+ manipulate! do |img|
49
+ img.resize "#{width}x#{height}^"
50
+ img.gravity "center"
51
+ img.crop "#{width}x#{height}+0+0!"
52
+
53
+ if img.mime_type.match(/(png|jpeg|jpg)\z/i)
54
+ img.combine_options do |c|
55
+ c.quality(percentage.to_s)
56
+ c.depth "8"
57
+ c.interlace "plane"
58
+ end
59
+ end
60
+
61
+ img = yield(img) if block_given?
62
+ add_metadata(img)
63
+ img
64
+ end
65
+ end
46
66
  end
47
67
  end
@@ -104,40 +104,16 @@ module LadyJosephine
104
104
  process :compress_to_fit => [2000, nil, 65]
105
105
  end
106
106
 
107
- def large
108
- w2000
109
- end
110
-
111
- def medium
112
- w1000
113
- end
114
-
115
- def small
116
- w300
117
- end
118
-
119
- def without_meta_data
120
- w2000
121
- end
122
-
123
- def thumb
124
- w300
125
- end
126
-
127
- def preview
128
- w300
129
- end
130
-
131
- def preview_retina
132
- w600
133
- end
134
-
135
- def main
136
- w1000
107
+ LadyJosephine.image_sizes.each do |key, value|
108
+ version key do
109
+ process dynamic_version: key
110
+ end
137
111
  end
138
112
 
139
- def main_retina
140
- w2000
113
+ def dynamic_version(version)
114
+ LadyJosephine.image_sizes[version].each do |method, args|
115
+ self.send method, *args
116
+ end
141
117
  end
142
118
 
143
119
  def extension_white_list
@@ -1,3 +1,3 @@
1
1
  module LadyJosephine
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -20,4 +20,23 @@ module LadyJosephine
20
20
  mattr_accessor :user_class_name
21
21
  @@user_class_name = "User"
22
22
 
23
+ mattr_accessor :image_sizes
24
+ @@image_sizes = {
25
+ thumbnail: {
26
+ compress_to_fill: [128, 128, 70],
27
+ },
28
+ w300: {
29
+ compress_to_fit: [300, nil, 70]
30
+ },
31
+ w600: {
32
+ compress_to_fit: [600, nil, 70]
33
+ },
34
+ w1000: {
35
+ compress_to_fit: [1000, nil, 65]
36
+ },
37
+ w2000: {
38
+ compress_to_fit: [2000, nil, 65]
39
+ }
40
+ }
41
+
23
42
  end
@@ -30,6 +30,12 @@ describe LadyJosephine::ImagesController, type: :controller do
30
30
  expect(image.uploadable_attribute).to eq "content-data"
31
31
  end
32
32
 
33
+ it 'should return a hash with all image urls for all versions' do
34
+ post :create, attachment: { name: 'file.jpg', file: file}, "block-uuid" => "uuid-uuid-uuid", "article-uuid" => article.lady_josephine_server_uuid, "model-name" => "article", "column-name" => "content-data"
35
+ expect(response.status).to eq 200
36
+ expect(response.body).to eq '{"file":{"url":"/storage/test/lady_josephine/image/file/1/depressed-cat.jpg"},"versions":{"w300":"/storage/test/lady_josephine/image/file/1/w300_depressed-cat.jpg","w600":"/storage/test/lady_josephine/image/file/1/w600_depressed-cat.jpg","w1000":"/storage/test/lady_josephine/image/file/1/w1000_depressed-cat.jpg","w2000":"/storage/test/lady_josephine/image/file/1/w2000_depressed-cat.jpg","thumbnail":"/storage/test/lady_josephine/image/file/1/thumbnail_depressed-cat.jpg"}}'
37
+ end
38
+
33
39
  end
34
40
 
35
41
  end