props_template 1.0.3 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31ca5a3810b9348f75dae05f2b5cb8927faaedf321a4a565914b5760968090c
4
- data.tar.gz: 6709d2fc54d81aaf2977158bffc0754089343e7aa8d32d50cbfb01a54a5b289b
3
+ metadata.gz: 9a54115d5cb581b3b4a3c487ca6bdad66a2f533a56f1171d65c9f1759ca9f2ec
4
+ data.tar.gz: d7672f8b3324ec7ae2b63e790b2c0f38e73f3b5534ad18a5e8a1704bd14c98b2
5
5
  SHA512:
6
- metadata.gz: 3d3c08391669747b2b3cecfae77e4c47893a1dd887e21ab999a56e7c5e58a3afed3ccdc8147f4bed75fe1c33a3b903975357e00b515e8f445c5f1d1fef9049bc
7
- data.tar.gz: da253f3b0d7f903ef0683990e270a1e5f4140c57416d023cce6645ac0156580a66145cc1061cf74d0f2b300d3e8e570d6bc3683d2aa2f88f5427496ddf43fbb3
6
+ metadata.gz: d07608d99ad469d3dfe6c4f264b7addb844b7a35f6a5ce2c13469bd1bd1dfa14d41c6800f62933a122d86d3ecf65a08aba95a4746d3fc329b5daf1305ec288af
7
+ data.tar.gz: b76b141b1938ebc83b40c2208c0d77274472c02615a17a0a6771147b38ac7639923b092b066333708087f2074b920e06d99e824b4b36fc9a8e4d517afb7d3f3a
@@ -63,6 +63,21 @@ module Props
63
63
  nil
64
64
  end
65
65
 
66
+ def set_value!(key, value)
67
+ if @scope == :array
68
+ raise InvalidScopeForObjError.new("Attempted to set! on an array! scope")
69
+ end
70
+
71
+ if @scope.nil?
72
+ @scope = :object
73
+ @stream.push_object
74
+ end
75
+
76
+ @stream.push_value(value, format_key(key))
77
+
78
+ nil
79
+ end
80
+
66
81
  def handle_collection_item(collection, item, index, options)
67
82
  @item_context = item
68
83
 
@@ -124,7 +139,7 @@ module Props
124
139
  [value, value]
125
140
  end
126
141
 
127
- set!(
142
+ set_value!(
128
143
  key,
129
144
  object.is_a?(Hash) ? object.fetch(attribute) : object.public_send(attribute)
130
145
  )
@@ -153,6 +168,15 @@ module Props
153
168
  @child_index = child_index
154
169
  end
155
170
 
171
+ def capture_json
172
+ parent_stream = @stream
173
+ @stream = Oj::StringWriter.new(mode: :rails)
174
+ yield
175
+ @stream.raw_json.strip
176
+ ensure
177
+ @stream = parent_stream
178
+ end
179
+
156
180
  def result!
157
181
  if @scope.nil?
158
182
  @stream.push_object
@@ -27,7 +27,7 @@ module Props
27
27
  end
28
28
 
29
29
  def set_content!(options = {})
30
- return super if !@em.has_extensions(options)
30
+ return super if options.empty? || !@em.has_extensions(options)
31
31
 
32
32
  @em.handle(options, item_context) do
33
33
  yield
@@ -70,22 +70,16 @@ module Props
70
70
 
71
71
  def handle_cache(options, item)
72
72
  if options[:cache]
73
- recently_cached = false
74
-
75
73
  key, rest = Cache
76
74
  .normalize_options(options[:cache], item)
75
+
76
+ # A miss renders into a writer of its own, so its JSON is added to
77
+ # the output below like a hit's.
77
78
  state = @cache.cache(key, rest) do
78
- recently_cached = true
79
79
  result = nil
80
- start = base.stream.to_s.length
81
80
  base.scoped_state { |stream, deferred_paths, fragment_paths|
82
- yield
81
+ raw = base.capture_json { yield }
83
82
  meta = Oj.dump([deferred_paths, fragment_paths]).strip
84
- json_in_progress = base.stream.to_s
85
- if json_in_progress[start] == ","
86
- start += 1
87
- end
88
- raw = base.stream.to_s[start..].strip
89
83
  result = "#{meta}\n#{raw}"
90
84
  }
91
85
  result
@@ -96,9 +90,7 @@ module Props
96
90
  deferred.push(*next_deferred)
97
91
  fragments.push(*next_fragments)
98
92
 
99
- if !recently_cached
100
- base.stream.push_json(raw_json)
101
- end
93
+ base.stream.push_json(raw_json)
102
94
  else
103
95
  yield
104
96
  end
@@ -46,6 +46,10 @@ module Props
46
46
  yield
47
47
  end
48
48
 
49
+ def set_value!(key, value)
50
+ nil
51
+ end
52
+
49
53
  def set!(key, options = {}, &block)
50
54
  return if @found_block || !block && !options.is_a?(Props::Options)
51
55
 
@@ -1,3 +1,3 @@
1
1
  module Props
2
- VERSION = "1.0.3".freeze
2
+ VERSION = "1.1.1".freeze
3
3
  end
@@ -67,8 +67,10 @@ module Props
67
67
  @builder.item_context = found_item
68
68
  set!(key, found_options, &found_block)
69
69
  end
70
- else
70
+ elsif block || options.is_a?(Props::Options)
71
71
  @builder.set!(key, options, &block)
72
+ else
73
+ @builder.set_value!(key, options)
72
74
  end
73
75
  end
74
76
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: props_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho