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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50763df0e819983cb318808758978492f576fd290d9ab91fd334f82039668c32
4
- data.tar.gz: af8d86fb9280f68fb294d3d39d63296e298e705bca29993297bda378ce775898
3
+ metadata.gz: ce6c35b5100e96423e481bdb7cb16685dd12eb13fd2712f0aa6e0018193a75e8
4
+ data.tar.gz: 70a5d3a46439faabb9588ec04655f92092bd94c357ec5b492b56bf1376621d64
5
5
  SHA512:
6
- metadata.gz: 13f66abade2659a4397a4efc27f294c35b757d12ff4fdc37b17f605408a7839f3e05613c1ea38c16d537ea6ee837e8603ceb3ab178091bc580e6a3bc644916b7
7
- data.tar.gz: '0896f29a1c41a9ad26b171899e0de5f94cd3a5c88e6bb6651bdfe00d0c0d69f8a883df478d4518ce9ef1deac57c8cc8487ba635abdbe9f5436b72ff0b4e98915'
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
- - Form validation (required, accept, size limits)
12
- - Persists attachments through validation errors
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
- gem "bard-attachment_field"
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 :avatar %>
26
- <%= form.attachment_field :documents, multiple: true %>
44
+ <%= form.attachment_field :image %>
45
+ <%= form.attachment_field :images, multiple: true %>
27
46
  ```
28
47
 
29
48
  ### Options
30
49
 
31
- - `multiple: true` - Allow multiple file uploads
32
- - `accept: "image/*"` - Restrict file types
33
- - `required: true` - Make field required
34
- - `preview: false` - Disable image previews
35
- - `disabled: true` - Disable the field
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
 
data/Rakefile CHANGED
@@ -16,3 +16,7 @@ task :compile do
16
16
  cp dist/input-attachment.esm.js ../app/assets/javascripts/input-attachment.js
17
17
  BASH
18
18
  end
19
+
20
+ task :restart do
21
+ touch "tmp/restart.txt"
22
+ end