tessa 6.0.0.rc1 → 6.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -16
- data/lib/tessa/simple_form/asset_input.rb +39 -15
- data/lib/tessa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e21c3d74e92f753a5d6ae6b0e78adf670a512a029b4044c35b82a06f02b6b4
|
4
|
+
data.tar.gz: a653d63a20d3433b3c983b5b552d739dd2a75b77bb272f1f066ca06f07122f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1b13ee45b792918c844b31d23c888309be682e3df4b40533c5ac9ca51f9b8b39b2d96c836c19cd0d89776e697aa2b698db5d74d6496962c07b19da98d9aa13a
|
7
|
+
data.tar.gz: 81fbd95c45021c449ed445c6d9831c824095279d26dc249b475b2a3aca9acc238af86634a12efac47f9e057180fa5aad1d45a6cb4ece929273ab284ce11da355
|
data/README.md
CHANGED
@@ -23,6 +23,12 @@ When that migration is completed, v2.x of this gem will remove all code that acc
|
|
23
23
|
will transition to being simply a convenience wrapper around ActiveStorage, so that we don't have to re-write as much
|
24
24
|
of our code in our frontend apps.
|
25
25
|
|
26
|
+
v6.x of this gem is compatible with ActiveStorage v6 and above. Since v6, ActiveStorage now does everything that this
|
27
|
+
gem used to do, with the exception of Dropzone integration. Therefore, tessa-client v6 only contains the following
|
28
|
+
two modules:
|
29
|
+
1. A set of Javascript utilities to integrate Dropzone.js with ActiveStorage direct uploads
|
30
|
+
2. A SimpleForm helper to write out the hidden input fields for an ActiveStorage `has_one_attached`.
|
31
|
+
|
26
32
|
## Installation
|
27
33
|
|
28
34
|
Add this line to your application's Gemfile:
|
@@ -61,17 +67,7 @@ from the user's browser.
|
|
61
67
|
|
62
68
|
To get all this working, follow these steps:
|
63
69
|
|
64
|
-
1.
|
65
|
-
in your `config/routes.rb`, `mount Tessa::Engine, at: '/'`. It's important that it is mounted at root.
|
66
|
-
|
67
|
-
You can use Authentication around the engine to prevent unauthorized uploads. With devise it's as simple as:
|
68
|
-
```rb
|
69
|
-
authenticated :user do
|
70
|
-
mount Tessa::Engine, at: '/'
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
2. In your application.js, require the js libraries:
|
70
|
+
1. In your application.js, require the js libraries:
|
75
71
|
```js
|
76
72
|
//= require dropzone
|
77
73
|
//= require tessa
|
@@ -79,16 +75,14 @@ You can use Authentication around the engine to prevent unauthorized uploads. W
|
|
79
75
|
Note that this only works if you are using Sprockets.
|
80
76
|
If you are using another bundler, we don't support that yet.
|
81
77
|
|
82
|
-
|
78
|
+
2. use ActiveStorage to add an attached asset
|
83
79
|
|
84
80
|
```rb
|
85
81
|
class Model < ApplicationRecord
|
86
|
-
include Tessa::Model
|
87
|
-
|
88
82
|
has_one_attached :image
|
89
83
|
```
|
90
84
|
|
91
|
-
|
85
|
+
3. When rendering your form, use the SimpleForm helper to render the dropzone div:
|
92
86
|
|
93
87
|
```erb
|
94
88
|
<%= f.input :image,
|
@@ -97,7 +91,7 @@ class Model < ApplicationRecord
|
|
97
91
|
hint: "Use an image that is 1440 x 288 in size (5:1 aspect ratio)" %>
|
98
92
|
```
|
99
93
|
|
100
|
-
|
94
|
+
4. Configure your ActiveStorage service to accept direct uploads.
|
101
95
|
The disk service does this automatically. The S3 service requires additional CORS configuration.
|
102
96
|
|
103
97
|
## Contributing
|
@@ -17,27 +17,51 @@ module Tessa
|
|
17
17
|
|
18
18
|
def hidden_fields_for(attribute_name)
|
19
19
|
asset = object.public_send(attribute_name)
|
20
|
-
|
21
|
-
|
20
|
+
if asset&.is_a?(String)
|
21
|
+
# This happens if the controller rejects the change with errors and re-renders the form.
|
22
|
+
# In this case our field value would be the signed upload ID.
|
23
|
+
return hidden_fileds_for_signed_id(attribute_name, asset)
|
22
24
|
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
if asset&.key.present?
|
27
|
+
@builder.hidden_field("#{attribute_name}", {
|
28
|
+
value: asset.key,
|
29
|
+
data: {
|
30
|
+
meta: meta_for_blob(asset).merge({
|
31
|
+
# this allows us to find the hidden HTML input to remove it if we remove the asset
|
32
|
+
"signedID" => blob.key,
|
33
|
+
})
|
34
|
+
}
|
29
35
|
})
|
36
|
+
end
|
37
|
+
|
38
|
+
return @builder.hidden_field("#{attribute_name}", value: nil)
|
39
|
+
end
|
40
|
+
|
41
|
+
def hidden_fileds_for_signed_id(attribute_name, signed_id)
|
42
|
+
if blob = ActiveStorage::Blob.find_signed(signed_id)
|
43
|
+
return @builder.hidden_field("#{attribute_name}", {
|
44
|
+
value: signed_id,
|
45
|
+
data: {
|
46
|
+
meta: meta_for_blob(blob).merge({
|
47
|
+
'signedID' => signed_id
|
48
|
+
})
|
49
|
+
}
|
50
|
+
})
|
51
|
+
end
|
52
|
+
|
53
|
+
# The form post sent some other string which was not a signed ID
|
54
|
+
return @builder.hidden_field("#{attribute_name}", value: nil)
|
30
55
|
end
|
31
56
|
|
32
|
-
|
57
|
+
# These get read by the JS to populate the preview in Dropzone
|
58
|
+
def meta_for_blob(blob)
|
33
59
|
{
|
34
|
-
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
38
|
-
|
39
|
-
"url" => asset.service_url(disposition: :inline, expires_in: 1.hour),
|
40
|
-
}.to_json
|
60
|
+
"name" => blob.filename,
|
61
|
+
"size" => blob.byte_size,
|
62
|
+
"mimeType" => blob.content_type,
|
63
|
+
"url" => blob.service_url(disposition: :inline, expires_in: 1.hour),
|
64
|
+
}.as_json
|
41
65
|
end
|
42
66
|
end
|
43
67
|
end
|
data/lib/tessa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tessa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Powell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|