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: 2bad5344dd2dcb3ff6332ccce094cafee462d8dad93253e40002d90869908c7d
4
- data.tar.gz: 75733a62d1ec0c8266e2577380a70d7459942a4b908ae17e5d98b25cdb6bfb0f
3
+ metadata.gz: 99ab630e8601d66da9873d48a3c1abbb3611df65e8aa57cb165b3397f2d2b085
4
+ data.tar.gz: d1a221e7ce27c1e3c48b6dad21c9cf5c72c67db3da17cf8d83a072d7691f5211
5
5
  SHA512:
6
- metadata.gz: f847a1f3ceb8b4c390e94575fd6aeb0b37bf93daf49804c4fbc125b476f896250b14a80cb522c76ce32e33e31457f30cb222f28b978851f58ccaa68f19aa76ed
7
- data.tar.gz: 682356c76cf59d62ad176adc0166e6e1ec4c8102b89d3214567cd2abea2721f5d6fdb70259f53b55aed6a955adcbf7f7c48275a37159fdb545caad23275df6cb
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: @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.pluralize
4
+ @object_name = object_name.to_s.tableize
5
5
  @prefixes = prefixes
6
6
  @view_partial_directory = view_partial_directory
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module ViewPartialFormBuilder
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_partial_form_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Doyle