handlebars-helpers 0.0.77 → 0.0.79
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/.handlebars_helpers.json +166 -107
- data/README.md +5 -3
- data/STORIES.md +1 -1
- data/USAGE.md +5 -5
- data/lib/handlebars/helpers/base_helper.rb +55 -0
- data/lib/handlebars/helpers/code_javascript/as_javascript.rb +61 -0
- data/lib/handlebars/helpers/json/as_json.rb +42 -0
- data/lib/handlebars/helpers/statistics.rb +2 -2
- data/lib/handlebars/helpers/version.rb +1 -1
- metadata +5 -4
- data/lib/handlebars/helpers/misc/json.rb +0 -99
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c57a2d3c8e0e593b9ae2a628d3ae139ffeb6b0989afc174ee41875a2ec38bc72
|
|
4
|
+
data.tar.gz: d7e9a3ba1fe17a5e1ae0a56322f571db878a08dae402b906ec1733980fcb7efa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49c1b409299678aac9b74a5c2c8580d79d85c8f621ae20dff140b483e013227916f2ff5928012f07fe0ac31eddc6d94c236d7decf574a04f82e6cca3f1c3b078
|
|
7
|
+
data.tar.gz: 92766053b2ca98b64b7f7c9181134d941fde107d283cf2e9eb1ab74b28f8d6346301f25c3d6a7ab6bef3b6f1eef096ac49aeb49dba12b9c3edf478f969767368
|
data/.handlebars_helpers.json
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"alias": "default",
|
|
22
22
|
"expected_value": "hello world",
|
|
23
23
|
"params": [
|
|
24
|
-
{ "name": "p1", "
|
|
25
|
-
{ "name": "p2", "
|
|
24
|
+
{ "name": "p1", "nil_value": true },
|
|
25
|
+
{ "name": "p2", "nil_value": true }
|
|
26
26
|
],
|
|
27
27
|
"template": "{{default p1 p2 \"hello world\"}}"
|
|
28
28
|
}
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"alias": "or",
|
|
43
43
|
"expected_value": "param2",
|
|
44
44
|
"params": [
|
|
45
|
-
{ "name": "p1", "
|
|
46
|
-
{ "name": "p2", "
|
|
45
|
+
{ "name": "p1", "nil_value": true },
|
|
46
|
+
{ "name": "p2", "string_value": "param2" }
|
|
47
47
|
],
|
|
48
48
|
"template": "\n {{~#if (or p1 p2)~}}\n {{p1}}{{p2}}\n {{~/if~}}\n "
|
|
49
49
|
},
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"alias": "any",
|
|
52
52
|
"expected_value": "param2",
|
|
53
53
|
"params": [
|
|
54
|
-
{ "name": "p1", "
|
|
55
|
-
{ "name": "p2", "
|
|
54
|
+
{ "name": "p1", "nil_value": true },
|
|
55
|
+
{ "name": "p2", "string_value": "param2" }
|
|
56
56
|
],
|
|
57
57
|
"template": "\n {{~#if (any p1 p2)~}}\n {{p1}}{{p2}}\n {{~/if~}}\n "
|
|
58
58
|
}
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"alias": "and",
|
|
73
73
|
"expected_value": "all params exist",
|
|
74
74
|
"params": [
|
|
75
|
-
{ "name": "p1", "
|
|
76
|
-
{ "name": "p2", "
|
|
75
|
+
{ "name": "p1", "string_value": "param1" },
|
|
76
|
+
{ "name": "p2", "string_value": "param2" }
|
|
77
77
|
],
|
|
78
78
|
"template": "\n {{~#if (and p1 p2)~}}\n all params exist\n {{~/if~}}\n "
|
|
79
79
|
},
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"alias": "all",
|
|
82
82
|
"expected_value": "all params exist",
|
|
83
83
|
"params": [
|
|
84
|
-
{ "name": "p1", "
|
|
85
|
-
{ "name": "p2", "
|
|
84
|
+
{ "name": "p1", "string_value": "param1" },
|
|
85
|
+
{ "name": "p2", "string_value": "param2" }
|
|
86
86
|
],
|
|
87
87
|
"template": "\n {{~#if (all p1 p2)~}}\n all params exist\n {{~/if~}}\n "
|
|
88
88
|
}
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
"alias": "eq",
|
|
103
103
|
"expected_value": "params are equal",
|
|
104
104
|
"params": [
|
|
105
|
-
{ "name": "p1", "
|
|
106
|
-
{ "name": "p2", "
|
|
105
|
+
{ "name": "p1", "string_value": "david" },
|
|
106
|
+
{ "name": "p2", "string_value": "david" }
|
|
107
107
|
],
|
|
108
108
|
"template": "\n {{~#if (eq p1 p2)~}}\n params are equal\n {{~/if~}}\n "
|
|
109
109
|
},
|
|
@@ -111,8 +111,8 @@
|
|
|
111
111
|
"alias": "equal",
|
|
112
112
|
"expected_value": "params are equal",
|
|
113
113
|
"params": [
|
|
114
|
-
{ "name": "p1", "
|
|
115
|
-
{ "name": "p2", "
|
|
114
|
+
{ "name": "p1", "string_value": "david" },
|
|
115
|
+
{ "name": "p2", "string_value": "david" }
|
|
116
116
|
],
|
|
117
117
|
"template": "\n {{~#if (equal p1 p2)~}}\n params are equal\n {{~/if~}}\n "
|
|
118
118
|
}
|
|
@@ -132,8 +132,8 @@
|
|
|
132
132
|
"alias": "ne",
|
|
133
133
|
"expected_value": "params are not equal",
|
|
134
134
|
"params": [
|
|
135
|
-
{ "name": "p1", "
|
|
136
|
-
{ "name": "p2", "
|
|
135
|
+
{ "name": "p1", "string_value": "aaa" },
|
|
136
|
+
{ "name": "p2", "string_value": "bbb" }
|
|
137
137
|
],
|
|
138
138
|
"template": "\n {{~#if (ne p1 p2)~}}\n params are not equal\n {{~/if~}}\n "
|
|
139
139
|
},
|
|
@@ -141,8 +141,8 @@
|
|
|
141
141
|
"alias": "not_equal",
|
|
142
142
|
"expected_value": "params are not equal",
|
|
143
143
|
"params": [
|
|
144
|
-
{ "name": "p1", "
|
|
145
|
-
{ "name": "p2", "
|
|
144
|
+
{ "name": "p1", "string_value": "aaa" },
|
|
145
|
+
{ "name": "p2", "string_value": "bbb" }
|
|
146
146
|
],
|
|
147
147
|
"template": "\n {{~#if (not_equal p1 p2)~}}\n params are not equal\n {{~/if~}}\n "
|
|
148
148
|
}
|
|
@@ -162,8 +162,8 @@
|
|
|
162
162
|
"alias": "lt",
|
|
163
163
|
"expected_value": "1 is less than 2",
|
|
164
164
|
"params": [
|
|
165
|
-
{ "name": "p1", "
|
|
166
|
-
{ "name": "p2", "
|
|
165
|
+
{ "name": "p1", "string_value": 1 },
|
|
166
|
+
{ "name": "p2", "string_value": 2 }
|
|
167
167
|
],
|
|
168
168
|
"template": "\n {{~#if (lt p1 p2)~}}\n 1 is less than 2\n {{~/if~}}\n "
|
|
169
169
|
},
|
|
@@ -171,8 +171,8 @@
|
|
|
171
171
|
"alias": "less_than",
|
|
172
172
|
"expected_value": "1 is less than 2",
|
|
173
173
|
"params": [
|
|
174
|
-
{ "name": "p1", "
|
|
175
|
-
{ "name": "p2", "
|
|
174
|
+
{ "name": "p1", "string_value": 1 },
|
|
175
|
+
{ "name": "p2", "string_value": 2 }
|
|
176
176
|
],
|
|
177
177
|
"template": "\n {{~#if (less_than p1 p2)~}}\n 1 is less than 2\n {{~/if~}}\n "
|
|
178
178
|
}
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
"alias": "lte",
|
|
193
193
|
"expected_value": "1 is less than or equal 1",
|
|
194
194
|
"params": [
|
|
195
|
-
{ "name": "p1", "
|
|
196
|
-
{ "name": "p2", "
|
|
195
|
+
{ "name": "p1", "string_value": 1 },
|
|
196
|
+
{ "name": "p2", "string_value": 1 }
|
|
197
197
|
],
|
|
198
198
|
"template": "\n {{~#if (lte p1 p2)~}}\n 1 is less than or equal 1\n {{~/if~}}\n "
|
|
199
199
|
},
|
|
@@ -201,8 +201,8 @@
|
|
|
201
201
|
"alias": "less_than_or_equal_to",
|
|
202
202
|
"expected_value": "1 is less than or equal 1",
|
|
203
203
|
"params": [
|
|
204
|
-
{ "name": "p1", "
|
|
205
|
-
{ "name": "p2", "
|
|
204
|
+
{ "name": "p1", "string_value": 1 },
|
|
205
|
+
{ "name": "p2", "string_value": 1 }
|
|
206
206
|
],
|
|
207
207
|
"template": "\n {{~#if (less_than_or_equal_to p1 p2)~}}\n 1 is less than or equal 1\n {{~/if~}}\n "
|
|
208
208
|
}
|
|
@@ -222,8 +222,8 @@
|
|
|
222
222
|
"alias": "gt",
|
|
223
223
|
"expected_value": "2 is greater than 1",
|
|
224
224
|
"params": [
|
|
225
|
-
{ "name": "p1", "
|
|
226
|
-
{ "name": "p2", "
|
|
225
|
+
{ "name": "p1", "string_value": 2 },
|
|
226
|
+
{ "name": "p2", "string_value": 1 }
|
|
227
227
|
],
|
|
228
228
|
"template": "\n {{~#if (gt p1 p2)~}}\n 2 is greater than 1\n {{~/if~}}\n "
|
|
229
229
|
},
|
|
@@ -231,8 +231,8 @@
|
|
|
231
231
|
"alias": "greater_than",
|
|
232
232
|
"expected_value": "2 is greater than 1",
|
|
233
233
|
"params": [
|
|
234
|
-
{ "name": "p1", "
|
|
235
|
-
{ "name": "p2", "
|
|
234
|
+
{ "name": "p1", "string_value": 2 },
|
|
235
|
+
{ "name": "p2", "string_value": 1 }
|
|
236
236
|
],
|
|
237
237
|
"template": "\n {{~#if (greater_than p1 p2)~}}\n 2 is greater than 1\n {{~/if~}}\n "
|
|
238
238
|
}
|
|
@@ -252,8 +252,8 @@
|
|
|
252
252
|
"alias": "gte",
|
|
253
253
|
"expected_value": "1 is greater than or equal 1",
|
|
254
254
|
"params": [
|
|
255
|
-
{ "name": "p1", "
|
|
256
|
-
{ "name": "p2", "
|
|
255
|
+
{ "name": "p1", "string_value": 1 },
|
|
256
|
+
{ "name": "p2", "string_value": 1 }
|
|
257
257
|
],
|
|
258
258
|
"template": "\n {{~#if (gte p1 p2)~}}\n 1 is greater than or equal 1\n {{~/if~}}\n "
|
|
259
259
|
},
|
|
@@ -261,8 +261,8 @@
|
|
|
261
261
|
"alias": "greater_than_or_equal_to",
|
|
262
262
|
"expected_value": "1 is greater than or equal 1",
|
|
263
263
|
"params": [
|
|
264
|
-
{ "name": "p1", "
|
|
265
|
-
{ "name": "p2", "
|
|
264
|
+
{ "name": "p1", "string_value": 1 },
|
|
265
|
+
{ "name": "p2", "string_value": 1 }
|
|
266
266
|
],
|
|
267
267
|
"template": "\n {{~#if (greater_than_or_equal_to p1 p2)~}}\n 1 is greater than or equal 1\n {{~/if~}}\n "
|
|
268
268
|
}
|
|
@@ -317,9 +317,9 @@
|
|
|
317
317
|
"alias": "pluralize_by_number",
|
|
318
318
|
"expected_value": "3 people",
|
|
319
319
|
"params": [
|
|
320
|
-
{ "name": "value", "
|
|
321
|
-
{ "name": "count", "
|
|
322
|
-
{ "name": "format", "
|
|
320
|
+
{ "name": "value", "string_value": "person" },
|
|
321
|
+
{ "name": "count", "string_value": "3" },
|
|
322
|
+
{ "name": "format", "string_value": "number_word" }
|
|
323
323
|
],
|
|
324
324
|
"template": "{{pluralize_by_number value count format}}"
|
|
325
325
|
}
|
|
@@ -364,26 +364,6 @@
|
|
|
364
364
|
"https://github.com/helpers/handlebars-helpers/blob/master/test/misc.js"
|
|
365
365
|
],
|
|
366
366
|
"helpers": [
|
|
367
|
-
{
|
|
368
|
-
"name": "json",
|
|
369
|
-
"description": "value as JSON string",
|
|
370
|
-
"test_in": null,
|
|
371
|
-
"test_out": null,
|
|
372
|
-
"tests": [
|
|
373
|
-
{
|
|
374
|
-
"alias": "json",
|
|
375
|
-
"expected_value": "{ \"david\": \"was here\" }",
|
|
376
|
-
"params": [
|
|
377
|
-
{ "name": "value", "value": "{ \"david\": \"was here\" }" }
|
|
378
|
-
],
|
|
379
|
-
"template": "{{json value}}"
|
|
380
|
-
}
|
|
381
|
-
],
|
|
382
|
-
"aliases": ["json"],
|
|
383
|
-
"require_path": "handlebars/helpers/misc/json",
|
|
384
|
-
"class_namespace": "Handlebars::Helpers::Misc::Json",
|
|
385
|
-
"is_string_formatter": null
|
|
386
|
-
},
|
|
387
367
|
{
|
|
388
368
|
"name": "safe",
|
|
389
369
|
"description": "value in safe string format",
|
|
@@ -393,7 +373,7 @@
|
|
|
393
373
|
{
|
|
394
374
|
"alias": "safe",
|
|
395
375
|
"expected_value": "\"hello\"",
|
|
396
|
-
"params": [{ "name": "value", "
|
|
376
|
+
"params": [{ "name": "value", "string_value": "\"hello\"" }],
|
|
397
377
|
"template": "{{safe value}}"
|
|
398
378
|
}
|
|
399
379
|
],
|
|
@@ -449,7 +429,7 @@
|
|
|
449
429
|
"alias": "classify",
|
|
450
430
|
"expected_value": "ProductCategory",
|
|
451
431
|
"params": [
|
|
452
|
-
{ "name": "table_name", "
|
|
432
|
+
{ "name": "table_name", "string_value": "product_categories" }
|
|
453
433
|
],
|
|
454
434
|
"template": "{{classify table_name}}"
|
|
455
435
|
}
|
|
@@ -471,7 +451,7 @@
|
|
|
471
451
|
"params": [
|
|
472
452
|
{
|
|
473
453
|
"name": "namespaced_class",
|
|
474
|
-
"
|
|
454
|
+
"string_value": "ActiveSupport::Inflector::Inflections"
|
|
475
455
|
}
|
|
476
456
|
],
|
|
477
457
|
"template": "{{demodulize namespaced_class}}"
|
|
@@ -492,7 +472,7 @@
|
|
|
492
472
|
"alias": "deconstantize",
|
|
493
473
|
"expected_value": "Net",
|
|
494
474
|
"params": [
|
|
495
|
-
{ "name": "constant_expression", "
|
|
475
|
+
{ "name": "constant_expression", "string_value": "Net::HTTP" }
|
|
496
476
|
],
|
|
497
477
|
"template": "{{deconstantize constant_expression}}"
|
|
498
478
|
}
|
|
@@ -511,7 +491,7 @@
|
|
|
511
491
|
{
|
|
512
492
|
"alias": "foreign_key",
|
|
513
493
|
"expected_value": "message_id",
|
|
514
|
-
"params": [{ "name": "class_name", "
|
|
494
|
+
"params": [{ "name": "class_name", "string_value": "Message" }],
|
|
515
495
|
"template": "{{foreign_key class_name}}"
|
|
516
496
|
}
|
|
517
497
|
],
|
|
@@ -529,7 +509,9 @@
|
|
|
529
509
|
{
|
|
530
510
|
"alias": "tableize",
|
|
531
511
|
"expected_value": "product_categories",
|
|
532
|
-
"params": [
|
|
512
|
+
"params": [
|
|
513
|
+
{ "name": "model_name", "string_value": "product_category" }
|
|
514
|
+
],
|
|
533
515
|
"template": "{{tableize model_name}}"
|
|
534
516
|
}
|
|
535
517
|
],
|
|
@@ -558,8 +540,8 @@
|
|
|
558
540
|
"alias": "format_as",
|
|
559
541
|
"expected_value": "the-quick-brown-foxes",
|
|
560
542
|
"params": [
|
|
561
|
-
{ "name": "value", "
|
|
562
|
-
{ "name": "format", "
|
|
543
|
+
{ "name": "value", "string_value": "the quick brown fox" },
|
|
544
|
+
{ "name": "format", "string_value": "pluralize,dashify" }
|
|
563
545
|
],
|
|
564
546
|
"template": "{{format_as value format}}"
|
|
565
547
|
}
|
|
@@ -775,9 +757,9 @@
|
|
|
775
757
|
"alias": "padr",
|
|
776
758
|
"expected_value": "pad-me....",
|
|
777
759
|
"params": [
|
|
778
|
-
{ "name": "value", "
|
|
779
|
-
{ "name": "count", "
|
|
780
|
-
{ "name": "char", "
|
|
760
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
761
|
+
{ "name": "count", "string_value": 10 },
|
|
762
|
+
{ "name": "char", "string_value": "." }
|
|
781
763
|
],
|
|
782
764
|
"template": "{{padr value count char}}"
|
|
783
765
|
},
|
|
@@ -785,9 +767,9 @@
|
|
|
785
767
|
"alias": "pad_right",
|
|
786
768
|
"expected_value": "pad-me....",
|
|
787
769
|
"params": [
|
|
788
|
-
{ "name": "value", "
|
|
789
|
-
{ "name": "count", "
|
|
790
|
-
{ "name": "char", "
|
|
770
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
771
|
+
{ "name": "count", "string_value": 10 },
|
|
772
|
+
{ "name": "char", "string_value": "." }
|
|
791
773
|
],
|
|
792
774
|
"template": "{{pad_right value count char}}"
|
|
793
775
|
},
|
|
@@ -795,9 +777,9 @@
|
|
|
795
777
|
"alias": "ljust",
|
|
796
778
|
"expected_value": "pad-me....",
|
|
797
779
|
"params": [
|
|
798
|
-
{ "name": "value", "
|
|
799
|
-
{ "name": "count", "
|
|
800
|
-
{ "name": "char", "
|
|
780
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
781
|
+
{ "name": "count", "string_value": 10 },
|
|
782
|
+
{ "name": "char", "string_value": "." }
|
|
801
783
|
],
|
|
802
784
|
"template": "{{ljust value count char}}"
|
|
803
785
|
}
|
|
@@ -817,9 +799,9 @@
|
|
|
817
799
|
"alias": "padl",
|
|
818
800
|
"expected_value": "....pad-me",
|
|
819
801
|
"params": [
|
|
820
|
-
{ "name": "value", "
|
|
821
|
-
{ "name": "count", "
|
|
822
|
-
{ "name": "char", "
|
|
802
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
803
|
+
{ "name": "count", "string_value": 10 },
|
|
804
|
+
{ "name": "char", "string_value": "." }
|
|
823
805
|
],
|
|
824
806
|
"template": "{{padl value count char}}"
|
|
825
807
|
},
|
|
@@ -827,9 +809,9 @@
|
|
|
827
809
|
"alias": "pad_left",
|
|
828
810
|
"expected_value": "....pad-me",
|
|
829
811
|
"params": [
|
|
830
|
-
{ "name": "value", "
|
|
831
|
-
{ "name": "count", "
|
|
832
|
-
{ "name": "char", "
|
|
812
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
813
|
+
{ "name": "count", "string_value": 10 },
|
|
814
|
+
{ "name": "char", "string_value": "." }
|
|
833
815
|
],
|
|
834
816
|
"template": "{{pad_left value count char}}"
|
|
835
817
|
},
|
|
@@ -837,9 +819,9 @@
|
|
|
837
819
|
"alias": "rjust",
|
|
838
820
|
"expected_value": "....pad-me",
|
|
839
821
|
"params": [
|
|
840
|
-
{ "name": "value", "
|
|
841
|
-
{ "name": "count", "
|
|
842
|
-
{ "name": "char", "
|
|
822
|
+
{ "name": "value", "string_value": "pad-me" },
|
|
823
|
+
{ "name": "count", "string_value": 10 },
|
|
824
|
+
{ "name": "char", "string_value": "." }
|
|
843
825
|
],
|
|
844
826
|
"template": "{{rjust value count char}}"
|
|
845
827
|
}
|
|
@@ -859,9 +841,9 @@
|
|
|
859
841
|
"alias": "prepend_if",
|
|
860
842
|
"expected_value": "# product_categories",
|
|
861
843
|
"params": [
|
|
862
|
-
{ "name": "value", "
|
|
863
|
-
{ "name": "prefix", "
|
|
864
|
-
{ "name": "formats", "
|
|
844
|
+
{ "name": "value", "string_value": "product category" },
|
|
845
|
+
{ "name": "prefix", "string_value": "# " },
|
|
846
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
865
847
|
],
|
|
866
848
|
"template": "{{prepend_if value prefix formats}}"
|
|
867
849
|
},
|
|
@@ -869,9 +851,9 @@
|
|
|
869
851
|
"alias": "prefix_if",
|
|
870
852
|
"expected_value": "# product_categories",
|
|
871
853
|
"params": [
|
|
872
|
-
{ "name": "value", "
|
|
873
|
-
{ "name": "prefix", "
|
|
874
|
-
{ "name": "formats", "
|
|
854
|
+
{ "name": "value", "string_value": "product category" },
|
|
855
|
+
{ "name": "prefix", "string_value": "# " },
|
|
856
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
875
857
|
],
|
|
876
858
|
"template": "{{prefix_if value prefix formats}}"
|
|
877
859
|
}
|
|
@@ -891,9 +873,9 @@
|
|
|
891
873
|
"alias": "append_if",
|
|
892
874
|
"expected_value": "product_categories:",
|
|
893
875
|
"params": [
|
|
894
|
-
{ "name": "value", "
|
|
895
|
-
{ "name": "suffix", "
|
|
896
|
-
{ "name": "formats", "
|
|
876
|
+
{ "name": "value", "string_value": "product category" },
|
|
877
|
+
{ "name": "suffix", "string_value": ":" },
|
|
878
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
897
879
|
],
|
|
898
880
|
"template": "{{append_if value suffix formats}}"
|
|
899
881
|
},
|
|
@@ -901,9 +883,9 @@
|
|
|
901
883
|
"alias": "suffix_if",
|
|
902
884
|
"expected_value": "product_categories:",
|
|
903
885
|
"params": [
|
|
904
|
-
{ "name": "value", "
|
|
905
|
-
{ "name": "suffix", "
|
|
906
|
-
{ "name": "formats", "
|
|
886
|
+
{ "name": "value", "string_value": "product category" },
|
|
887
|
+
{ "name": "suffix", "string_value": ":" },
|
|
888
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
907
889
|
],
|
|
908
890
|
"template": "{{suffix_if value suffix formats}}"
|
|
909
891
|
}
|
|
@@ -923,10 +905,10 @@
|
|
|
923
905
|
"alias": "surround_if",
|
|
924
906
|
"expected_value": "(product_categories)",
|
|
925
907
|
"params": [
|
|
926
|
-
{ "name": "value", "
|
|
927
|
-
{ "name": "prefix", "
|
|
928
|
-
{ "name": "suffix", "
|
|
929
|
-
{ "name": "formats", "
|
|
908
|
+
{ "name": "value", "string_value": "product category" },
|
|
909
|
+
{ "name": "prefix", "string_value": "(" },
|
|
910
|
+
{ "name": "suffix", "string_value": ")" },
|
|
911
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
930
912
|
],
|
|
931
913
|
"template": "{{surround_if value prefix suffix formats}}"
|
|
932
914
|
},
|
|
@@ -934,10 +916,10 @@
|
|
|
934
916
|
"alias": "surround_if_value",
|
|
935
917
|
"expected_value": "(product_categories)",
|
|
936
918
|
"params": [
|
|
937
|
-
{ "name": "value", "
|
|
938
|
-
{ "name": "prefix", "
|
|
939
|
-
{ "name": "suffix", "
|
|
940
|
-
{ "name": "formats", "
|
|
919
|
+
{ "name": "value", "string_value": "product category" },
|
|
920
|
+
{ "name": "prefix", "string_value": "(" },
|
|
921
|
+
{ "name": "suffix", "string_value": ")" },
|
|
922
|
+
{ "name": "formats", "string_value": "pluralize,snake" }
|
|
941
923
|
],
|
|
942
924
|
"template": "{{surround_if_value value prefix suffix formats}}"
|
|
943
925
|
}
|
|
@@ -957,10 +939,10 @@
|
|
|
957
939
|
"alias": "surround",
|
|
958
940
|
"expected_value": "()",
|
|
959
941
|
"params": [
|
|
960
|
-
{ "name": "value", "
|
|
961
|
-
{ "name": "prefix", "
|
|
962
|
-
{ "name": "suffix", "
|
|
963
|
-
{ "name": "formats", "
|
|
942
|
+
{ "name": "value", "nil_value": true },
|
|
943
|
+
{ "name": "prefix", "string_value": "(" },
|
|
944
|
+
{ "name": "suffix", "string_value": ")" },
|
|
945
|
+
{ "name": "formats", "nil_value": true }
|
|
964
946
|
],
|
|
965
947
|
"template": "{{surround value prefix suffix formats}}"
|
|
966
948
|
}
|
|
@@ -971,6 +953,83 @@
|
|
|
971
953
|
"is_string_formatter": null
|
|
972
954
|
}
|
|
973
955
|
]
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
"active": true,
|
|
959
|
+
"name": "code_javascript",
|
|
960
|
+
"base_require": "handlebars/helpers/code_javascript",
|
|
961
|
+
"base_namespace": "Handlebars::Helpers::CodeJavascript",
|
|
962
|
+
"description": "Javascript code handling routines",
|
|
963
|
+
"examples": [],
|
|
964
|
+
"helpers": [
|
|
965
|
+
{
|
|
966
|
+
"name": "as_javascript",
|
|
967
|
+
"description": "value as javascript string",
|
|
968
|
+
"test_in": null,
|
|
969
|
+
"test_out": null,
|
|
970
|
+
"tests": [
|
|
971
|
+
{
|
|
972
|
+
"alias": "as_javascript",
|
|
973
|
+
"expected_value": "{ david: \"was here\" }",
|
|
974
|
+
"params": [
|
|
975
|
+
{ "name": "value", "hash_value": "{ david: \"was here\" }" }
|
|
976
|
+
],
|
|
977
|
+
"template": "{{as_javascript value}}",
|
|
978
|
+
"custom_expectation": "it {\n expected_value = <<~RUBY.strip\n {\n david: \"was here\"\n } \n RUBY\n\n is_expected.to eq(expected_value)\n}"
|
|
979
|
+
}
|
|
980
|
+
],
|
|
981
|
+
"aliases": ["as_javascript"],
|
|
982
|
+
"require_path": "handlebars/helpers/code_javascript/as_javascript",
|
|
983
|
+
"class_namespace": "Handlebars::Helpers::CodeJavascript::AsJavascript",
|
|
984
|
+
"is_string_formatter": null
|
|
985
|
+
}
|
|
986
|
+
]
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
"active": true,
|
|
990
|
+
"name": "json",
|
|
991
|
+
"base_require": "handlebars/helpers/json",
|
|
992
|
+
"base_namespace": "Handlebars::Helpers::Json",
|
|
993
|
+
"description": "Json handling routines",
|
|
994
|
+
"examples": [
|
|
995
|
+
"https://github.com/rails/rails/blob/v6.1.1/activesupport/lib/active_support/json.rb"
|
|
996
|
+
],
|
|
997
|
+
"helpers": [
|
|
998
|
+
{
|
|
999
|
+
"name": "as_json",
|
|
1000
|
+
"description": "value as JSON string",
|
|
1001
|
+
"test_in": null,
|
|
1002
|
+
"test_out": null,
|
|
1003
|
+
"tests": [
|
|
1004
|
+
{
|
|
1005
|
+
"alias": "as_json",
|
|
1006
|
+
"expected_value": "{ \"david\": \"was here\" }",
|
|
1007
|
+
"params": [
|
|
1008
|
+
{
|
|
1009
|
+
"name": "value",
|
|
1010
|
+
"string_value": "{ \"david\": \"was here\" }"
|
|
1011
|
+
}
|
|
1012
|
+
],
|
|
1013
|
+
"template": "{{as_json value}}"
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
"alias": "json",
|
|
1017
|
+
"expected_value": "{ \"david\": \"was here\" }",
|
|
1018
|
+
"params": [
|
|
1019
|
+
{
|
|
1020
|
+
"name": "value",
|
|
1021
|
+
"string_value": "{ \"david\": \"was here\" }"
|
|
1022
|
+
}
|
|
1023
|
+
],
|
|
1024
|
+
"template": "{{json value}}"
|
|
1025
|
+
}
|
|
1026
|
+
],
|
|
1027
|
+
"aliases": ["as_json", "json"],
|
|
1028
|
+
"require_path": "handlebars/helpers/json/as_json",
|
|
1029
|
+
"class_namespace": "Handlebars::Helpers::Json::AsJson",
|
|
1030
|
+
"is_string_formatter": null
|
|
1031
|
+
}
|
|
1032
|
+
]
|
|
974
1033
|
}
|
|
975
1034
|
]
|
|
976
1035
|
}
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Handlebars Helpers
|
|
2
2
|
|
|
3
|
-
> Handlebars Helpers is a library that provides <b>
|
|
3
|
+
> Handlebars Helpers is a library that provides <b>44</b> handlebars helpers across <b>7</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
|
4
4
|
|
|
5
5
|
This GEM is inspired by the Javascript Library [handlebars-helpers](https://github.com/helpers/handlebars-helpers).
|
|
6
6
|
|
|
@@ -42,10 +42,12 @@ See all [usage examples](./USAGE.md)
|
|
|
42
42
|
|
|
43
43
|
#### Basic example
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Render a template value using camel case and dasherize case
|
|
46
46
|
|
|
47
47
|
```ruby
|
|
48
|
-
|
|
48
|
+
Handlebars::Helpers::Template.render('{{camel .}}', 'david was here') # => "DavidWasHere"
|
|
49
|
+
|
|
50
|
+
Handlebars::Helpers::Template.render('{{dasherize .}}', 'david was here') # => "david-was-here"
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
## Development
|
data/STORIES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Handlebars Helpers
|
|
2
2
|
|
|
3
|
-
> Handlebars Helpers is a library that provides <b>
|
|
3
|
+
> Handlebars Helpers is a library that provides <b>44</b> handlebars helpers across <b>7</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
|
4
4
|
|
|
5
5
|
As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I have a rich templating experience
|
|
6
6
|
|
data/USAGE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Handlebars Helpers
|
|
2
2
|
|
|
3
|
-
> Handlebars Helpers is a library that provides <b>
|
|
3
|
+
> Handlebars Helpers is a library that provides <b>44</b> handlebars helpers across <b>7</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
|
4
4
|
|
|
5
5
|
As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I have a rich templating experience
|
|
6
6
|
|
|
@@ -10,10 +10,10 @@ As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I h
|
|
|
10
10
|
|
|
11
11
|
#### Simple example
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Render a template value using camel case and dasherize case
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
Handlebars::Helpers::Template.render('{{camel .}}', 'david was here') # => "DavidWasHere"
|
|
17
|
+
|
|
18
|
+
Handlebars::Helpers::Template.render('{{dasherize .}}', 'david was here') # => "david-was-here"
|
|
19
19
|
```
|
|
@@ -31,6 +31,61 @@ module Handlebars
|
|
|
31
31
|
def tokenizer
|
|
32
32
|
@_tokenizer ||= Handlebars::Helpers.configuration.tokenizer
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
# This needs to be in a data_helper
|
|
36
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Style/HashEachMethods
|
|
37
|
+
def parse_json(value, hash = {})
|
|
38
|
+
return value.map { |item| parse_json(item) } if value.is_a?(V8::Array)
|
|
39
|
+
|
|
40
|
+
return struct_to_hash(value) if value.is_a?(OpenStruct)
|
|
41
|
+
|
|
42
|
+
return value unless value.is_a?(V8::Object)
|
|
43
|
+
|
|
44
|
+
value.keys.each do |key|
|
|
45
|
+
hash[key] = case value[key]
|
|
46
|
+
when V8::Object
|
|
47
|
+
parse_json(value[key])
|
|
48
|
+
when V8::Array
|
|
49
|
+
value[key].map do |item|
|
|
50
|
+
case item
|
|
51
|
+
when V8::Object, V8::Array
|
|
52
|
+
parse_json(item)
|
|
53
|
+
when String
|
|
54
|
+
item
|
|
55
|
+
else
|
|
56
|
+
item.values
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
value[key]
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
hash
|
|
65
|
+
end
|
|
66
|
+
# rubocop:enable Metrics/PerceivedComplexity, Style/HashEachMethods
|
|
67
|
+
|
|
68
|
+
# Needs to move into a GEM and make sure I have consistency
|
|
69
|
+
def struct_to_hash(data)
|
|
70
|
+
# No test yet
|
|
71
|
+
if data.is_a?(Array)
|
|
72
|
+
return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
data.each_pair.with_object({}) do |(key, value), hash|
|
|
76
|
+
case value
|
|
77
|
+
when OpenStruct
|
|
78
|
+
hash[key] = struct_to_hash(value)
|
|
79
|
+
when Array
|
|
80
|
+
# No test yet
|
|
81
|
+
values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
|
82
|
+
hash[key] = values
|
|
83
|
+
else
|
|
84
|
+
hash[key] = value
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
34
89
|
end
|
|
35
90
|
end
|
|
36
91
|
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
|
4
|
+
require 'active_support/core_ext/string'
|
|
5
|
+
|
|
6
|
+
require 'handlebars/helpers/base_safe_string_helper'
|
|
7
|
+
|
|
8
|
+
module Handlebars
|
|
9
|
+
module Helpers
|
|
10
|
+
# Miscellaneous handling routines
|
|
11
|
+
module CodeJavascript
|
|
12
|
+
# take ruby object and write it out as Javascript notation
|
|
13
|
+
class AsJavascript < Handlebars::Helpers::BaseSafeStringHelper
|
|
14
|
+
# Parse will take ruby object and write it out as Javascript notation
|
|
15
|
+
#
|
|
16
|
+
# @example
|
|
17
|
+
#
|
|
18
|
+
# puts AsJavascript.new.parse({david: "was here", why: ['reason1', 'reason2', 'reason3']})
|
|
19
|
+
#
|
|
20
|
+
# { david: "was here", why: ['reason1', 'reason2', 'reason3'] }
|
|
21
|
+
#
|
|
22
|
+
# @param [Object] value - object to be converted to Javascript notation string
|
|
23
|
+
# @return [String] value as Javascript string
|
|
24
|
+
def parse(value)
|
|
25
|
+
return '' if value.nil?
|
|
26
|
+
|
|
27
|
+
case value
|
|
28
|
+
when Hash
|
|
29
|
+
hash_to_javascript(value)
|
|
30
|
+
when OpenStruct, V8::Object, V8::Array
|
|
31
|
+
hash_to_javascript(parse_json(value))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def handlebars_helper
|
|
36
|
+
proc do |_context, value|
|
|
37
|
+
# Handle optional: value
|
|
38
|
+
# value = nil if value.is_a?(V8::Object)
|
|
39
|
+
wrapper(parse(value))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Convert ruby hash to javascript notation
|
|
44
|
+
#
|
|
45
|
+
# convert
|
|
46
|
+
# { "david": "cruwys" }
|
|
47
|
+
# to
|
|
48
|
+
# { david: "cruwys" }
|
|
49
|
+
def hash_to_javascript(value)
|
|
50
|
+
javascript = JSON.pretty_generate(value)
|
|
51
|
+
|
|
52
|
+
rex = /"(?<name>\w*)":/
|
|
53
|
+
|
|
54
|
+
javascript.gsub(rex) do |_|
|
|
55
|
+
"#{$LAST_MATCH_INFO['name']}:"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
|
4
|
+
require 'active_support/core_ext/string'
|
|
5
|
+
|
|
6
|
+
require 'handlebars/helpers/base_safe_string_helper'
|
|
7
|
+
|
|
8
|
+
module Handlebars
|
|
9
|
+
module Helpers
|
|
10
|
+
# Miscellaneous handling routines
|
|
11
|
+
module Json
|
|
12
|
+
# AsJson will take handlebars object and write it out as JSON
|
|
13
|
+
class AsJson < Handlebars::Helpers::BaseSafeStringHelper
|
|
14
|
+
# Parse will take a ruby or handlebars object and write it out as JSON
|
|
15
|
+
#
|
|
16
|
+
# @example
|
|
17
|
+
#
|
|
18
|
+
# puts AsJson.new.parse({david: "was here", why: ['reason1', 'reason2', 'reason3']})
|
|
19
|
+
#
|
|
20
|
+
# { "david": "was here", "why": ['reason1', 'reason2', 'reason3'] }
|
|
21
|
+
#
|
|
22
|
+
# @param [Object] value - object to be converted to JSON string
|
|
23
|
+
# @return [String] value as JSON string
|
|
24
|
+
def parse(value)
|
|
25
|
+
value = '' if value.nil?
|
|
26
|
+
|
|
27
|
+
value = parse_json(value).to_json if value.is_a?(Hash) || value.is_a?(OpenStruct) || value.is_a?(V8::Object) || value.is_a?(V8::Array)
|
|
28
|
+
|
|
29
|
+
value
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def handlebars_helper
|
|
33
|
+
proc do |_context, value|
|
|
34
|
+
# Handle optional: value
|
|
35
|
+
# value = nil if value.is_a?(V8::Object)
|
|
36
|
+
wrapper(parse(value))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: handlebars-helpers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.79
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Cruwys
|
|
@@ -38,7 +38,7 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: 0.8.0
|
|
41
|
-
description: Handlebars Helpers provides (
|
|
41
|
+
description: Handlebars Helpers provides (44) handlebars helpers across (7) categories
|
|
42
42
|
email:
|
|
43
43
|
- david@ideasmen.com.au
|
|
44
44
|
executables: []
|
|
@@ -75,6 +75,7 @@ files:
|
|
|
75
75
|
- lib/handlebars/helpers.rb
|
|
76
76
|
- lib/handlebars/helpers/base_helper.rb
|
|
77
77
|
- lib/handlebars/helpers/base_safe_string_helper.rb
|
|
78
|
+
- lib/handlebars/helpers/code_javascript/as_javascript.rb
|
|
78
79
|
- lib/handlebars/helpers/code_ruby/classify.rb
|
|
79
80
|
- lib/handlebars/helpers/code_ruby/deconstantize.rb
|
|
80
81
|
- lib/handlebars/helpers/code_ruby/demodulize.rb
|
|
@@ -95,7 +96,7 @@ files:
|
|
|
95
96
|
- lib/handlebars/helpers/inflection/pluralize.rb
|
|
96
97
|
- lib/handlebars/helpers/inflection/pluralize_by_number.rb
|
|
97
98
|
- lib/handlebars/helpers/inflection/singularize.rb
|
|
98
|
-
- lib/handlebars/helpers/
|
|
99
|
+
- lib/handlebars/helpers/json/as_json.rb
|
|
99
100
|
- lib/handlebars/helpers/misc/noop.rb
|
|
100
101
|
- lib/handlebars/helpers/misc/safe.rb
|
|
101
102
|
- lib/handlebars/helpers/register_helpers.rb
|
|
@@ -157,5 +158,5 @@ requirements: []
|
|
|
157
158
|
rubygems_version: 3.2.7
|
|
158
159
|
signing_key:
|
|
159
160
|
specification_version: 4
|
|
160
|
-
summary: Handlebars Helpers provides (
|
|
161
|
+
summary: Handlebars Helpers provides (44) handlebars helpers across (7) categories
|
|
161
162
|
test_files: []
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
|
4
|
-
require 'active_support/core_ext/string'
|
|
5
|
-
|
|
6
|
-
require 'handlebars/helpers/base_safe_string_helper'
|
|
7
|
-
|
|
8
|
-
module Handlebars
|
|
9
|
-
module Helpers
|
|
10
|
-
# Miscellaneous handling routines
|
|
11
|
-
module Misc
|
|
12
|
-
# Json will take handlebars object and write it out as JSON
|
|
13
|
-
class Json < Handlebars::Helpers::BaseSafeStringHelper
|
|
14
|
-
# Parse will take a ruby or handlebars object and write it out as JSON
|
|
15
|
-
#
|
|
16
|
-
# @example
|
|
17
|
-
#
|
|
18
|
-
# puts Json.new.parse({david: "was here", why: ['reason1', 'reason2', 'reason3']})
|
|
19
|
-
#
|
|
20
|
-
# { "david": "was here" }
|
|
21
|
-
#
|
|
22
|
-
# @param [Object] value - object to be converted to JSON string
|
|
23
|
-
# @return [String] value as JSON string
|
|
24
|
-
def parse(value)
|
|
25
|
-
value = '' if value.nil?
|
|
26
|
-
|
|
27
|
-
value = parse_json(value).to_json if value.is_a?(Hash) || value.is_a?(OpenStruct) || value.is_a?(V8::Object) || value.is_a?(V8::Array)
|
|
28
|
-
|
|
29
|
-
value
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def handlebars_helper
|
|
33
|
-
proc do |_context, value|
|
|
34
|
-
# Handle optional: value
|
|
35
|
-
# value = nil if value.is_a?(V8::Object)
|
|
36
|
-
wrapper(parse(value))
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
# This needs to be in a data_helper
|
|
43
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Style/HashEachMethods
|
|
44
|
-
def parse_json(value, hash = {})
|
|
45
|
-
return value.map { |item| parse_json(item) } if value.is_a?(V8::Array)
|
|
46
|
-
|
|
47
|
-
return struct_to_hash(value) if value.is_a?(OpenStruct)
|
|
48
|
-
|
|
49
|
-
return value unless value.is_a?(V8::Object)
|
|
50
|
-
|
|
51
|
-
value.keys.each do |key|
|
|
52
|
-
hash[key] = case value[key]
|
|
53
|
-
when V8::Object
|
|
54
|
-
parse_json(value[key])
|
|
55
|
-
when V8::Array
|
|
56
|
-
value[key].map do |item|
|
|
57
|
-
case item
|
|
58
|
-
when V8::Object, V8::Array
|
|
59
|
-
parse_json(item)
|
|
60
|
-
when String
|
|
61
|
-
item
|
|
62
|
-
else
|
|
63
|
-
item.values
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
else
|
|
67
|
-
value[key]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
hash
|
|
72
|
-
end
|
|
73
|
-
# rubocop:enable Metrics/PerceivedComplexity, Style/HashEachMethods
|
|
74
|
-
|
|
75
|
-
# Needs to move into a GEM and make sure I have consistency
|
|
76
|
-
def struct_to_hash(data)
|
|
77
|
-
# No test yet
|
|
78
|
-
if data.is_a?(Array)
|
|
79
|
-
return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
data.each_pair.with_object({}) do |(key, value), hash|
|
|
83
|
-
case value
|
|
84
|
-
when OpenStruct
|
|
85
|
-
hash[key] = struct_to_hash(value)
|
|
86
|
-
when Array
|
|
87
|
-
# No test yet
|
|
88
|
-
values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
|
89
|
-
hash[key] = values
|
|
90
|
-
else
|
|
91
|
-
hash[key] = value
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|