handlebars-helpers 0.0.72 → 0.0.79

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: ae3c2a971cab0fcd668bc00d5270a1068936fb8dafdfe2b28d3848b5ea259fbf
4
- data.tar.gz: cb50609e529b575aa566f60f06dc1ea8250dc31827f8db10fd2a19938a82453f
3
+ metadata.gz: c57a2d3c8e0e593b9ae2a628d3ae139ffeb6b0989afc174ee41875a2ec38bc72
4
+ data.tar.gz: d7e9a3ba1fe17a5e1ae0a56322f571db878a08dae402b906ec1733980fcb7efa
5
5
  SHA512:
6
- metadata.gz: ce7f92f4ea322405411429818be48de69615bdab44679c403c8ba40c437111b5ae729b3e33d3d095749923e6704a83ed91144e1da201898a44490ef1e16f0d46
7
- data.tar.gz: 745be404fd84830dd31db42be2ae879651d74797e4d1a54b2552af86afd7b7dedd36e6fe7dcaa2a79bc88c3830f1b26b8e96a47929bf0dd1fdc278a6a5126ac2
6
+ metadata.gz: 49c1b409299678aac9b74a5c2c8580d79d85c8f621ae20dff140b483e013227916f2ff5928012f07fe0ac31eddc6d94c236d7decf574a04f82e6cca3f1c3b078
7
+ data.tar.gz: 92766053b2ca98b64b7f7c9181134d941fde107d283cf2e9eb1ab74b28f8d6346301f25c3d6a7ab6bef3b6f1eef096ac49aeb49dba12b9c3edf478f969767368
@@ -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>$HELPER_COUNT$</b> handlebars helpers across <b>$HELPER_CATEGORY_COUNT$</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
@@ -77,7 +79,7 @@ To release a new version, update the version number in `version.rb`, build the g
77
79
  gem build
78
80
  gem push rspec-usecases-?.?.??.gem
79
81
  # or push the latest gem
80
- ls handlebars-helpers*.gem | sort -r | head -1 | xargs gem push
82
+ ls *.gem | sort -r | head -1 | xargs gem push
81
83
  ```
82
84
 
83
85
  ## Contributing
data/STORIES.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Handlebars Helpers
2
2
 
3
- > Handlebars Helpers is a library that provides <b>5</b> handlebars helpers across <b>42</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>5</b> handlebars helpers across <b>42</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
  ```
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'lib/handlebars/helpers/version'
4
+ require_relative 'lib/handlebars/helpers/statistics'
4
5
 
5
6
  Gem::Specification.new do |spec|
7
+ description = "Handlebars Helpers provides (#{Handlebars::Helpers::HANDLER_COUNT}) handlebars helpers across (#{Handlebars::Helpers::CATEGORY_COUNT}) categories"
8
+
6
9
  spec.required_ruby_version = '>= 2.5'
7
10
  spec.name = 'handlebars-helpers'
8
11
  spec.version = Handlebars::Helpers::VERSION
9
12
  spec.authors = ['David Cruwys']
10
13
  spec.email = ['david@ideasmen.com.au']
11
14
 
12
- spec.summary = 'Handlebars Helpers provides (Nx) handlebars helpers across (Ny) categories'
13
- spec.description = <<-TEXT
14
- Handlebars Helpers provides (Nx) handlebars helpers across (Ny) categories
15
- TEXT
15
+ spec.summary = description
16
+ spec.description = description
16
17
  spec.homepage = 'http://appydave.com/gems/handlebars-helpers'
17
18
  spec.license = 'MIT'
18
19
 
@@ -25,6 +26,7 @@ Gem::Specification.new do |spec|
25
26
  spec.metadata['homepage_uri'] = spec.homepage
26
27
  spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/handlebars-helpers'
27
28
  spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/handlebars-helpers/commits/master'
29
+ spec.metadata['documentation_uri'] = 'https://rubydoc.info/github/klueless-io/handlebars-helpers/master'
28
30
 
29
31
  # Specify which files should be added to the gem when it is released.
30
32
  # The `git ls-files -z` loads the RubyGem files that have been added into git.
@@ -33,6 +35,10 @@ Gem::Specification.new do |spec|
33
35
  f.match(%r{^(test|spec|features)/})
34
36
  end
35
37
  end
38
+
39
+ # spec.files.each do |file|
40
+ # puts file
41
+ # end
36
42
  spec.bindir = 'exe'
37
43
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
44
  spec.require_paths = ['lib']
@@ -41,10 +47,10 @@ Gem::Specification.new do |spec|
41
47
  spec.rdoc_options += [
42
48
  '--title', 'handlebars-helpers by appydave.com',
43
49
  '--main', 'README.md',
44
- '--files', 'STORIES.MD USAGE.MD'
50
+ '--files STORIES.MD USAGE.MD'
45
51
  ]
46
52
 
47
53
  # spec.add_dependency 'tty-box', '~> 0.5.0'
48
- spec.add_dependency 'activesupport'
49
- spec.add_dependency 'handlebars'
54
+ spec.add_dependency 'activesupport' , '~> 6'
55
+ spec.add_dependency 'handlebars' , '~> 0.8.0'
50
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,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
@@ -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.72'
5
+ VERSION = '0.0.79'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,45 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.72
4
+ version: 0.0.79
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-02 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 (Nx) handlebars helpers across (Ny)
42
- categories\n"
40
+ version: 0.8.0
41
+ description: Handlebars Helpers provides (44) handlebars helpers across (7) categories
43
42
  email:
44
43
  - david@ideasmen.com.au
45
44
  executables: []
@@ -76,6 +75,7 @@ files:
76
75
  - lib/handlebars/helpers.rb
77
76
  - lib/handlebars/helpers/base_helper.rb
78
77
  - lib/handlebars/helpers/base_safe_string_helper.rb
78
+ - lib/handlebars/helpers/code_javascript/as_javascript.rb
79
79
  - lib/handlebars/helpers/code_ruby/classify.rb
80
80
  - lib/handlebars/helpers/code_ruby/deconstantize.rb
81
81
  - lib/handlebars/helpers/code_ruby/demodulize.rb
@@ -96,9 +96,11 @@ files:
96
96
  - lib/handlebars/helpers/inflection/pluralize.rb
97
97
  - lib/handlebars/helpers/inflection/pluralize_by_number.rb
98
98
  - lib/handlebars/helpers/inflection/singularize.rb
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
103
+ - lib/handlebars/helpers/statistics.rb
102
104
  - lib/handlebars/helpers/string_formatting/append_if.rb
103
105
  - lib/handlebars/helpers/string_formatting/back_slash.rb
104
106
  - lib/handlebars/helpers/string_formatting/camel.rb
@@ -132,14 +134,14 @@ metadata:
132
134
  homepage_uri: http://appydave.com/gems/handlebars-helpers
133
135
  source_code_uri: https://github.com/klueless-io/handlebars-helpers
134
136
  changelog_uri: https://github.com/klueless-io/handlebars-helpers/commits/master
137
+ documentation_uri: https://rubydoc.info/github/klueless-io/handlebars-helpers/master
135
138
  post_install_message:
136
139
  rdoc_options:
137
140
  - "--title"
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 (Nx) handlebars helpers across (Ny) categories
161
+ summary: Handlebars Helpers provides (44) handlebars helpers across (7) categories
160
162
  test_files: []