bard-attachment_field 0.5.3 → 0.5.4
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 +72 -12
- data/Rakefile +4 -0
- data/app/assets/javascripts/input-attachment.js +245 -234
- data/bard-attachment_field.gemspec +1 -1
- data/input-attachment/bun.lockb +0 -0
- data/input-attachment/package.json +3 -1
- data/input-attachment/src/components/attachment-file/attachment-file.css +0 -1
- data/input-attachment/src/components/attachment-file/attachment-file.tsx +1 -1
- data/lib/bard/attachment_field/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: ce6c35b5100e96423e481bdb7cb16685dd12eb13fd2712f0aa6e0018193a75e8
|
|
4
|
+
data.tar.gz: 70a5d3a46439faabb9588ec04655f92092bd94c357ec5b492b56bf1376621d64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f73d93cd92298b236646d0bbe72d54bccfe8490fe0bc8dc2dc0e46512afaecca53e6fb44ff4ab4ebb6a2343483afc17fba84171d392ff9981bb0e5ebd1ae4e5
|
|
7
|
+
data.tar.gz: 78ecf96abad31aaebf81a9a4d0cc8073a8a565ead77cd6c0406d95bb34b0b05371fb1711db616079969ca437ef6cb72b8039c5fef99f15c15e14e5d6a3af0ae1
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bard Attachment Field
|
|
2
2
|
|
|
3
|
-
An enhanced file upload field for Rails forms, powered by web components. Provides drag-and-drop uploads, image previews, and seamless ActiveStorage integration.
|
|
3
|
+
An enhanced file upload field for Rails forms, powered by web components. Provides drag-and-drop uploads, image/video previews, and seamless ActiveStorage direct upload integration.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -8,31 +8,91 @@ An enhanced file upload field for Rails forms, powered by web components. Provid
|
|
|
8
8
|
- Image and video previews
|
|
9
9
|
- Direct uploads to ActiveStorage
|
|
10
10
|
- Multiple file support
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- Client-side validation (required, accepted types, max size)
|
|
12
|
+
- Upload progress dialog
|
|
13
|
+
- Persists attachments through server-side validation errors
|
|
14
|
+
- Supports Rails 7.1, 7.2, 8.0, and 8.1
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
16
18
|
Add to your Gemfile:
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
```ruby
|
|
21
|
+
gem "bard-attachment_field"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The engine ships a prebuilt `input-attachment.js` bundle and adds it to the Sprockets precompile list automatically. Load it as a module script in your layout:
|
|
25
|
+
|
|
26
|
+
```erb
|
|
27
|
+
<script type="module" src="<%= asset_path("input-attachment.js") %>"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The model must declare an ActiveStorage attachment:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
class Post < ApplicationRecord
|
|
34
|
+
has_one_attached :image
|
|
35
|
+
has_many_attached :images
|
|
36
|
+
end
|
|
37
|
+
```
|
|
19
38
|
|
|
20
39
|
## Usage
|
|
21
40
|
|
|
22
|
-
In your form
|
|
41
|
+
In your form, use `attachment_field` just like any other form builder field. It automatically sets the form's encoding to `multipart`:
|
|
23
42
|
|
|
24
43
|
```erb
|
|
25
|
-
<%= form.attachment_field :
|
|
26
|
-
<%= form.attachment_field :
|
|
44
|
+
<%= form.attachment_field :image %>
|
|
45
|
+
<%= form.attachment_field :images, multiple: true %>
|
|
27
46
|
```
|
|
28
47
|
|
|
29
48
|
### Options
|
|
30
49
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
| Option | Description |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `multiple: true` | Allow multiple files (use with `has_many_attached`). |
|
|
53
|
+
| `accepts: "image"` | Restrict accepted file types. Comma-separated list of type prefixes, e.g. `"image,video"`. |
|
|
54
|
+
| `max: 5.megabytes` | Maximum file size. |
|
|
55
|
+
| `required: true` | Require at least one file. |
|
|
56
|
+
| `preview: false` | Disable image/video previews. |
|
|
57
|
+
| `disabled: true` | Disable the field. |
|
|
58
|
+
| `upload_dialog: false` | Disable the upload progress dialog shown during direct uploads. |
|
|
59
|
+
| `directupload: "/path"` | Override the ActiveStorage direct upload URL (defaults to `/rails/active_storage/direct_uploads`). |
|
|
60
|
+
|
|
61
|
+
```erb
|
|
62
|
+
<%= form.attachment_field :image, accepts: "image", max: 5.megabytes, required: true %>
|
|
63
|
+
<%= form.attachment_field :media, accepts: "image,video", multiple: true %>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Custom rendering
|
|
67
|
+
|
|
68
|
+
Pass a block to render your own children inside the `<input-attachment>` element instead of the default persisted-attachment markup. The block receives the resolved HTML options:
|
|
69
|
+
|
|
70
|
+
```erb
|
|
71
|
+
<%= form.attachment_field :image do |options| %>
|
|
72
|
+
<!-- custom <attachment-file> markup -->
|
|
73
|
+
<% end %>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
This project has two parts: the Ruby gem and the Stencil web components in `input-attachment/`.
|
|
79
|
+
|
|
80
|
+
The web components use [Bun](https://bun.sh):
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
cd input-attachment
|
|
84
|
+
bun install
|
|
85
|
+
bun run build # builds app/assets/javascripts/input-attachment.js
|
|
86
|
+
bun run test # JS component tests
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The JavaScript bundle must be built before running the Ruby test suite, which is driven by Cucumber against a self-contained Rails app:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
bundle exec cucumber features/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Multi-Rails testing uses [Appraisal](https://github.com/thoughtbot/appraisal) with the gemfiles in `gemfiles/`.
|
|
36
96
|
|
|
37
97
|
## License
|
|
38
98
|
|