bard-tag_field 0.4.1 → 0.5.0
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/Appraisals +5 -1
- data/CLAUDE.md +109 -0
- data/README.md +16 -16
- data/Rakefile +3 -3
- data/app/assets/javascripts/input-tag.js +482 -465
- data/gemfiles/rails_8.1.gemfile +7 -0
- data/input-tag/bun.lockb +0 -0
- data/input-tag/package.json +16 -0
- data/lib/bard/tag_field/form_builder.rb +4 -4
- data/lib/bard/tag_field/version.rb +1 -1
- metadata +9 -7
- data/bard-tag/bun.lockb +0 -0
- data/bard-tag/package.json +0 -15
- /data/{bard-tag → input-tag}/.gitignore +0 -0
- /data/{bard-tag → input-tag}/index.js +0 -0
- /data/{bard-tag → input-tag}/rollup.config.js +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 41638b348c696d0f3f95ae6c6c485c53d83c24df043c705cbfb52045410eee6f
|
|
4
|
+
data.tar.gz: 581a77505a56ee7c545ec14f1fb856a99af95346f02af98ddddb4703fbbbcf3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c7056e3b6f96f40a4f4b704e10b626012e5d6df73b8c6f91e189e9238bf3a69260f768e2bbe2cdcde18b9a9c493f036e3e6b5b9b999be35e098ab617308e8681
|
|
7
|
+
data.tar.gz: ea50ae8634d86c7f796fbf636475dd6805e4446abdb0b486ad2b4e63b5d8c20b63d0fc1db76e6fed23f2c48a75733aa18ddc62ded5698676929e5d799b4db75b
|
data/Appraisals
CHANGED
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is a Rails form helper gem that provides `tag_field` for creating interactive tag input fields. The gem wraps the [@botandrose/input-tag](https://github.com/botandrose/input-tag) custom element and integrates it with Rails form builders.
|
|
8
|
+
|
|
9
|
+
**Key Architecture:**
|
|
10
|
+
- `lib/bard/tag_field/form_builder.rb` - Rails form builder integration that handles method signature variants (like Rails' `select` helper)
|
|
11
|
+
- `lib/bard/tag_field/field.rb` - Core field rendering logic, extends `ActionView::Helpers::Tags::TextField`
|
|
12
|
+
- `lib/bard/tag_field.rb` - Rails Engine that auto-registers the form builder and precompiles JavaScript assets
|
|
13
|
+
- `input-tag/` - JavaScript build directory using Rollup to bundle the `@botandrose/input-tag` package with Bun
|
|
14
|
+
- `app/assets/javascripts/input-tag.js` - Compiled JavaScript output for Rails asset pipeline
|
|
15
|
+
|
|
16
|
+
## Development Commands
|
|
17
|
+
|
|
18
|
+
### Testing
|
|
19
|
+
```bash
|
|
20
|
+
# Run all tests
|
|
21
|
+
bundle exec rspec
|
|
22
|
+
|
|
23
|
+
# Run tests for specific Rails version
|
|
24
|
+
bundle exec appraisal rails-7.1 rspec
|
|
25
|
+
bundle exec appraisal rails-7.2 rspec
|
|
26
|
+
bundle exec appraisal rails-8.0 rspec
|
|
27
|
+
|
|
28
|
+
# Generate appraisal gemfiles after updating Appraisals
|
|
29
|
+
bundle exec appraisal install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### JavaScript Assets
|
|
33
|
+
```bash
|
|
34
|
+
# Build JavaScript assets (required before running tests or releasing)
|
|
35
|
+
cd input-tag && bun run build
|
|
36
|
+
|
|
37
|
+
# Install Bun dependencies
|
|
38
|
+
cd input-tag && bun install
|
|
39
|
+
|
|
40
|
+
# Clean compiled assets
|
|
41
|
+
cd input-tag && bun run clean
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Gem Management
|
|
45
|
+
```bash
|
|
46
|
+
# Install the gem locally for testing
|
|
47
|
+
bundle exec rake install
|
|
48
|
+
|
|
49
|
+
# Build gem package
|
|
50
|
+
bundle exec rake build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Form Builder Method Signatures
|
|
54
|
+
|
|
55
|
+
The `tag_field` method supports multiple signatures to match Rails conventions:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
# Basic usage
|
|
59
|
+
form.tag_field :tags
|
|
60
|
+
|
|
61
|
+
# With HTML options only
|
|
62
|
+
form.tag_field :tags, class: "form-control"
|
|
63
|
+
|
|
64
|
+
# With choices (like form.select)
|
|
65
|
+
form.tag_field :tags, ["ruby", "rails", "javascript"]
|
|
66
|
+
|
|
67
|
+
# With choices and HTML options
|
|
68
|
+
form.tag_field :tags, ["ruby", "rails"], {}, { class: "form-control" }
|
|
69
|
+
|
|
70
|
+
# With nested choices [display, value]
|
|
71
|
+
form.tag_field :categories, [["Web Dev", "web"], ["ML", "ml"]]
|
|
72
|
+
|
|
73
|
+
# With block for custom rendering
|
|
74
|
+
form.tag_field :tags do |options|
|
|
75
|
+
# Custom tag-option rendering
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The FormBuilder handles signature detection in lib/bard/tag_field/form_builder.rb:6-21.
|
|
80
|
+
|
|
81
|
+
## Rendering Logic
|
|
82
|
+
|
|
83
|
+
The Field class (lib/bard/tag_field/field.rb) handles three rendering scenarios:
|
|
84
|
+
|
|
85
|
+
1. **Object values only** - Renders current object's tags as `<tag-option>` elements
|
|
86
|
+
2. **With choices** - Renders object values as `<tag-option>` and choices in a nested `<datalist>`
|
|
87
|
+
3. **With block** - Delegates content rendering to the provided block
|
|
88
|
+
|
|
89
|
+
The `build_choice_map` method (lib/bard/tag_field/field.rb:58-74) maps choice values to display labels for proper tag rendering.
|
|
90
|
+
|
|
91
|
+
## Testing
|
|
92
|
+
|
|
93
|
+
Tests use RSpec with a custom HTML matcher that supports wildcards (`...`) for flexible HTML comparison. The matcher is defined in spec/spec_helper.rb:55-152 and allows testing HTML structure without exact whitespace or attribute order matching.
|
|
94
|
+
|
|
95
|
+
Test setup includes a mock Rails application (TestApp) initialized in spec/spec_helper.rb:12-17.
|
|
96
|
+
|
|
97
|
+
## JavaScript Build Process
|
|
98
|
+
|
|
99
|
+
The gem bundles the `@botandrose/input-tag` package using Rollup with Bun:
|
|
100
|
+
1. Source: `input-tag/index.js` imports from `@botandrose/input-tag`
|
|
101
|
+
2. Build: `cd input-tag && bun run build` runs Rollup
|
|
102
|
+
3. Output: `app/assets/javascripts/input-tag.js` for Rails asset pipeline
|
|
103
|
+
4. The Engine precompiles this asset (lib/bard/tag_field.rb:11)
|
|
104
|
+
|
|
105
|
+
**Important:** Always rebuild JavaScript assets after updating the `@botandrose/input-tag` dependency.
|
|
106
|
+
|
|
107
|
+
## Multi-Rails Version Support
|
|
108
|
+
|
|
109
|
+
Uses Appraisal gem to test against Rails 7.1, 7.2, and 8.0. Gemfiles are in `gemfiles/` directory. CI tests all combinations of Ruby 3.2/3.3/3.4 with each Rails version.
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.ruby-lang.org)
|
|
5
5
|
[](https://rubyonrails.org)
|
|
6
6
|
|
|
7
|
-
A Rails form helper gem that adds `
|
|
7
|
+
A Rails form helper gem that adds `tag_field` to your forms, creating interactive tag input fields using the [@botandrose/input-tag](https://github.com/botandrose/input-tag) custom element.
|
|
8
8
|
|
|
9
9
|
Perfect for adding tag functionality to your Rails forms with a clean, modern interface that works seamlessly with your existing Rails form helpers.
|
|
10
10
|
|
|
@@ -22,11 +22,11 @@ Perfect for adding tag functionality to your Rails forms with a clean, modern in
|
|
|
22
22
|
|
|
23
23
|
### Basic Usage
|
|
24
24
|
|
|
25
|
-
After installing and requiring the gem, Use `
|
|
25
|
+
After installing and requiring the gem, Use `tag_field` in your Rails forms just like any other form helper:
|
|
26
26
|
|
|
27
27
|
```erb
|
|
28
28
|
<%= form_with model: @post do |form| %>
|
|
29
|
-
<%= form.
|
|
29
|
+
<%= form.tag_field :tags %>
|
|
30
30
|
<% end %>
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ This generates an interactive tag field that binds to your model's `tags` attrib
|
|
|
37
37
|
Add CSS classes, data attributes, and other HTML options:
|
|
38
38
|
|
|
39
39
|
```erb
|
|
40
|
-
<%= form.
|
|
40
|
+
<%= form.tag_field :tags,
|
|
41
41
|
class: "form-control",
|
|
42
42
|
id: "post-tags",
|
|
43
43
|
data: { placeholder: "Add tags..." } %>
|
|
@@ -54,7 +54,7 @@ The field automatically displays existing tags from your model:
|
|
|
54
54
|
|
|
55
55
|
```erb
|
|
56
56
|
<!-- Tags will be pre-populated in the form -->
|
|
57
|
-
<%= form.
|
|
57
|
+
<%= form.tag_field :tags %>
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
### With Predefined Choices (Rails select-style)
|
|
@@ -62,13 +62,13 @@ The field automatically displays existing tags from your model:
|
|
|
62
62
|
Like `form.select`, you can provide predefined choices for users to select from:
|
|
63
63
|
|
|
64
64
|
```erb
|
|
65
|
-
<%= form.
|
|
65
|
+
<%= form.tag_field :tags, ["ruby", "rails", "javascript", "css"] %>
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
Or use nested arrays for display vs submit values:
|
|
69
69
|
|
|
70
70
|
```erb
|
|
71
|
-
<%= form.
|
|
71
|
+
<%= form.tag_field :categories, [
|
|
72
72
|
["Web Development", "web-dev"],
|
|
73
73
|
["Machine Learning", "ml"],
|
|
74
74
|
["Database Design", "db"]
|
|
@@ -82,7 +82,7 @@ This creates a datalist with available options while still showing current objec
|
|
|
82
82
|
Use blocks for custom tag rendering:
|
|
83
83
|
|
|
84
84
|
```erb
|
|
85
|
-
<%= form.
|
|
85
|
+
<%= form.tag_field :tags do |options| %>
|
|
86
86
|
<% @post.tags.each do |tag| %>
|
|
87
87
|
<tag-option value="<%= tag %>" class="custom-tag"><%= tag %></tag-option>
|
|
88
88
|
<% end %>
|
|
@@ -128,7 +128,7 @@ end
|
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
```erb
|
|
131
|
-
<%= form.
|
|
131
|
+
<%= form.tag_field :tags_array %>
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
## Generated HTML
|
|
@@ -155,7 +155,7 @@ The gem generates semantic HTML using custom elements:
|
|
|
155
155
|
|
|
156
156
|
## JavaScript Integration
|
|
157
157
|
|
|
158
|
-
This gem works with the [@botandrose/input-tag](https://github.com/botandrose/input-tag) custom element.
|
|
158
|
+
This gem works with the [@botandrose/input-tag](https://github.com/botandrose/input-tag) custom element.
|
|
159
159
|
|
|
160
160
|
```javascript
|
|
161
161
|
// In your application.js or wherever you manage JS
|
|
@@ -176,7 +176,7 @@ Or include the precompiled asset (automatically added by this gem):
|
|
|
176
176
|
|
|
177
177
|
## API Reference
|
|
178
178
|
|
|
179
|
-
### `
|
|
179
|
+
### `tag_field(method, choices = nil, options = {}, html_options = {}, &block)`
|
|
180
180
|
|
|
181
181
|
**Parameters:**
|
|
182
182
|
- `method` - The attribute name (symbol)
|
|
@@ -190,19 +190,19 @@ Or include the precompiled asset (automatically added by this gem):
|
|
|
190
190
|
**Examples:**
|
|
191
191
|
```ruby
|
|
192
192
|
# Basic usage
|
|
193
|
-
form.
|
|
193
|
+
form.tag_field :tags
|
|
194
194
|
|
|
195
195
|
# With choices
|
|
196
|
-
form.
|
|
196
|
+
form.tag_field :tags, ["ruby", "rails", "javascript"]
|
|
197
197
|
|
|
198
198
|
# With nested choices (display vs value)
|
|
199
|
-
form.
|
|
199
|
+
form.tag_field :categories, [["Web Dev", "web"], ["ML", "ml"]]
|
|
200
200
|
|
|
201
201
|
# With HTML options
|
|
202
|
-
form.
|
|
202
|
+
form.tag_field :tags, class: "form-control", data: { max_tags: 5 }
|
|
203
203
|
|
|
204
204
|
# With choices and HTML options
|
|
205
|
-
form.
|
|
205
|
+
form.tag_field :tags, ["ruby", "rails"], {}, { class: "form-control" }
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
## Development
|
data/Rakefile
CHANGED
|
@@ -9,10 +9,10 @@ task default: :spec
|
|
|
9
9
|
|
|
10
10
|
desc "Build JavaScript assets"
|
|
11
11
|
task :build_js do
|
|
12
|
-
sh "cd
|
|
12
|
+
sh "cd input-tag && bun run build"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
desc "Install
|
|
15
|
+
desc "Install Bun dependencies"
|
|
16
16
|
task :install_deps do
|
|
17
|
-
sh "cd
|
|
17
|
+
sh "cd input-tag && bun install"
|
|
18
18
|
end
|