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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 033f87d750a6bb05ca27e653b62c4b0f5abe9a13a30226e0e874173a90091d22
4
- data.tar.gz: b299e641d1c47faf81d70a9f11b74627015b50776a9c16ed26a6012c23a99048
3
+ metadata.gz: a8e21c3d74e92f753a5d6ae6b0e78adf670a512a029b4044c35b82a06f02b6b4
4
+ data.tar.gz: a653d63a20d3433b3c983b5b552d739dd2a75b77bb272f1f066ca06f07122f6b
5
5
  SHA512:
6
- metadata.gz: fa737da8ef768d7091b81fc5175edd746e4ed8eac5c8453157d6d0621920f90f6005a29ae40c98d2ce03e732ac79c5dc83eba8fd90233804d65b14b701599dd4
7
- data.tar.gz: bf534fec4385f7e6ab38e333cfabde983268b6d501a8beea638021b88310a973f3cdef499818eee046e0061d198d158f31221453afd2612e2892c5b614a20800
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. Mount the engine
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
- 3. Ensure you configure your model with ActiveStorage
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
- 4. When rendering your form, use the SimpleForm helper to render the dropzone div:
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
- 5. Configure your ActiveStorage service to accept direct uploads.
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
- unless asset&.key.present?
21
- return @builder.hidden_field("#{attribute_name}")
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
- @builder.hidden_field("#{attribute_name}",
25
- value: asset.key,
26
- data: {
27
- # These get read by the JS to populate the preview in Dropzone
28
- meta: meta_for_asset(asset)
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
- def meta_for_asset(asset)
57
+ # These get read by the JS to populate the preview in Dropzone
58
+ def meta_for_blob(blob)
33
59
  {
34
- # this allows us to find the hidden HTML input to remove it if we remove the asset
35
- "signedID" => asset.key,
36
- "name" => asset.filename,
37
- "size" => asset.byte_size,
38
- "mimeType" => asset.content_type,
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
@@ -1,3 +1,3 @@
1
1
  module Tessa
2
- VERSION = "6.0.0.rc1"
2
+ VERSION = "6.0.0.rc3"
3
3
  end
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.rc1
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-04-17 00:00:00.000000000 Z
12
+ date: 2023-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake