form_props 0.0.4 → 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: e3200a705c61ab6b0ebae4316cb80874b53ee0be1297e1230632e8b4568d7054
4
- data.tar.gz: e0f83bff9ce077fee68002cedc1a0906d4139aff509fe514c73a4e085c82a386
3
+ metadata.gz: 6f36ab347fd2b8b9d118ac1d4756f18b9934ff03b0016edfdbc61b1fa01d3a61
4
+ data.tar.gz: 823dfb6b47b5fc418e37cde6642ea3dafef38c74149f30b51dc8218647e5ccf9
5
5
  SHA512:
6
- metadata.gz: 6054204836874c8cebb5fa3f9cfd6f84fb3cb5c96f27ac9945683dc5e2aac73fe4be3a652dd64d3cfab33bfc70703fb2283fcf553d1908eaba46a0b4c10a8c7c
7
- data.tar.gz: d586f6ebb862c1e75fe55056cdf7138dc72db2a0e3f2c847563524d2889d44b5afb16dc4135681b7524e80c4d2081ae08719fdd46951e3a14631fa73fa84a504
6
+ metadata.gz: a4b854fba57f47c833142bb229c19447f5e2d19d12e1162c3c718a54c53ead2d4e5aa5cb084c48dee40b70b249aae1613017ec7c3116fbb149e4723075703632
7
+ data.tar.gz: df34fc8fea47afcc3d0e7c1492b7c8ef359bfc5f5c37507f98855e524dd13fac1e9dc81d5c09dbcbec615be3c857affd2e185671cecba4c21768516535b33604
@@ -40,12 +40,12 @@ module FormProps
40
40
  end
41
41
 
42
42
  html_options = html_options_for_form_with(url, model, **options)
43
- html_options["acceptCharset"] ||= html_options.delete("accept-charset")
44
43
 
45
44
  json.extras do
46
45
  extra_props_for_form(json, html_options)
47
46
  end
48
- json.props(html_options)
47
+
48
+ json.props(FormProps::Helper.format_keys(html_options))
49
49
  end
50
50
 
51
51
  private
@@ -62,8 +62,8 @@ module FormProps
62
62
  json.set!("csrf") do
63
63
  json.name request_forgery_protection_token.to_s
64
64
  json.type "hidden"
65
- json.default_value token
66
- json.auto_complete "off"
65
+ json.defaultValue token
66
+ json.autoComplete "off"
67
67
  end
68
68
  end
69
69
  end
@@ -72,8 +72,8 @@ module FormProps
72
72
  json.set!("method") do
73
73
  json.name "_method"
74
74
  json.type "hidden"
75
- json.default_value method.to_s
76
- json.auto_complete "off"
75
+ json.defaultValue method.to_s
76
+ json.autoComplete "off"
77
77
  end
78
78
  end
79
79
 
@@ -81,8 +81,8 @@ module FormProps
81
81
  json.set!("utf8") do
82
82
  json.name "utf8"
83
83
  json.type "hidden"
84
- json.default_value "✓"
85
- json.auto_complete "off"
84
+ json.defaultValue "✓"
85
+ json.autoComplete "off"
86
86
  end
87
87
  end
88
88
 
@@ -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
@@ -0,0 +1,534 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Keep up to date with
4
+ # https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/shared/possibleStandardNames.js
5
+ module FormProps
6
+ POSSIBLE_STANDARD_NAMES = {
7
+ ## HTML
8
+ accept: "accept",
9
+ acceptcharset: "acceptCharset",
10
+ "accept-charset": "acceptCharset",
11
+ accesskey: "accessKey",
12
+ action: "action",
13
+ allowfullscreen: "allowFullScreen",
14
+ alt: "alt",
15
+ as: "as",
16
+ async: "async",
17
+ autocapitalize: "autoCapitalize",
18
+ autocomplete: "autoComplete",
19
+ autocorrect: "autoCorrect",
20
+ autofocus: "autoFocus",
21
+ autoplay: "autoPlay",
22
+ autosave: "autoSave",
23
+ capture: "capture",
24
+ cellpadding: "cellPadding",
25
+ cellspacing: "cellSpacing",
26
+ challenge: "challenge",
27
+ charset: "charSet",
28
+ checked: "checked",
29
+ children: "children",
30
+ cite: "cite",
31
+ class: "className",
32
+ classid: "classID",
33
+ classname: "className",
34
+ cols: "cols",
35
+ colspan: "colSpan",
36
+ content: "content",
37
+ contenteditable: "contentEditable",
38
+ contextmenu: "contextMenu",
39
+ controls: "controls",
40
+ controlslist: "controlsList",
41
+ coords: "coords",
42
+ crossorigin: "crossOrigin",
43
+ dangerouslysetinnerhtml: "dangerouslySetInnerHTML",
44
+ data: "data",
45
+ datetime: "dateTime",
46
+ default: "default",
47
+ defaultchecked: "defaultChecked",
48
+ defaultvalue: "defaultValue",
49
+ defer: "defer",
50
+ dir: "dir",
51
+ disabled: "disabled",
52
+ disablepictureinpicture: "disablePictureInPicture",
53
+ disableremoteplayback: "disableRemotePlayback",
54
+ download: "download",
55
+ draggable: "draggable",
56
+ enctype: "encType",
57
+ enterkeyhint: "enterKeyHint",
58
+ fetchpriority: "fetchPriority",
59
+ for: "htmlFor",
60
+ form: "form",
61
+ formmethod: "formMethod",
62
+ formaction: "formAction",
63
+ formenctype: "formEncType",
64
+ formnovalidate: "formNoValidate",
65
+ formtarget: "formTarget",
66
+ frameborder: "frameBorder",
67
+ headers: "headers",
68
+ height: "height",
69
+ hidden: "hidden",
70
+ high: "high",
71
+ href: "href",
72
+ hreflang: "hrefLang",
73
+ htmlfor: "htmlFor",
74
+ httpequiv: "httpEquiv",
75
+ "http-equiv": "httpEquiv",
76
+ icon: "icon",
77
+ id: "id",
78
+ imagesizes: "imageSizes",
79
+ imagesrcset: "imageSrcSet",
80
+ innerhtml: "innerHTML",
81
+ inputmode: "inputMode",
82
+ integrity: "integrity",
83
+ is: "is",
84
+ itemid: "itemID",
85
+ itemprop: "itemProp",
86
+ itemref: "itemRef",
87
+ itemscope: "itemScope",
88
+ itemtype: "itemType",
89
+ keyparams: "keyParams",
90
+ keytype: "keyType",
91
+ kind: "kind",
92
+ label: "label",
93
+ lang: "lang",
94
+ list: "list",
95
+ loop: "loop",
96
+ low: "low",
97
+ manifest: "manifest",
98
+ marginwidth: "marginWidth",
99
+ marginheight: "marginHeight",
100
+ max: "max",
101
+ maxlength: "maxLength",
102
+ media: "media",
103
+ mediagroup: "mediaGroup",
104
+ method: "method",
105
+ min: "min",
106
+ minlength: "minLength",
107
+ multiple: "multiple",
108
+ muted: "muted",
109
+ name: "name",
110
+ nomodule: "noModule",
111
+ nonce: "nonce",
112
+ novalidate: "noValidate",
113
+ open: "open",
114
+ optimum: "optimum",
115
+ pattern: "pattern",
116
+ placeholder: "placeholder",
117
+ playsinline: "playsInline",
118
+ poster: "poster",
119
+ preload: "preload",
120
+ profile: "profile",
121
+ radiogroup: "radioGroup",
122
+ readonly: "readOnly",
123
+ referrerpolicy: "referrerPolicy",
124
+ rel: "rel",
125
+ required: "required",
126
+ reversed: "reversed",
127
+ role: "role",
128
+ rows: "rows",
129
+ rowspan: "rowSpan",
130
+ sandbox: "sandbox",
131
+ scope: "scope",
132
+ scoped: "scoped",
133
+ scrolling: "scrolling",
134
+ seamless: "seamless",
135
+ selected: "selected",
136
+ shape: "shape",
137
+ size: "size",
138
+ sizes: "sizes",
139
+ span: "span",
140
+ spellcheck: "spellCheck",
141
+ src: "src",
142
+ srcdoc: "srcDoc",
143
+ srclang: "srcLang",
144
+ srcset: "srcSet",
145
+ start: "start",
146
+ step: "step",
147
+ style: "style",
148
+ summary: "summary",
149
+ tabindex: "tabIndex",
150
+ target: "target",
151
+ title: "title",
152
+ type: "type",
153
+ usemap: "useMap",
154
+ value: "value",
155
+ width: "width",
156
+ wmode: "wmode",
157
+ wrap: "wrap",
158
+
159
+ # SVG
160
+ about: "about",
161
+ accentheight: "accentHeight",
162
+ "accent-height": "accentHeight",
163
+ accumulate: "accumulate",
164
+ additive: "additive",
165
+ alignmentbaseline: "alignmentBaseline",
166
+ "alignment-baseline": "alignmentBaseline",
167
+ allowreorder: "allowReorder",
168
+ alphabetic: "alphabetic",
169
+ amplitude: "amplitude",
170
+ arabicform: "arabicForm",
171
+ "arabic-form": "arabicForm",
172
+ ascent: "ascent",
173
+ attributename: "attributeName",
174
+ attributetype: "attributeType",
175
+ autoreverse: "autoReverse",
176
+ azimuth: "azimuth",
177
+ basefrequency: "baseFrequency",
178
+ baselineshift: "baselineShift",
179
+ "baseline-shift": "baselineShift",
180
+ baseprofile: "baseProfile",
181
+ bbox: "bbox",
182
+ begin: "begin",
183
+ bias: "bias",
184
+ by: "by",
185
+ calcmode: "calcMode",
186
+ capheight: "capHeight",
187
+ "cap-height": "capHeight",
188
+ clip: "clip",
189
+ clippath: "clipPath",
190
+ "clip-path": "clipPath",
191
+ clippathunits: "clipPathUnits",
192
+ cliprule: "clipRule",
193
+ "clip-rule": "clipRule",
194
+ color: "color",
195
+ colorinterpolation: "colorInterpolation",
196
+ "color-interpolation": "colorInterpolation",
197
+ colorinterpolationfilters: "colorInterpolationFilters",
198
+ "color-interpolation-filters": "colorInterpolationFilters",
199
+ colorprofile: "colorProfile",
200
+ "color-profile": "colorProfile",
201
+ colorrendering: "colorRendering",
202
+ "color-rendering": "colorRendering",
203
+ contentscripttype: "contentScriptType",
204
+ contentstyletype: "contentStyleType",
205
+ cursor: "cursor",
206
+ cx: "cx",
207
+ cy: "cy",
208
+ d: "d",
209
+ datatype: "datatype",
210
+ decelerate: "decelerate",
211
+ descent: "descent",
212
+ diffuseconstant: "diffuseConstant",
213
+ direction: "direction",
214
+ display: "display",
215
+ divisor: "divisor",
216
+ dominantbaseline: "dominantBaseline",
217
+ "dominant-baseline": "dominantBaseline",
218
+ dur: "dur",
219
+ dx: "dx",
220
+ dy: "dy",
221
+ edgemode: "edgeMode",
222
+ elevation: "elevation",
223
+ enablebackground: "enableBackground",
224
+ "enable-background": "enableBackground",
225
+ end: "end",
226
+ exponent: "exponent",
227
+ externalresourcesrequired: "externalResourcesRequired",
228
+ fill: "fill",
229
+ fillopacity: "fillOpacity",
230
+ "fill-opacity": "fillOpacity",
231
+ fillrule: "fillRule",
232
+ "fill-rule": "fillRule",
233
+ filter: "filter",
234
+ filterres: "filterRes",
235
+ filterunits: "filterUnits",
236
+ floodopacity: "floodOpacity",
237
+ "flood-opacity": "floodOpacity",
238
+ floodcolor: "floodColor",
239
+ "flood-color": "floodColor",
240
+ focusable: "focusable",
241
+ fontfamily: "fontFamily",
242
+ "font-family": "fontFamily",
243
+ fontsize: "fontSize",
244
+ "font-size": "fontSize",
245
+ fontsizeadjust: "fontSizeAdjust",
246
+ "font-size-adjust": "fontSizeAdjust",
247
+ fontstretch: "fontStretch",
248
+ "font-stretch": "fontStretch",
249
+ fontstyle: "fontStyle",
250
+ "font-style": "fontStyle",
251
+ fontvariant: "fontVariant",
252
+ "font-variant": "fontVariant",
253
+ fontweight: "fontWeight",
254
+ "font-weight": "fontWeight",
255
+ format: "format",
256
+ from: "from",
257
+ fx: "fx",
258
+ fy: "fy",
259
+ g1: "g1",
260
+ g2: "g2",
261
+ glyphname: "glyphName",
262
+ "glyph-name": "glyphName",
263
+ glyphorientationhorizontal: "glyphOrientationHorizontal",
264
+ "glyph-orientation-horizontal": "glyphOrientationHorizontal",
265
+ glyphorientationvertical: "glyphOrientationVertical",
266
+ "glyph-orientation-vertical": "glyphOrientationVertical",
267
+ glyphref: "glyphRef",
268
+ gradienttransform: "gradientTransform",
269
+ gradientunits: "gradientUnits",
270
+ hanging: "hanging",
271
+ horizadvx: "horizAdvX",
272
+ "horiz-adv-x": "horizAdvX",
273
+ horizoriginx: "horizOriginX",
274
+ "horiz-origin-x": "horizOriginX",
275
+ ideographic: "ideographic",
276
+ imagerendering: "imageRendering",
277
+ "image-rendering": "imageRendering",
278
+ in2: "in2",
279
+ in: "in",
280
+ inlist: "inlist",
281
+ intercept: "intercept",
282
+ k1: "k1",
283
+ k2: "k2",
284
+ k3: "k3",
285
+ k4: "k4",
286
+ k: "k",
287
+ kernelmatrix: "kernelMatrix",
288
+ kernelunitlength: "kernelUnitLength",
289
+ kerning: "kerning",
290
+ keypoints: "keyPoints",
291
+ keysplines: "keySplines",
292
+ keytimes: "keyTimes",
293
+ lengthadjust: "lengthAdjust",
294
+ letterspacing: "letterSpacing",
295
+ "letter-spacing": "letterSpacing",
296
+ lightingcolor: "lightingColor",
297
+ "lighting-color": "lightingColor",
298
+ limitingconeangle: "limitingConeAngle",
299
+ local: "local",
300
+ markerend: "markerEnd",
301
+ "marker-end": "markerEnd",
302
+ markerheight: "markerHeight",
303
+ markermid: "markerMid",
304
+ "marker-mid": "markerMid",
305
+ markerstart: "markerStart",
306
+ "marker-start": "markerStart",
307
+ markerunits: "markerUnits",
308
+ markerwidth: "markerWidth",
309
+ mask: "mask",
310
+ maskcontentunits: "maskContentUnits",
311
+ maskunits: "maskUnits",
312
+ mathematical: "mathematical",
313
+ mode: "mode",
314
+ numoctaves: "numOctaves",
315
+ offset: "offset",
316
+ opacity: "opacity",
317
+ operator: "operator",
318
+ order: "order",
319
+ orient: "orient",
320
+ orientation: "orientation",
321
+ origin: "origin",
322
+ overflow: "overflow",
323
+ overlineposition: "overlinePosition",
324
+ "overline-position": "overlinePosition",
325
+ overlinethickness: "overlineThickness",
326
+ "overline-thickness": "overlineThickness",
327
+ paintorder: "paintOrder",
328
+ "paint-order": "paintOrder",
329
+ panose1: "panose1",
330
+ "panose-1": "panose1",
331
+ pathlength: "pathLength",
332
+ patterncontentunits: "patternContentUnits",
333
+ patterntransform: "patternTransform",
334
+ patternunits: "patternUnits",
335
+ pointerevents: "pointerEvents",
336
+ "pointer-events": "pointerEvents",
337
+ points: "points",
338
+ pointsatx: "pointsAtX",
339
+ pointsaty: "pointsAtY",
340
+ pointsatz: "pointsAtZ",
341
+ prefix: "prefix",
342
+ preservealpha: "preserveAlpha",
343
+ preserveaspectratio: "preserveAspectRatio",
344
+ primitiveunits: "primitiveUnits",
345
+ property: "property",
346
+ r: "r",
347
+ radius: "radius",
348
+ refx: "refX",
349
+ refy: "refY",
350
+ renderingintent: "renderingIntent",
351
+ "rendering-intent": "renderingIntent",
352
+ repeatcount: "repeatCount",
353
+ repeatdur: "repeatDur",
354
+ requiredextensions: "requiredExtensions",
355
+ requiredfeatures: "requiredFeatures",
356
+ resource: "resource",
357
+ restart: "restart",
358
+ result: "result",
359
+ results: "results",
360
+ rotate: "rotate",
361
+ rx: "rx",
362
+ ry: "ry",
363
+ scale: "scale",
364
+ security: "security",
365
+ seed: "seed",
366
+ shaperendering: "shapeRendering",
367
+ "shape-rendering": "shapeRendering",
368
+ slope: "slope",
369
+ spacing: "spacing",
370
+ specularconstant: "specularConstant",
371
+ specularexponent: "specularExponent",
372
+ speed: "speed",
373
+ spreadmethod: "spreadMethod",
374
+ startoffset: "startOffset",
375
+ stddeviation: "stdDeviation",
376
+ stemh: "stemh",
377
+ stemv: "stemv",
378
+ stitchtiles: "stitchTiles",
379
+ stopcolor: "stopColor",
380
+ "stop-color": "stopColor",
381
+ stopopacity: "stopOpacity",
382
+ "stop-opacity": "stopOpacity",
383
+ strikethroughposition: "strikethroughPosition",
384
+ "strikethrough-position": "strikethroughPosition",
385
+ strikethroughthickness: "strikethroughThickness",
386
+ "strikethrough-thickness": "strikethroughThickness",
387
+ string: "string",
388
+ stroke: "stroke",
389
+ strokedasharray: "strokeDasharray",
390
+ "stroke-dasharray": "strokeDasharray",
391
+ strokedashoffset: "strokeDashoffset",
392
+ "stroke-dashoffset": "strokeDashoffset",
393
+ strokelinecap: "strokeLinecap",
394
+ "stroke-linecap": "strokeLinecap",
395
+ strokelinejoin: "strokeLinejoin",
396
+ "stroke-linejoin": "strokeLinejoin",
397
+ strokemiterlimit: "strokeMiterlimit",
398
+ "stroke-miterlimit": "strokeMiterlimit",
399
+ strokewidth: "strokeWidth",
400
+ "stroke-width": "strokeWidth",
401
+ strokeopacity: "strokeOpacity",
402
+ "stroke-opacity": "strokeOpacity",
403
+ suppresscontenteditablewarning: "suppressContentEditableWarning",
404
+ suppresshydrationwarning: "suppressHydrationWarning",
405
+ surfacescale: "surfaceScale",
406
+ systemlanguage: "systemLanguage",
407
+ tablevalues: "tableValues",
408
+ targetx: "targetX",
409
+ targety: "targetY",
410
+ textanchor: "textAnchor",
411
+ "text-anchor": "textAnchor",
412
+ textdecoration: "textDecoration",
413
+ "text-decoration": "textDecoration",
414
+ textlength: "textLength",
415
+ textrendering: "textRendering",
416
+ "text-rendering": "textRendering",
417
+ to: "to",
418
+ transform: "transform",
419
+ transformorigin: "transformOrigin",
420
+ "transform-origin": "transformOrigin",
421
+ typeof: "typeof",
422
+ u1: "u1",
423
+ u2: "u2",
424
+ underlineposition: "underlinePosition",
425
+ "underline-position": "underlinePosition",
426
+ underlinethickness: "underlineThickness",
427
+ "underline-thickness": "underlineThickness",
428
+ unicode: "unicode",
429
+ unicodebidi: "unicodeBidi",
430
+ "unicode-bidi": "unicodeBidi",
431
+ unicoderange: "unicodeRange",
432
+ "unicode-range": "unicodeRange",
433
+ unitsperem: "unitsPerEm",
434
+ "units-per-em": "unitsPerEm",
435
+ unselectable: "unselectable",
436
+ valphabetic: "vAlphabetic",
437
+ "v-alphabetic": "vAlphabetic",
438
+ values: "values",
439
+ vectoreffect: "vectorEffect",
440
+ "vector-effect": "vectorEffect",
441
+ version: "version",
442
+ vertadvy: "vertAdvY",
443
+ "vert-adv-y": "vertAdvY",
444
+ vertoriginx: "vertOriginX",
445
+ "vert-origin-x": "vertOriginX",
446
+ vertoriginy: "vertOriginY",
447
+ "vert-origin-y": "vertOriginY",
448
+ vhanging: "vHanging",
449
+ "v-hanging": "vHanging",
450
+ videographic: "vIdeographic",
451
+ "v-ideographic": "vIdeographic",
452
+ viewbox: "viewBox",
453
+ viewtarget: "viewTarget",
454
+ visibility: "visibility",
455
+ vmathematical: "vMathematical",
456
+ "v-mathematical": "vMathematical",
457
+ vocab: "vocab",
458
+ widths: "widths",
459
+ wordspacing: "wordSpacing",
460
+ "word-spacing": "wordSpacing",
461
+ writingmode: "writingMode",
462
+ "writing-mode": "writingMode",
463
+ x1: "x1",
464
+ x2: "x2",
465
+ x: "x",
466
+ xchannelselector: "xChannelSelector",
467
+ xheight: "xHeight",
468
+ "x-height": "xHeight",
469
+ xlinkactuate: "xlinkActuate",
470
+ "xlink:actuate": "xlinkActuate",
471
+ xlinkarcrole: "xlinkArcrole",
472
+ "xlink:arcrole": "xlinkArcrole",
473
+ xlinkhref: "xlinkHref",
474
+ "xlink:href": "xlinkHref",
475
+ xlinkrole: "xlinkRole",
476
+ "xlink:role": "xlinkRole",
477
+ xlinkshow: "xlinkShow",
478
+ "xlink:show": "xlinkShow",
479
+ xlinktitle: "xlinkTitle",
480
+ "xlink:title": "xlinkTitle",
481
+ xlinktype: "xlinkType",
482
+ "xlink:type": "xlinkType",
483
+ xmlbase: "xmlBase",
484
+ "xml:base": "xmlBase",
485
+ xmllang: "xmlLang",
486
+ "xml:lang": "xmlLang",
487
+ xmlns: "xmlns",
488
+ "xml:space": "xmlSpace",
489
+ xmlnsxlink: "xmlnsXlink",
490
+ "xmlns:xlink": "xmlnsXlink",
491
+ xmlspace: "xmlSpace",
492
+ y1: "y1",
493
+ y2: "y2",
494
+ y: "y",
495
+ ychannelselector: "yChannelSelector",
496
+ z: "z",
497
+ zoomandpan: "zoomAndPan"
498
+ }
499
+
500
+ OPTION_STANDARD_NAMES = {
501
+ default_value: "defaultValue",
502
+ default_checked: "defaultChecked",
503
+ checked_value: "checkedValue",
504
+ unchecked_value: "uncheckedValue",
505
+ include_hidden: "includeHidden",
506
+ include_blank: "includeBlank",
507
+ max_length: "maxLength",
508
+ min_length: "minLength",
509
+ class_name: "className",
510
+ auto_complete: "autoComplete",
511
+ read_only: "readOnly"
512
+ }
513
+
514
+ STANDARD_NAMES = POSSIBLE_STANDARD_NAMES.merge(OPTION_STANDARD_NAMES)
515
+
516
+ module Helper
517
+ extend self
518
+
519
+ def format_key(key)
520
+ if STANDARD_NAMES.has_key?(key.to_sym)
521
+ STANDARD_NAMES[key.to_sym]
522
+ else
523
+ key
524
+ end
525
+ end
526
+
527
+ def format_keys(props)
528
+ props.each_with_object({}) do |(key, val), memo|
529
+ key = format_key(key)
530
+ memo[key] = val
531
+ end
532
+ end
533
+ end
534
+ end
@@ -11,11 +11,17 @@ 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
 
21
+ def sanitized_key
22
+ @key || sanitized_method_name.camelize(:lower)
23
+ end
24
+
19
25
  def add_options(option_tags, options, value = nil)
20
26
  if options[:include_blank]
21
27
  content = (options[:include_blank] if options[:include_blank].is_a?(String))
@@ -95,6 +101,7 @@ module FormProps
95
101
  end
96
102
  end
97
103
 
104
+ key = FormProps::Helper.format_key(key)
98
105
  json.set!(key, value)
99
106
  end
100
107
 
@@ -150,11 +157,11 @@ module FormProps
150
157
  end
151
158
  end
152
159
 
153
- json.set!(sanitized_method_name) do
160
+ json.set!(sanitized_key) do
154
161
  input_props(html_options)
155
162
 
156
163
  if options.key?(:include_hidden)
157
- json.include_hidden options[:include_hidden]
164
+ json.includeHidden options[:include_hidden]
158
165
  end
159
166
  json.options(option_tags)
160
167
  end
@@ -40,7 +40,7 @@ module FormProps
40
40
  if flatten
41
41
  body_block.call
42
42
  else
43
- json.set!(sanitized_method_name) do
43
+ json.set!(sanitized_key) do
44
44
  body_block.call
45
45
  end
46
46
  end
@@ -21,12 +21,12 @@ module FormProps
21
21
  end
22
22
 
23
23
  def render
24
- json.set!(sanitized_method_name) do
24
+ json.set!(sanitized_key) do
25
25
  json.collection do
26
26
  render_collection_for(CheckBoxBuilder)
27
27
  end
28
28
 
29
- json.include_hidden(@options.fetch(:include_hidden) { true })
29
+ json.includeHidden(@options.fetch(:include_hidden) { true })
30
30
 
31
31
  input_props(@html_options)
32
32
  end
@@ -20,12 +20,12 @@ module FormProps
20
20
  end
21
21
 
22
22
  def render
23
- json.set!(sanitized_method_name) do
23
+ json.set!(sanitized_key) do
24
24
  json.collection do
25
25
  render_collection_for(RadioButtonBuilder)
26
26
  end
27
27
 
28
- json.include_hidden(@options.fetch(:include_hidden) { true })
28
+ json.includeHidden(@options.fetch(:include_hidden) { true })
29
29
 
30
30
  input_props(@html_options)
31
31
  end
@@ -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)}"
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
@@ -8,7 +8,7 @@ module FormProps
8
8
  include ActionView::Helpers::Tags::Placeholderable
9
9
 
10
10
  def render
11
- json.set!(sanitized_method_name) do
11
+ json.set!(sanitized_key) do
12
12
  add_default_name_and_id(@options)
13
13
  @options[:type] ||= field_type
14
14
  @options[:value] = @options.fetch(:value) { value_before_type_cast }
@@ -12,7 +12,7 @@ module FormProps
12
12
  @options[:type] ||= field_type
13
13
  @options[:value] = @options.fetch(:value) { value_before_type_cast } unless field_type == "file"
14
14
 
15
- json.set!(sanitized_method_name) do
15
+ json.set!(sanitized_key) do
16
16
  add_default_name_and_id(@options)
17
17
  input_props(@options)
18
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormProps
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.6"
5
5
  end
data/lib/form_props.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "action_view"
4
4
  require "action_pack"
5
+ require "form_props/helper"
5
6
  require "form_props/action_view_extensions/form_helper"
6
7
  require "form_props/form_options_helper"
7
8
  require "form_props/inputs/base"
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.4
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-17 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
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.23.0
47
+ version: 0.30.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.23.0
54
+ version: 0.30.0
55
55
  description: Form props is a Rails form builder that renders form attributes in JSON
56
56
  email: johny@thoughtbot.com
57
57
  executables: []
@@ -63,6 +63,7 @@ files:
63
63
  - lib/form_props/action_view_extensions/form_helper.rb
64
64
  - lib/form_props/form_builder.rb
65
65
  - lib/form_props/form_options_helper.rb
66
+ - lib/form_props/helper.rb
66
67
  - lib/form_props/inputs/base.rb
67
68
  - lib/form_props/inputs/check_box.rb
68
69
  - lib/form_props/inputs/collection_check_boxes.rb