form_props 0.0.5 → 0.0.6

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: 6c4781f03e94d7cdc4b2c3868e6283c8e3c6241e97eb869d957121b665b2deeb
4
- data.tar.gz: c5696aaf2cd138ca74869c228dee0d1f368ed3822c72df389dbfa5d3aaa36103
3
+ metadata.gz: 6f36ab347fd2b8b9d118ac1d4756f18b9934ff03b0016edfdbc61b1fa01d3a61
4
+ data.tar.gz: 823dfb6b47b5fc418e37cde6642ea3dafef38c74149f30b51dc8218647e5ccf9
5
5
  SHA512:
6
- metadata.gz: e51e3147f39f549f35d940d5b1f900213e363c6108e06b190d7d1d6dfa318795092986e87edf3cf26bbffcfa4f89b2be4fe623213acc913530902928614b7691
7
- data.tar.gz: 63047633479d69d86f7bbd219e760e4d28825a2d2a68863266331365ccab6140cf480221ad2192ff96996a7684d5456e62423b60ae88a20f3bc30965e6368783
6
+ metadata.gz: a4b854fba57f47c833142bb229c19447f5e2d19d12e1162c3c718a54c53ead2d4e5aa5cb084c48dee40b70b249aae1613017ec7c3116fbb149e4723075703632
7
+ data.tar.gz: df34fc8fea47afcc3d0e7c1492b7c8ef359bfc5f5c37507f98855e524dd13fac1e9dc81d5c09dbcbec615be3c857affd2e185671cecba4c21768516535b33604
@@ -139,6 +139,7 @@ module FormProps
139
139
 
140
140
  def fields_for_with_nested_attributes(association_name, association, options, block)
141
141
  name = "#{object_name}[#{association_name}_attributes]"
142
+ association_key = "#{association_name.to_s.camelize(:lower)}Attributes"
142
143
  association = convert_to_model(association)
143
144
  json = @template.instance_variable_get(:@__json)
144
145
 
@@ -151,7 +152,7 @@ module FormProps
151
152
  if association.respond_to?(:to_ary)
152
153
  explicit_child_index = options[:child_index]
153
154
 
154
- json.set!("#{association_name}Attributes") do
155
+ json.set!(association_key) do
155
156
  json.array! association do |child|
156
157
  if explicit_child_index
157
158
  options[:child_index] = explicit_child_index.call if explicit_child_index.respond_to?(:call)
@@ -163,7 +164,7 @@ module FormProps
163
164
  end
164
165
  end
165
166
  elsif association
166
- json.set!("#{association_name}Attributes") do
167
+ json.set!(association_key) do
167
168
  fields_for_nested_model(name, association, options, block)
168
169
  end
169
170
  end
@@ -11,13 +11,15 @@ module FormProps
11
11
  options = options.with_indifferent_access
12
12
 
13
13
  @controlled = options.delete(:controlled)
14
+ @key = options.delete(:key)
15
+
14
16
  super(object_name, method_name, template_object, options)
15
17
  end
16
18
 
17
19
  private
18
20
 
19
21
  def sanitized_key
20
- sanitized_method_name.camelize(:lower)
22
+ @key || sanitized_method_name.camelize(:lower)
21
23
  end
22
24
 
23
25
  def add_options(option_tags, options, value = nil)
@@ -6,7 +6,7 @@ module FormProps
6
6
  private
7
7
 
8
8
  def format_date(value)
9
- value&.strftime("%Y-%m-%d")
9
+ value.presence&.strftime("%Y-%m-%d")
10
10
  end
11
11
 
12
12
  def field_type
@@ -22,8 +22,6 @@ module FormProps
22
22
  @options[:value] = @tag_value
23
23
  @options[:checked] = true if input_checked?(@options)
24
24
 
25
- name_for_key = (sanitized_method_name + "_#{sanitized_value(@tag_value)}").camelize(:lower)
26
-
27
25
  body_block = -> {
28
26
  add_default_name_and_id_for_value(@tag_value, @options)
29
27
  input_props(@options)
@@ -32,7 +30,7 @@ module FormProps
32
30
  if flatten
33
31
  body_block.call
34
32
  else
35
- json.set!(name_for_key) do
33
+ json.set!(sanitized_key) do
36
34
  body_block.call
37
35
  end
38
36
  end
@@ -40,6 +38,10 @@ module FormProps
40
38
 
41
39
  private
42
40
 
41
+ def sanitized_key
42
+ @key || (sanitized_method_name + "_#{sanitized_value(@tag_value)}").camelize(:lower)
43
+ end
44
+
43
45
  def checked?(value)
44
46
  value.to_s == @tag_value.to_s
45
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormProps
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_props
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-26 00:00:00.000000000 Z
11
+ date: 2023-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport