handlebars-helpers 0.0.79 → 0.0.80

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: c57a2d3c8e0e593b9ae2a628d3ae139ffeb6b0989afc174ee41875a2ec38bc72
4
- data.tar.gz: d7e9a3ba1fe17a5e1ae0a56322f571db878a08dae402b906ec1733980fcb7efa
3
+ metadata.gz: 39509c73f11207c3e1d83f13c505597b78e5a168d724e5d71295f95d1ec48fbc
4
+ data.tar.gz: 7e185664a22428731c2512b6a576d82784ae0f16f218fe22b34117639f7475aa
5
5
  SHA512:
6
- metadata.gz: 49c1b409299678aac9b74a5c2c8580d79d85c8f621ae20dff140b483e013227916f2ff5928012f07fe0ac31eddc6d94c236d7decf574a04f82e6cca3f1c3b078
7
- data.tar.gz: 92766053b2ca98b64b7f7c9181134d941fde107d283cf2e9eb1ab74b28f8d6346301f25c3d6a7ab6bef3b6f1eef096ac49aeb49dba12b9c3edf478f969767368
6
+ metadata.gz: b285b313b078c81cbd76e5b68fb43c6c7ed2f0c81e39dd3b18adb623d4629ab7396cf2a068cc51fe3380c5a26a4cd85856fd1ba81ae6692409a3add7699cabac
7
+ data.tar.gz: 7b89009b0db7dae0e635fa09d0f7b362bd15b17850db9548a07b891784bb11f0f3fcd6da703347d82473f27187ff8c765c7a491d783283c64ce3eb79ad41bb70
@@ -21,22 +21,29 @@ module Handlebars
21
21
  #
22
22
  # @param [Object] value - object to be converted to Javascript notation string
23
23
  # @return [String] value as Javascript string
24
- def parse(value)
24
+ def parse(value, format)
25
25
  return '' if value.nil?
26
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
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
33
38
  end
34
39
 
35
40
  def handlebars_helper
36
- proc do |_context, value|
41
+ proc do |_context, value, format|
42
+ # Handle optional: format
43
+ format = nil if format.is_a?(V8::Object)
37
44
  # Handle optional: value
38
45
  # value = nil if value.is_a?(V8::Object)
39
- wrapper(parse(value))
46
+ wrapper(parse(value, format))
40
47
  end
41
48
  end
42
49
 
@@ -55,6 +62,10 @@ module Handlebars
55
62
  "#{$LAST_MATCH_INFO['name']}:"
56
63
  end
57
64
  end
65
+
66
+ def remove_root_brace(javascript)
67
+ javascript.sub('{', '').tap { |s| s.slice!(s.rindex('}')) }.strip
68
+ end
58
69
  end
59
70
  end
60
71
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Handlebars
4
4
  module Helpers
5
- VERSION = '0.0.79'
5
+ VERSION = '0.0.80'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.79
4
+ version: 0.0.80
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-03-02 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