view_partial_form_builder 0.1.3 → 0.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99ab630e8601d66da9873d48a3c1abbb3611df65e8aa57cb165b3397f2d2b085
|
4
|
+
data.tar.gz: d1a221e7ce27c1e3c48b6dad21c9cf5c72c67db3da17cf8d83a072d7691f5211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44950718466b81b4928ffe33060cc7a90cce087702e8d3830d189bd2e5f1ec1b8fd0bdca68845f94ffdda02ec15febe8fa847bc78dc613e00682f28eab7a072c
|
7
|
+
data.tar.gz: 1bae64c4d9601d0a265b442bc9de563c691a2d76753414901aac0db176757bc132ff22ed1e92e890d3415b2cc277d705b4cffe1830fe97c7a846176a59803f1f
|
data/README.md
CHANGED
@@ -293,6 +293,37 @@ arguments from both partials:
|
|
293
293
|
>
|
294
294
|
```
|
295
295
|
|
296
|
+
When constructing fields within a `form_with(model: ...)` block, partials will
|
297
|
+
use the `model:` instance's [`tableize`-d model name][tableize] to resolve
|
298
|
+
partials.
|
299
|
+
|
300
|
+
For example, `posts/form_builder/_text_field.html.erb` will be resolved ahead of
|
301
|
+
`form_builder/_text_field.html.erb`:
|
302
|
+
|
303
|
+
```html+erb
|
304
|
+
<%# app/views/posts/form_builder/_text_field.html.erb %>
|
305
|
+
|
306
|
+
<%= form.text_field(method, class: "post-text #{options.delete(:class)}", **options) %>
|
307
|
+
|
308
|
+
<%# app/views/application/form_builder/_text_field.html.erb %>
|
309
|
+
|
310
|
+
<%= form.text_field(method, class: "text #{options.delete(:class)}", **options) %>
|
311
|
+
```
|
312
|
+
|
313
|
+
The rendered `posts/form_builder/text_field` partial could combine options and
|
314
|
+
arguments from both partials:
|
315
|
+
|
316
|
+
```html
|
317
|
+
<input type="text" class="post-text text">
|
318
|
+
```
|
319
|
+
|
320
|
+
Models declared within modules will be delimited with `/`. For example,
|
321
|
+
`Special::Post` instances would first resolve partials within the
|
322
|
+
`app/views/special/posts/form_builder` directory, before falling back to
|
323
|
+
`app/views/application/form_builder`.
|
324
|
+
|
325
|
+
[tableize]: https://api.rubyonrails.org/classes/String.html#method-i-tableize
|
326
|
+
|
296
327
|
### Configuration
|
297
328
|
|
298
329
|
View partials lookup and resolution will be scoped to the
|
@@ -16,7 +16,7 @@ module ViewPartialFormBuilder
|
|
16
16
|
)
|
17
17
|
@lookup_override = LookupOverride.new(
|
18
18
|
prefixes: @template.lookup_context.prefixes,
|
19
|
-
object_name:
|
19
|
+
object_name: object&.model_name || object_name,
|
20
20
|
view_partial_directory: ViewPartialFormBuilder.view_partial_directory,
|
21
21
|
)
|
22
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ViewPartialFormBuilder
|
2
2
|
class LookupOverride
|
3
3
|
def initialize(prefixes:, object_name:, view_partial_directory:)
|
4
|
-
@object_name = object_name.to_s.
|
4
|
+
@object_name = object_name.to_s.tableize
|
5
5
|
@prefixes = prefixes
|
6
6
|
@view_partial_directory = view_partial_directory
|
7
7
|
end
|