uploadbox 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/app/helpers/uploadbox/img_helper.rb +4 -5
- data/lib/uploadbox/image_uploader.rb +31 -2
- data/lib/uploadbox/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e67bd33d5d1a517c147e1220c50de325994091
|
4
|
+
data.tar.gz: 1a75ed1144f8b7957afb5171227809fb1346e62a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b000d2b6cce30d44614441f51341628d5881864a4e900e8d253287c20be9c4472297a3559e7b951393e2e37193d365d3c300375f0250f32d8bb26805fee13977
|
7
|
+
data.tar.gz: fc091d97575dd2226d83f159a584a680a6074a9b271250592aa07fcfc48b02dc092c0bed124cab996622183b49d57f0d970b3526d4e817d41a373953d9c0848e
|
data/README.md
CHANGED
@@ -60,10 +60,13 @@ Edit CORS config for the bucket
|
|
60
60
|
Add `uploads_one` to your model
|
61
61
|
```
|
62
62
|
class Post < ActiveRecord::Base
|
63
|
-
uploads_one :picture, thumb: [100, 100], regular: [600, 300]
|
63
|
+
uploads_one :picture, thumb: [100, 100], regular: [600, 300], placeholder: 'default.png'
|
64
64
|
end
|
65
65
|
```
|
66
66
|
|
67
|
+
If `placeholder` is set posts without uploads will render the placeholder.
|
68
|
+
Empty `@post.picture.thumb` will render `app/assets/images/thumb_default.png`
|
69
|
+
|
67
70
|
Add field to form
|
68
71
|
```
|
69
72
|
<%= f.uploader :picture %>
|
@@ -15,12 +15,11 @@ module Uploadbox
|
|
15
15
|
).gsub("\n", "")
|
16
16
|
end
|
17
17
|
|
18
|
-
def img(
|
19
|
-
|
20
|
-
|
21
|
-
image_tag(upload.url, width: upload.width, height: upload.height)
|
18
|
+
def img(source, options={})
|
19
|
+
if source.respond_to?(:url) and source.respond_to?(:width) and source.respond_to?(:height)
|
20
|
+
image_tag(source.url, {width: source.width, height: source.height}.merge(options))
|
22
21
|
else
|
23
|
-
image_tag(
|
22
|
+
image_tag(source, options)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -3,6 +3,7 @@ module Uploadbox
|
|
3
3
|
def uploads_one(upload_name, options={})
|
4
4
|
default_options = {
|
5
5
|
default: false,
|
6
|
+
placeholder: false,
|
6
7
|
removable: true,
|
7
8
|
retina: Uploadbox.retina,
|
8
9
|
quality: Uploadbox.retina ? (Uploadbox.retina_quality || 40) : (Uploadbox.image_quality || 80)
|
@@ -17,7 +18,35 @@ module Uploadbox
|
|
17
18
|
Uploadbox.const_set(upload_class_name, upload_class)
|
18
19
|
|
19
20
|
# @post.picture?
|
20
|
-
define_method("#{upload_name}?")
|
21
|
+
define_method("#{upload_name}?") do
|
22
|
+
upload = send("#{upload_name}_upload")
|
23
|
+
upload and upload.file?
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method(upload_name) do
|
27
|
+
upload = send("#{upload_name}_upload")
|
28
|
+
|
29
|
+
if upload
|
30
|
+
upload
|
31
|
+
else
|
32
|
+
image = Struct.new(:url, :width, :height) do
|
33
|
+
def to_s
|
34
|
+
url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
placeholder = Class.new do
|
39
|
+
upload_versions.keys.each do |version|
|
40
|
+
define_method(version) do
|
41
|
+
width = upload_versions[version][0]
|
42
|
+
height = upload_versions[version][1]
|
43
|
+
image.new("#{version}_#{options[:placeholder]}", width, height)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
placeholder.new
|
48
|
+
end
|
49
|
+
end
|
21
50
|
|
22
51
|
# @post.attach_picture
|
23
52
|
define_method("attach_#{upload_name}") do |upload_id|
|
@@ -86,7 +115,7 @@ module Uploadbox
|
|
86
115
|
mount_uploader :file, dynamic_uploader
|
87
116
|
end
|
88
117
|
|
89
|
-
has_one upload_name, as: :imageable, dependent: :destroy, class_name: "Uploadbox::#{self.to_s + upload_name.to_s.camelize}"
|
118
|
+
has_one "#{upload_name}_upload".to_sym, as: :imageable, dependent: :destroy, class_name: "Uploadbox::#{self.to_s + upload_name.to_s.camelize}"
|
90
119
|
end
|
91
120
|
|
92
121
|
end
|
data/lib/uploadbox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Protzek
|
@@ -333,6 +333,20 @@ dependencies:
|
|
333
333
|
- - ~>
|
334
334
|
- !ruby/object:Gem::Version
|
335
335
|
version: 0.7.1
|
336
|
+
- !ruby/object:Gem::Dependency
|
337
|
+
name: pry-rails
|
338
|
+
requirement: !ruby/object:Gem::Requirement
|
339
|
+
requirements:
|
340
|
+
- - ~>
|
341
|
+
- !ruby/object:Gem::Version
|
342
|
+
version: 0.3.2
|
343
|
+
type: :development
|
344
|
+
prerelease: false
|
345
|
+
version_requirements: !ruby/object:Gem::Requirement
|
346
|
+
requirements:
|
347
|
+
- - ~>
|
348
|
+
- !ruby/object:Gem::Version
|
349
|
+
version: 0.3.2
|
336
350
|
description: Uploadbox makes easy to manage files in your Rails application.
|
337
351
|
email:
|
338
352
|
- julio@startae.com.br
|