formatic 0.6.1 → 0.7.1
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/CHANGELOG.md +10 -0
- data/README.md +14 -0
- data/app/components/formatic/file.rb +1 -1
- data/app/components/formatic/search/frontend.rb +24 -7
- data/app/components/formatic/search/selected.rb +2 -2
- data/app/components/formatic/search.rb +1 -1
- data/lib/formatic/templates/search.rb +3 -2
- data/lib/formatic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9eb8cde2cea564e9f1a532de1b6ad245ce0145b97bc7a9ddbc18d58eb2baf578
|
|
4
|
+
data.tar.gz: 8853a92749378d295b46a002ddae644b97d2dcbeb1d1309243bc4fd0f897e759
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c8a99303b72910952d07517e9b6a0be2d930752364c1288be06f77b65a7a8044da19a74228acb0193f6326f6c303ffb34d643255b8c3b97021e9c56048a04db
|
|
7
|
+
data.tar.gz: 3e48b8ab3115e0a5a17964c4aa3be8e5a09af484f4818212811466d382de296ef4bae759f1029b7c487870aa60fdb35c20a4289930bf42ff2baed49dfadade36
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [0.7.1] - 2026-10-27
|
|
2
|
+
|
|
3
|
+
- Fix malformed `Formatic::File` wrapper markup so Rails 8.2's Herb handler can compile it.
|
|
4
|
+
|
|
5
|
+
## [0.7.0] - 2026-10-27
|
|
6
|
+
|
|
7
|
+
- Add an instance-based `Formatic::Search::Frontend` with `as_json` and `to_json`.
|
|
8
|
+
- Pass the frontend object to `Formatic::Search` to render selected records.
|
|
9
|
+
- Remove the class-level `.json` helper and the `with_selected_record` slot.
|
|
10
|
+
|
|
1
11
|
## [0.6.1] 2026-10-26
|
|
2
12
|
|
|
3
13
|
- Proper i18n for Formatic::Search placeholders
|
data/README.md
CHANGED
|
@@ -38,6 +38,20 @@ For Rack tests, call `Formatic::Testing::Search.call(page:, query: 'Bob', from:
|
|
|
38
38
|
It reads the field's URL and parameter names, requests matching JSON directly, and
|
|
39
39
|
fills the hidden input with a result returned by that endpoint.
|
|
40
40
|
|
|
41
|
+
Use `Formatic::Search::Frontend` to represent a result for both the JSON response
|
|
42
|
+
and a selected search field. Its `as_json` and `to_json` methods return the wrapped
|
|
43
|
+
`id`, `choice`, and `selected` record. Pass the object to
|
|
44
|
+
`Formatic::Search` to render its selected markup, including the usual clear control:
|
|
45
|
+
the app supplies the rendered record fragments, and Formatic adds the search wrappers.
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
frontend = Formatic::Search::Frontend.new(id: commander.id,
|
|
49
|
+
choice_html:,
|
|
50
|
+
selected_html:)
|
|
51
|
+
render Formatic::Search.new(f:, attribute_name: :commander_id,
|
|
52
|
+
url: admin_commanders_path(format: :json), frontend:)
|
|
53
|
+
```
|
|
54
|
+
|
|
41
55
|
Capybara RackTest test classes can include the `search` helper instead:
|
|
42
56
|
|
|
43
57
|
```ruby
|
|
@@ -2,20 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
module Formatic
|
|
4
4
|
class Search
|
|
5
|
-
#
|
|
5
|
+
# Represents one search result for JSON responses and selected search fields.
|
|
6
6
|
class Frontend
|
|
7
|
-
|
|
7
|
+
attr_reader :id, :choice_html, :selected_html
|
|
8
|
+
|
|
9
|
+
def initialize(id:, choice_html:, selected_html:)
|
|
10
|
+
@id = id
|
|
11
|
+
@choice_html = choice_html
|
|
12
|
+
@selected_html = selected_html
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def as_json(_options = nil)
|
|
8
16
|
{
|
|
9
|
-
id
|
|
10
|
-
choice: render_html(
|
|
11
|
-
selected: render_html(::Formatic::Search::Selected.new.with_content(
|
|
17
|
+
id:,
|
|
18
|
+
choice: render_html(choice_component),
|
|
19
|
+
selected: render_html(::Formatic::Search::Selected.new.with_content(selected_html))
|
|
12
20
|
}
|
|
13
21
|
end
|
|
14
22
|
|
|
15
|
-
def
|
|
23
|
+
def to_json(options = nil)
|
|
24
|
+
as_json.to_json(options)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def choice_component
|
|
30
|
+
::Formatic::Search::Choice.new(record_id: id).with_content(choice_html)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def render_html(component)
|
|
16
34
|
ApplicationController.render(component)
|
|
17
35
|
end
|
|
18
|
-
private_class_method :render_html
|
|
19
36
|
end
|
|
20
37
|
end
|
|
21
38
|
end
|
|
@@ -4,12 +4,12 @@ module Formatic
|
|
|
4
4
|
class Search
|
|
5
5
|
# The record that is currently chosen.
|
|
6
6
|
class Selected < ::Formatic::ApplicationComponent
|
|
7
|
-
option :
|
|
7
|
+
option :clearable, default: -> { true }
|
|
8
8
|
|
|
9
9
|
erb_template <<~ERB
|
|
10
10
|
<div class="c-formatic-search__selection">
|
|
11
11
|
<div class="c-formatic-search__selected-record"><%= content %></div>
|
|
12
|
-
<%
|
|
12
|
+
<% if clearable %>
|
|
13
13
|
<div class="c-formatic-search__actions"><%= render ::Formatic::Search::Clear.new %></div>
|
|
14
14
|
<% end %>
|
|
15
15
|
</div>
|
|
@@ -8,10 +8,10 @@ module Formatic
|
|
|
8
8
|
option :url
|
|
9
9
|
option :record_name, as: :manual_record_name, optional: true
|
|
10
10
|
option :exclude_ids, default: -> { [] }
|
|
11
|
+
option :frontend, optional: true
|
|
11
12
|
option :placeholder, as: :manual_placeholder, optional: true
|
|
12
13
|
option :prevent_submit_on_enter, default: -> { true }
|
|
13
14
|
|
|
14
|
-
renders_one :selected_record
|
|
15
15
|
renders_one :add_record
|
|
16
16
|
|
|
17
17
|
erb_template(::Formatic::Templates::Search.call)
|
|
@@ -19,8 +19,9 @@ module Formatic
|
|
|
19
19
|
class: 'js-formatic-search__value' %>
|
|
20
20
|
|
|
21
21
|
<div class="c-formatic-search__selected js-formatic-search__selected">
|
|
22
|
-
<% if
|
|
23
|
-
<%= render ::Formatic::Search::Selected.new(
|
|
22
|
+
<% if frontend %>
|
|
23
|
+
<%= render ::Formatic::Search::Selected.new(clearable: !readonly)
|
|
24
|
+
.with_content(frontend.selected_html) %>
|
|
24
25
|
<% end %>
|
|
25
26
|
</div>
|
|
26
27
|
|
data/lib/formatic/version.rb
CHANGED