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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/controllers/lady_josephine/images_controller.rb +9 -1
- data/app/uploader/lady_josephine/base_uploader.rb +20 -0
- data/app/uploader/lady_josephine/image_uploader.rb +8 -32
- data/lib/lady_josephine/version.rb +1 -1
- data/lib/lady_josephine.rb +19 -0
- data/spec/controllers/lady_josephine/images_controller_spec.rb +6 -0
- data/spec/dummy/log/test.log +2982 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/thumbnail_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297625-14767-2478/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297625-14767-5632/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297625-14767-6955/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297625-14767-7681/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-0391/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-0678/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-2981/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-3843/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-4815/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-5314/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-6911/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297650-14955-8584/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-1076/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-1603/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-2185/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-2208/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-4253/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297683-15123-5822/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297684-15123-6302/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297684-15123-7185/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297837-15423-0221/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297837-15423-4034/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297941-15648-3378/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458297941-15648-7747/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298031-15804-3719/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298031-15804-6451/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298080-15891-3288/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298080-15891-8575/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-2061/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/thumbnail_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-4216/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298150-16006-7424/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/thumbnail_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-1253/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-2402/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298244-16154-9561/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298289-16330-3415/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1458298289-16330-4694/w600_depressed-cat.jpg +0 -0
- data/spec/helper/lady_josephine/sir_trevor_helper_spec.rb +1 -1
- metadata +88 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 311475881a67cedf75b8623723f7fc0cdfd5da33
|
4
|
+
data.tar.gz: 0dd20039fc936bd66dd66daa8368a7ba164d9ed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea074bbde1e4caaa604ccf74edadfa34e56858dbcdd7ad6c919a82737a629cd823759c2799c7772a63b09b75e4b43ad46bbdc829972910df149911a4c250b7d
|
7
|
+
data.tar.gz: 5ec432b9ceb41339aacfd834912c0ca121b99c165b08128afc94fbebc4f9cd5ab8f08cb4c108019ba4ba7b3811d695889e153c4ac9cc7eb4a8c2b0792192f249
|
data/MIT-LICENSE
CHANGED
@@ -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
|
-
|
108
|
-
|
109
|
-
|
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
|
140
|
-
|
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
|
data/lib/lady_josephine.rb
CHANGED
@@ -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
|