handlebars-helpers 0.0.74 → 0.0.81

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: f70bb20a653e2c9a3e01812c77aae7cdf0ee5709a359bbb4d3243ebcc440d9a4
4
- data.tar.gz: b20c4836771738ea1cd86e0cdaf91af8be97ddf99e87f34b001a5bf9f78d7d2e
3
+ metadata.gz: d83a1d35d176cf5af7dc32206a7284fd49592daaf4b9d180f71d894f8ac270e2
4
+ data.tar.gz: d9dd469c0a6a55266f0783d656b905432c8d81ce0ce8f56b8818f421fae887e6
5
5
  SHA512:
6
- metadata.gz: 799126c7777513d5390f31a6d9a214b317e7763caf48f784ea395e9c30a5a2eb18a854eab68626d24352c464f293d2b21415462aca6e969e46af82fee94c0720
7
- data.tar.gz: eabc9896fc354ad324b9c7b0451ebf5bb6146685a6d544b49fee63bd286f83621ecacb737c299f2af1f465153d0a717e8c90b90d3b57c207713399b737c2419f
6
+ metadata.gz: '02066321193e16b5e17dedc77f537cd364c7ccd596ed24aa57a7a4df4819d0818303e5a5a8e236ea35ed2c48186f7ba862db7ea26a540e88a810c013ea78a700'
7
+ data.tar.gz: fbe2b160cdc4f3925e507c06cc2f8c43253baebf6a6314c85a806c7f649bee73198b974220ba854cd83e6a7ec262c970ecc8cee78a58faf6a906bf9e03b4671e
@@ -21,8 +21,8 @@
21
21
  "alias": "default",
22
22
  "expected_value": "hello world",
23
23
  "params": [
24
- { "name": "p1", "value": null },
25
- { "name": "p2", "value": null }
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", "value": null },
46
- { "name": "p2", "value": "param2" }
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", "value": null },
55
- { "name": "p2", "value": "param2" }
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", "value": "param1" },
76
- { "name": "p2", "value": "param2" }
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", "value": "param1" },
85
- { "name": "p2", "value": "param2" }
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", "value": "david" },
106
- { "name": "p2", "value": "david" }
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", "value": "david" },
115
- { "name": "p2", "value": "david" }
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", "value": "aaa" },
136
- { "name": "p2", "value": "bbb" }
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", "value": "aaa" },
145
- { "name": "p2", "value": "bbb" }
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", "value": 1 },
166
- { "name": "p2", "value": 2 }
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", "value": 1 },
175
- { "name": "p2", "value": 2 }
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", "value": 1 },
196
- { "name": "p2", "value": 1 }
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", "value": 1 },
205
- { "name": "p2", "value": 1 }
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", "value": 2 },
226
- { "name": "p2", "value": 1 }
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", "value": 2 },
235
- { "name": "p2", "value": 1 }
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", "value": 1 },
256
- { "name": "p2", "value": 1 }
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", "value": 1 },
265
- { "name": "p2", "value": 1 }
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", "value": "person" },
321
- { "name": "count", "value": "3" },
322
- { "name": "format", "value": "number_word" }
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
  }
@@ -373,7 +373,7 @@
373
373
  {
374
374
  "alias": "safe",
375
375
  "expected_value": "\"hello\"",
376
- "params": [{ "name": "value", "value": "\"hello\"" }],
376
+ "params": [{ "name": "value", "string_value": "\"hello\"" }],
377
377
  "template": "{{safe value}}"
378
378
  }
379
379
  ],
@@ -429,7 +429,7 @@
429
429
  "alias": "classify",
430
430
  "expected_value": "ProductCategory",
431
431
  "params": [
432
- { "name": "table_name", "value": "product_categories" }
432
+ { "name": "table_name", "string_value": "product_categories" }
433
433
  ],
434
434
  "template": "{{classify table_name}}"
435
435
  }
@@ -451,7 +451,7 @@
451
451
  "params": [
452
452
  {
453
453
  "name": "namespaced_class",
454
- "value": "ActiveSupport::Inflector::Inflections"
454
+ "string_value": "ActiveSupport::Inflector::Inflections"
455
455
  }
456
456
  ],
457
457
  "template": "{{demodulize namespaced_class}}"
@@ -472,7 +472,7 @@
472
472
  "alias": "deconstantize",
473
473
  "expected_value": "Net",
474
474
  "params": [
475
- { "name": "constant_expression", "value": "Net::HTTP" }
475
+ { "name": "constant_expression", "string_value": "Net::HTTP" }
476
476
  ],
477
477
  "template": "{{deconstantize constant_expression}}"
478
478
  }
@@ -491,7 +491,7 @@
491
491
  {
492
492
  "alias": "foreign_key",
493
493
  "expected_value": "message_id",
494
- "params": [{ "name": "class_name", "value": "Message" }],
494
+ "params": [{ "name": "class_name", "string_value": "Message" }],
495
495
  "template": "{{foreign_key class_name}}"
496
496
  }
497
497
  ],
@@ -509,7 +509,9 @@
509
509
  {
510
510
  "alias": "tableize",
511
511
  "expected_value": "product_categories",
512
- "params": [{ "name": "model_name", "value": "product_category" }],
512
+ "params": [
513
+ { "name": "model_name", "string_value": "product_category" }
514
+ ],
513
515
  "template": "{{tableize model_name}}"
514
516
  }
515
517
  ],
@@ -538,8 +540,8 @@
538
540
  "alias": "format_as",
539
541
  "expected_value": "the-quick-brown-foxes",
540
542
  "params": [
541
- { "name": "value", "value": "the quick brown fox" },
542
- { "name": "format", "value": "pluralize,dashify" }
543
+ { "name": "value", "string_value": "the quick brown fox" },
544
+ { "name": "format", "string_value": "pluralize,dashify" }
543
545
  ],
544
546
  "template": "{{format_as value format}}"
545
547
  }
@@ -755,9 +757,9 @@
755
757
  "alias": "padr",
756
758
  "expected_value": "pad-me....",
757
759
  "params": [
758
- { "name": "value", "value": "pad-me" },
759
- { "name": "count", "value": 10 },
760
- { "name": "char", "value": "." }
760
+ { "name": "value", "string_value": "pad-me" },
761
+ { "name": "count", "string_value": 10 },
762
+ { "name": "char", "string_value": "." }
761
763
  ],
762
764
  "template": "{{padr value count char}}"
763
765
  },
@@ -765,9 +767,9 @@
765
767
  "alias": "pad_right",
766
768
  "expected_value": "pad-me....",
767
769
  "params": [
768
- { "name": "value", "value": "pad-me" },
769
- { "name": "count", "value": 10 },
770
- { "name": "char", "value": "." }
770
+ { "name": "value", "string_value": "pad-me" },
771
+ { "name": "count", "string_value": 10 },
772
+ { "name": "char", "string_value": "." }
771
773
  ],
772
774
  "template": "{{pad_right value count char}}"
773
775
  },
@@ -775,9 +777,9 @@
775
777
  "alias": "ljust",
776
778
  "expected_value": "pad-me....",
777
779
  "params": [
778
- { "name": "value", "value": "pad-me" },
779
- { "name": "count", "value": 10 },
780
- { "name": "char", "value": "." }
780
+ { "name": "value", "string_value": "pad-me" },
781
+ { "name": "count", "string_value": 10 },
782
+ { "name": "char", "string_value": "." }
781
783
  ],
782
784
  "template": "{{ljust value count char}}"
783
785
  }
@@ -797,9 +799,9 @@
797
799
  "alias": "padl",
798
800
  "expected_value": "....pad-me",
799
801
  "params": [
800
- { "name": "value", "value": "pad-me" },
801
- { "name": "count", "value": 10 },
802
- { "name": "char", "value": "." }
802
+ { "name": "value", "string_value": "pad-me" },
803
+ { "name": "count", "string_value": 10 },
804
+ { "name": "char", "string_value": "." }
803
805
  ],
804
806
  "template": "{{padl value count char}}"
805
807
  },
@@ -807,9 +809,9 @@
807
809
  "alias": "pad_left",
808
810
  "expected_value": "....pad-me",
809
811
  "params": [
810
- { "name": "value", "value": "pad-me" },
811
- { "name": "count", "value": 10 },
812
- { "name": "char", "value": "." }
812
+ { "name": "value", "string_value": "pad-me" },
813
+ { "name": "count", "string_value": 10 },
814
+ { "name": "char", "string_value": "." }
813
815
  ],
814
816
  "template": "{{pad_left value count char}}"
815
817
  },
@@ -817,9 +819,9 @@
817
819
  "alias": "rjust",
818
820
  "expected_value": "....pad-me",
819
821
  "params": [
820
- { "name": "value", "value": "pad-me" },
821
- { "name": "count", "value": 10 },
822
- { "name": "char", "value": "." }
822
+ { "name": "value", "string_value": "pad-me" },
823
+ { "name": "count", "string_value": 10 },
824
+ { "name": "char", "string_value": "." }
823
825
  ],
824
826
  "template": "{{rjust value count char}}"
825
827
  }
@@ -839,9 +841,9 @@
839
841
  "alias": "prepend_if",
840
842
  "expected_value": "# product_categories",
841
843
  "params": [
842
- { "name": "value", "value": "product category" },
843
- { "name": "prefix", "value": "# " },
844
- { "name": "formats", "value": "pluralize,snake" }
844
+ { "name": "value", "string_value": "product category" },
845
+ { "name": "prefix", "string_value": "# " },
846
+ { "name": "formats", "string_value": "pluralize,snake" }
845
847
  ],
846
848
  "template": "{{prepend_if value prefix formats}}"
847
849
  },
@@ -849,9 +851,9 @@
849
851
  "alias": "prefix_if",
850
852
  "expected_value": "# product_categories",
851
853
  "params": [
852
- { "name": "value", "value": "product category" },
853
- { "name": "prefix", "value": "# " },
854
- { "name": "formats", "value": "pluralize,snake" }
854
+ { "name": "value", "string_value": "product category" },
855
+ { "name": "prefix", "string_value": "# " },
856
+ { "name": "formats", "string_value": "pluralize,snake" }
855
857
  ],
856
858
  "template": "{{prefix_if value prefix formats}}"
857
859
  }
@@ -871,9 +873,9 @@
871
873
  "alias": "append_if",
872
874
  "expected_value": "product_categories:",
873
875
  "params": [
874
- { "name": "value", "value": "product category" },
875
- { "name": "suffix", "value": ":" },
876
- { "name": "formats", "value": "pluralize,snake" }
876
+ { "name": "value", "string_value": "product category" },
877
+ { "name": "suffix", "string_value": ":" },
878
+ { "name": "formats", "string_value": "pluralize,snake" }
877
879
  ],
878
880
  "template": "{{append_if value suffix formats}}"
879
881
  },
@@ -881,9 +883,9 @@
881
883
  "alias": "suffix_if",
882
884
  "expected_value": "product_categories:",
883
885
  "params": [
884
- { "name": "value", "value": "product category" },
885
- { "name": "suffix", "value": ":" },
886
- { "name": "formats", "value": "pluralize,snake" }
886
+ { "name": "value", "string_value": "product category" },
887
+ { "name": "suffix", "string_value": ":" },
888
+ { "name": "formats", "string_value": "pluralize,snake" }
887
889
  ],
888
890
  "template": "{{suffix_if value suffix formats}}"
889
891
  }
@@ -903,10 +905,10 @@
903
905
  "alias": "surround_if",
904
906
  "expected_value": "(product_categories)",
905
907
  "params": [
906
- { "name": "value", "value": "product category" },
907
- { "name": "prefix", "value": "(" },
908
- { "name": "suffix", "value": ")" },
909
- { "name": "formats", "value": "pluralize,snake" }
908
+ { "name": "value", "string_value": "product category" },
909
+ { "name": "prefix", "string_value": "(" },
910
+ { "name": "suffix", "string_value": ")" },
911
+ { "name": "formats", "string_value": "pluralize,snake" }
910
912
  ],
911
913
  "template": "{{surround_if value prefix suffix formats}}"
912
914
  },
@@ -914,10 +916,10 @@
914
916
  "alias": "surround_if_value",
915
917
  "expected_value": "(product_categories)",
916
918
  "params": [
917
- { "name": "value", "value": "product category" },
918
- { "name": "prefix", "value": "(" },
919
- { "name": "suffix", "value": ")" },
920
- { "name": "formats", "value": "pluralize,snake" }
919
+ { "name": "value", "string_value": "product category" },
920
+ { "name": "prefix", "string_value": "(" },
921
+ { "name": "suffix", "string_value": ")" },
922
+ { "name": "formats", "string_value": "pluralize,snake" }
921
923
  ],
922
924
  "template": "{{surround_if_value value prefix suffix formats}}"
923
925
  }
@@ -937,10 +939,10 @@
937
939
  "alias": "surround",
938
940
  "expected_value": "()",
939
941
  "params": [
940
- { "name": "value", "value": null },
941
- { "name": "prefix", "value": "(" },
942
- { "name": "suffix", "value": ")" },
943
- { "name": "formats", "value": "" }
942
+ { "name": "value", "nil_value": true },
943
+ { "name": "prefix", "string_value": "(" },
944
+ { "name": "suffix", "string_value": ")" },
945
+ { "name": "formats", "nil_value": true }
944
946
  ],
945
947
  "template": "{{surround value prefix suffix formats}}"
946
948
  }
@@ -951,6 +953,83 @@
951
953
  "is_string_formatter": null
952
954
  }
953
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
+ ]
954
1033
  }
955
1034
  ]
956
1035
  }
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Handlebars Helpers
2
2
 
3
- > Handlebars Helpers is a library that provides <b>42</b> handlebars helpers across <b>5</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
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
- Description for a basic example to be featured in the main README.MD file
45
+ Render a template value using camel case and dasherize case
46
46
 
47
47
  ```ruby
48
- class SomeRuby; end
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>42</b> handlebars helpers across <b>5</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
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>42</b> handlebars helpers across <b>5</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
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
- Description for a simple example that shows up in the USAGE.MD
13
+ Render a template value using camel case and dasherize case
14
14
 
15
15
  ```ruby
16
- class SomeRuby
17
- def initialize; end
18
- end
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
  ```
@@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
36
36
  end
37
37
  end
38
38
 
39
- spec.files.each do |file|
40
- puts file
41
- end
39
+ # spec.files.each do |file|
40
+ # puts file
41
+ # end
42
42
  spec.bindir = 'exe'
43
43
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
44
44
  spec.require_paths = ['lib']
@@ -47,10 +47,10 @@ Gem::Specification.new do |spec|
47
47
  spec.rdoc_options += [
48
48
  '--title', 'handlebars-helpers by appydave.com',
49
49
  '--main', 'README.md',
50
- '--files', 'STORIES.MD USAGE.MD'
50
+ '--files STORIES.MD USAGE.MD'
51
51
  ]
52
52
 
53
53
  # spec.add_dependency 'tty-box', '~> 0.5.0'
54
- spec.add_dependency 'activesupport'
55
- spec.add_dependency 'handlebars'
54
+ spec.add_dependency 'activesupport' , '~> 6'
55
+ spec.add_dependency 'handlebars' , '~> 0.8.0'
56
56
  end
@@ -3,6 +3,8 @@
3
3
  require 'handlebars/helpers/version'
4
4
  require 'handlebars/helpers/template'
5
5
  require 'handlebars/helpers/register_helpers'
6
+ # ruby docs is not showing all classes because
7
+ # this gem dynamically loads the classes for performance reasons
6
8
 
7
9
  module Handlebars
8
10
  module Helpers
@@ -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,72 @@
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, format)
25
+ return '' if value.nil?
26
+
27
+ format = :include_root_brace if format.nil?
28
+
29
+ javascript = case value
30
+ when Hash
31
+ hash_to_javascript(value)
32
+ when OpenStruct, V8::Object, V8::Array
33
+ hash_to_javascript(parse_json(value))
34
+ end
35
+
36
+ javascript = remove_root_brace(javascript) if format == :exclude_root
37
+ javascript
38
+ end
39
+
40
+ def handlebars_helper
41
+ proc do |_context, value, format|
42
+ # Handle optional: format
43
+ format = nil if format.is_a?(V8::Object)
44
+ format = format.to_sym if format.is_a?(String)
45
+
46
+ wrapper(parse(value, format))
47
+ end
48
+ end
49
+
50
+ # Convert ruby hash to javascript notation
51
+ #
52
+ # convert
53
+ # { "david": "cruwys" }
54
+ # to
55
+ # { david: "cruwys" }
56
+ def hash_to_javascript(value)
57
+ javascript = JSON.pretty_generate(value)
58
+
59
+ rex = /"(?<name>\w*)":/
60
+
61
+ javascript.gsub(rex) do |_|
62
+ "#{$LAST_MATCH_INFO['name']}:"
63
+ end
64
+ end
65
+
66
+ def remove_root_brace(javascript)
67
+ javascript.sub('{', '').tap { |s| s.slice!(s.rindex('}')) }.strip
68
+ end
69
+ end
70
+ end
71
+ end
72
+ 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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Handlebars
4
+ module Helpers
5
+ HANDLER_COUNT = 44
6
+
7
+ CATEGORY_COUNT = 7
8
+ end
9
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Handlebars
4
4
  module Helpers
5
- VERSION = '0.0.74'
5
+ VERSION = '0.0.81'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,44 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.74
4
+ version: 0.0.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-14 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: handlebars
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Handlebars Helpers provides (42) handlebars helpers across (5) categories
40
+ version: 0.8.0
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,9 +96,11 @@ 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
99
+ - lib/handlebars/helpers/json/as_json.rb
98
100
  - lib/handlebars/helpers/misc/noop.rb
99
101
  - lib/handlebars/helpers/misc/safe.rb
100
102
  - lib/handlebars/helpers/register_helpers.rb
103
+ - lib/handlebars/helpers/statistics.rb
101
104
  - lib/handlebars/helpers/string_formatting/append_if.rb
102
105
  - lib/handlebars/helpers/string_formatting/back_slash.rb
103
106
  - lib/handlebars/helpers/string_formatting/camel.rb
@@ -138,8 +141,7 @@ rdoc_options:
138
141
  - handlebars-helpers by appydave.com
139
142
  - "--main"
140
143
  - README.md
141
- - "--files"
142
- - STORIES.MD USAGE.MD
144
+ - "--files STORIES.MD USAGE.MD"
143
145
  require_paths:
144
146
  - lib
145
147
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -156,5 +158,5 @@ requirements: []
156
158
  rubygems_version: 3.2.7
157
159
  signing_key:
158
160
  specification_version: 4
159
- summary: Handlebars Helpers provides (42) handlebars helpers across (5) categories
161
+ summary: Handlebars Helpers provides (44) handlebars helpers across (7) categories
160
162
  test_files: []