breezy_template 0.9.0 → 0.10.1

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
  SHA1:
3
- metadata.gz: da144588b56af534e34e76bb6b3485b80aea270e
4
- data.tar.gz: 3acda36705e7044799381005fb13137993ac4c2b
3
+ metadata.gz: 196103d517bfc16643b1bc270edf634b9ec60d72
4
+ data.tar.gz: 7af3f57a2e858036f9b9a45051e2816539b45a52
5
5
  SHA512:
6
- metadata.gz: 03cc588d52178c4c6c2b31c2213be5c448d7cd06510575cf7135e3e6bfb89748616737d182d164fc96f04cfebd83a54c3cadb22a2402e0cef105fb37d8b98f36
7
- data.tar.gz: 6fff2ab23c9078831fbda468e9d96a810afc5a0a70e3eda461f6e0b85a378fa20de81017229f58c9a8e5934eb967895b01622a148c8cb7b481b4caebfe8d71d5
6
+ metadata.gz: 0227c106472a3e605ebfbe4cafd22392ad93d70ffbf79a0fadfe12814e3741c6ce01256486620a36fb06361ae01e13066399fce8242b485a1b981ea95db366e8
7
+ data.tar.gz: f9e1d92f429733c66db0d76307111ee388af65c697a3484a76e6a6a9886c174373f80c585aaba48c99e115eda9d0f3c721906716a1c2e3627c2f0ab731d98857
@@ -2,6 +2,7 @@ require 'breezy_template/breezy_template'
2
2
 
3
3
  require 'breezy_template/blank'
4
4
  require 'breezy_template/var'
5
+ require 'breezy_template/key_formatter'
5
6
  require 'breezy_template/errors'
6
7
 
7
8
  require 'breezy_template/active_support'
@@ -39,9 +40,10 @@ class BreezyTemplate
39
40
  @context = context
40
41
  @js = []
41
42
  @path = []
42
- @joints = {}
43
+ @fragments = {}
43
44
 
44
45
  @attributes = {}
46
+ @key_formatter = KeyFormatter.new({camelize: :lower})
45
47
  @ignore_nil = options.fetch(:ignore_nil, @@ignore_nil)
46
48
 
47
49
  yield self if ::Kernel.block_given?
@@ -176,7 +178,7 @@ class BreezyTemplate
176
178
  js = _breezy_return(@attributes)
177
179
 
178
180
  @js.push(js)
179
- "(function(){var joints={};var cache={};var defers=[];#{@js.join}})()"
181
+ "(function(){var fragments={};var lastFragmentName;var lastFragmentPath;var cache={};var defers=[];#{@js.join}})()"
180
182
  end
181
183
 
182
184
  # Merges hash or array into current builder.
@@ -211,7 +213,7 @@ class BreezyTemplate
211
213
  end
212
214
 
213
215
  def _key(key)
214
- key.to_s
216
+ @key_formatter ? @key_formatter.format(key) : key.to_s
215
217
  end
216
218
 
217
219
  def _set_value(key, value)
@@ -249,12 +251,12 @@ class BreezyTemplate
249
251
  end
250
252
 
251
253
  def _scope
252
- parent_attributes = @attributes
254
+ parent_attributes, parent_formatter = @attributes, @key_formatter
253
255
  @attributes = BLANK
254
256
  yield
255
257
  @attributes
256
258
  ensure
257
- @attributes = parent_attributes
259
+ @attributes, @key_formatter = parent_attributes, parent_formatter
258
260
  end
259
261
 
260
262
  def _is_collection?(object)
@@ -35,8 +35,8 @@ class BreezyTemplate
35
35
  _deferment_options(options) == :auto
36
36
  end
37
37
 
38
- def _set_request_url(request_path)
39
- @request_path = request_path
38
+ def _set_request_url_once(request_path)
39
+ @request_path ||= request_path
40
40
  end
41
41
 
42
42
  def _extended_options?(value)
@@ -45,12 +45,23 @@ class BreezyTemplate
45
45
 
46
46
  def _mapping_element(element, options)
47
47
  if _deferment_options?(options)
48
+ if ::Proc === _deferment_options(options)
49
+ value = _deferment_options(options).call(element)
50
+ options = options.dup.merge({defer: value})
51
+ end
52
+ end
53
+
54
+ if _deferment_options?(options)
55
+ if _deferment_auto?(options)
56
+ @js.push(_breezy_visit_current(@path))
57
+ end
58
+
48
59
  if options.has_key? :key
49
60
  id_name = options[:key]
50
61
  id_val = element[id_name]
51
62
  ::Hash[id_name, id_val]
52
63
  else
53
- nil
64
+ ::BreezyTemplate::Var.new('undefined')
54
65
  end
55
66
  else
56
67
  super
@@ -11,10 +11,9 @@ class BreezyTemplate
11
11
 
12
12
  def self.call(template)
13
13
  # this juggling is required to keep line numbers right in the error
14
- %{__already_defined = defined?(json); json||=::BreezyTemplate.new(self);json._filter_by_path(breezy_filter) if defined?(breezy_filter); json._set_request_url(request.path);#{template.source}
14
+ %{__already_defined = defined?(json);json||=::BreezyTemplate.new(self);json._set_search_path_once(breezy_filter) if defined?(breezy_filter); json._set_request_url_once(request.fullpath);#{template.source}
15
15
  if !(__already_defined && __already_defined != "method")
16
16
  json.merge!({data: json._found! || json.empty! })
17
-
18
17
  json.set! :screen, '#{self.template_id(template)}'
19
18
 
20
19
  if defined?(breezy) && breezy
@@ -23,32 +22,49 @@ class BreezyTemplate
23
22
  end
24
23
  end
25
24
 
26
- if protect_against_forgery?
27
- json.csrf_token form_authenticity_token
28
- end
25
+ json.fragments ::BreezyTemplate::Var.new('fragments')
29
26
 
30
- __sprockets_assets = (::BreezyTemplate.configuration.track_sprockets_assets || []).map do |asset|
31
- asset_path(asset)
32
- end
27
+ json.private_opts do
28
+ if protect_against_forgery?
29
+ json.csrf_token form_authenticity_token
30
+ end
33
31
 
34
- __pack_assets = []
35
- if defined?(asset_pack_path)
36
- __pack_assets = (::BreezyTemplate.configuration.track_pack_assets || []).map do |asset|
37
- asset_pack_path(asset)
32
+ __sprockets_assets = (::BreezyTemplate.configuration.track_sprockets_assets || []).map do |asset|
33
+ asset_path(asset)
38
34
  end
39
- end
40
35
 
41
- if __sprockets_assets.any? || __pack_assets.any?
42
- json.assets (__sprockets_assets + __pack_assets)
43
- end
36
+ __pack_assets = []
37
+ if defined?(asset_pack_path)
38
+ __pack_assets = (::BreezyTemplate.configuration.track_pack_assets || []).map do |asset|
39
+ asset_pack_path(asset)
40
+ end
41
+ end
44
42
 
45
- if defined?(breezy_filter) && !!breezy_filter
46
- json.action 'graft'
47
- json.path breezy_filter
48
- end
43
+ if __sprockets_assets.any? || __pack_assets.any?
44
+ json.assets (__sprockets_assets + __pack_assets)
45
+ end
46
+
47
+ if defined?(breezy_filter) && !!breezy_filter
48
+ json.action 'graft'
49
+ __formatter = ::BreezyTemplate::KeyFormatter.new({camelize: :lower})
50
+ json.path breezy_filter
51
+ .split('.')
52
+ .map {|part|
53
+ if part.include? '='
54
+ k, v = part.split('=')
55
+ [__formatter.format(k),v].join('=')
56
+ else
57
+ __formatter.format(part)
58
+ end
59
+ }
60
+ .join('.')
61
+ end
62
+
63
+ json.last_fragment_name ::BreezyTemplate::Var.new('lastFragmentName')
64
+ json.last_fragment_path ::BreezyTemplate::Var.new('lastFragmentPath')
49
65
 
50
- json.joints ::BreezyTemplate::Var.new('joints')
51
- json.defers ::BreezyTemplate::Var.new('defers')
66
+ json.defers ::BreezyTemplate::Var.new('defers')
67
+ end
52
68
 
53
69
  json.target!
54
70
  end
@@ -0,0 +1,34 @@
1
+ require 'breezy_template/breezy_template'
2
+ require 'active_support/core_ext/array'
3
+
4
+ class BreezyTemplate
5
+ class KeyFormatter
6
+ def initialize(*args)
7
+ @format = {}
8
+ @cache = {}
9
+
10
+ options = args.extract_options!
11
+ args.each do |name|
12
+ @format[name] = []
13
+ end
14
+ options.each do |name, parameters|
15
+ @format[name] = parameters
16
+ end
17
+ end
18
+
19
+ def initialize_copy(original)
20
+ @cache = {}
21
+ end
22
+
23
+ def format(key)
24
+ @cache[key] ||= @format.inject(key.to_s) do |result, args|
25
+ func, args = args
26
+ if ::Proc === func
27
+ func.call result, *args
28
+ else
29
+ result.send func, *args
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -17,9 +17,7 @@ class BreezyTemplate
17
17
  options = _normalize_options_for_partial(options)
18
18
 
19
19
  if attributes.one? && _partial_options?(options)
20
- _, opts = options[:partial]
21
- opts.reverse_merge!(collection: collection)
22
- _render_partial_with_options(options)
20
+ _render_partial_with_options(collection, options)
23
21
  else
24
22
  super
25
23
  end
@@ -57,9 +55,6 @@ class BreezyTemplate
57
55
  options = _normalize_options_for_partial(options)
58
56
 
59
57
  partial, partial_opts = options[:partial]
60
- if partial_opts[:joint] == true
61
- partial_opts[:joint] = name
62
- end
63
58
 
64
59
  value = if object.nil? && partial.empty?
65
60
  []
@@ -79,45 +74,40 @@ class BreezyTemplate
79
74
 
80
75
  def _render_partial(options)
81
76
  partial, options = options[:partial]
82
- joint = options[:joint]
83
- if joint
84
- joint = joint.to_sym
77
+ fragment_name = options[:fragment_name]
78
+ if fragment_name
79
+ fragment_name = fragment_name.to_sym
85
80
  path = @path.dup.join('.')
86
- @js.push "joints['#{joint}'] ||= []; joints['#{joint}'].push('#{path}');"
87
- @joints[joint]
81
+ @js.push "fragments['#{fragment_name}'] = fragments['#{fragment_name}'] || []; fragments['#{fragment_name}'].push('#{path}'); lastFragmentName='#{fragment_name}'; lastFragmentPath='#{path}';"
82
+ @fragments[fragment_name]
88
83
  end
89
84
 
90
85
  options[:locals].merge! json: self
91
86
  @context.render options.merge(partial: partial)
92
87
  end
93
88
 
94
- def _render_partial_with_options(options)
89
+ def _render_partial_with_options(collection, options)
95
90
  options = _normalize_options_for_partial(options)
96
91
  partial, partial_opts = options[:partial]
97
- ary_opts = options.dup
92
+ array_opts = options.dup
98
93
 
99
94
  partial_opts.reverse_merge! locals: {}
100
95
  partial_opts.reverse_merge! ::BreezyTemplate.template_lookup_options
101
96
  as = partial_opts[:as]
102
97
 
103
- if partial_opts.key?(:collection)
104
- collection = partial_opts.delete(:collection)
105
- extract_joint_name = partial_opts.delete(:joint)
106
- locals = partial_opts.delete(:locals)
107
-
108
- ary_opts.delete(:partial)
109
- array! collection, ary_opts do |member|
110
-
111
- member_locals = locals.clone
112
- member_locals.merge! collection: collection
113
- member_locals.merge! as.to_sym => member if as
114
- partial_opts.merge!(locals: member_locals)
115
- if extract_joint_name.respond_to?(:call)
116
- partial_opts.merge!(joint: extract_joint_name.call(member))
117
- end
118
- _render_partial options
98
+ extract_fragment_name = partial_opts.delete(:fragment_name)
99
+ locals = partial_opts.delete(:locals)
100
+
101
+ array_opts.delete(:partial)
102
+ array! collection, array_opts do |member|
103
+ member_locals = locals.clone
104
+ member_locals.merge! collection: collection
105
+ member_locals.merge! as.to_sym => member if as
106
+ partial_opts.merge!(locals: member_locals)
107
+
108
+ if extract_fragment_name.respond_to?(:call)
109
+ partial_opts.merge!(fragment_name: extract_fragment_name.call(member))
119
110
  end
120
- else
121
111
  _render_partial options
122
112
  end
123
113
  end
@@ -13,9 +13,11 @@ class BreezyTemplate
13
13
  found
14
14
  end
15
15
 
16
- def _filter_by_path(search_path)
16
+ def _set_search_path_once(search_path)
17
+ return if @search_path
18
+
17
19
  if search_path.is_a? ::String
18
- return _filter_by_path(search_path.split('.'))
20
+ return _set_search_path_once(search_path.split('.'))
19
21
  end
20
22
  @search_path = search_path
21
23
  end
@@ -24,10 +24,22 @@ PROFILE_PARTIAL = <<-JBUILDER
24
24
  json.email email
25
25
  JBUILDER
26
26
 
27
+ RECORD_PARTIAL = <<-JBUILDER
28
+ json.email record[:email]
29
+ JBUILDER
30
+
27
31
  FOOTER_PARTIAL = <<-JBUILDER
28
32
  json.terms "You agree"
29
33
  JBUILDER
30
34
 
35
+ NESTED_PARTIAL = <<-JBUILDER
36
+ json.foo do
37
+ json.bar 'goo'
38
+ end
39
+
40
+ json.nested nil, partial: "footer"
41
+ JBUILDER
42
+
31
43
  FLATTENED_PARTIAL = <<-JBUILDER
32
44
  json.array! [1,2]
33
45
  JBUILDER
@@ -44,7 +56,9 @@ PARTIALS = {
44
56
  "_partial.js.breezy" => "foo ||= 'hello'; json.content foo",
45
57
  "_blog_post.js.breezy" => BLOG_POST_PARTIAL,
46
58
  "_profile.js.breezy" => PROFILE_PARTIAL,
59
+ "_record.js.breezy" => RECORD_PARTIAL,
47
60
  "_footer.js.breezy" => FOOTER_PARTIAL,
61
+ "_nested.js.breezy" => NESTED_PARTIAL,
48
62
  "_collection.js.breezy" => COLLECTION_PARTIAL,
49
63
  "_flattened.js.breezy" => FLATTENED_PARTIAL
50
64
  }
@@ -149,10 +163,12 @@ class BreezyTemplateTest < ActionView::TestCase
149
163
 
150
164
  expected = strip_format(<<-JS)
151
165
  (function(){
152
- var joints={};
166
+ var fragments={};
167
+ var lastFragmentName;
168
+ var lastFragmentPath;
153
169
  var cache={};
154
170
  var defers=[];
155
- return ({"data":{"content":"hello"},"screen":"test","joints":joints,"defers":defers});
171
+ return ({"data":{"content":"hello"},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
156
172
  })()
157
173
  JS
158
174
 
@@ -173,10 +189,12 @@ class BreezyTemplateTest < ActionView::TestCase
173
189
 
174
190
  expected = strip_format(<<-JS)
175
191
  (function(){
176
- var joints={};
192
+ var fragments={};
193
+ var lastFragmentName;
194
+ var lastFragmentPath;
177
195
  var cache={};
178
196
  var defers=[];
179
- return ({"data":{"content":{"hit":123}},"screen":"test","joints":joints,"defers":defers});
197
+ return ({"data":{"content":{"hit":123}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
180
198
  })()
181
199
  JS
182
200
 
@@ -193,10 +211,12 @@ class BreezyTemplateTest < ActionView::TestCase
193
211
 
194
212
  expected = strip_format(<<-JS)
195
213
  (function(){
196
- var joints={};
214
+ var fragments={};
215
+ var lastFragmentName;
216
+ var lastFragmentPath;
197
217
  var cache={};
198
218
  var defers=[];
199
- return ({\"data\":{\"content\":[3,4]},"screen":"test","joints":joints,"defers":defers});
219
+ return ({\"data\":{\"content\":[3,4]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
200
220
  })()
201
221
  JS
202
222
 
@@ -213,10 +233,12 @@ class BreezyTemplateTest < ActionView::TestCase
213
233
 
214
234
  expected = strip_format(<<-JS)
215
235
  (function(){
216
- var joints={};
236
+ var fragments={};
237
+ var lastFragmentName;
238
+ var lastFragmentPath;
217
239
  var cache={};
218
240
  var defers=[];
219
- return ({"data":{"content":"hello"},"screen":"test","assets":["/test.js","/test.css","test_pack.js","test_pack.css"],"joints":joints,"defers":defers});
241
+ return ({"data":{"content":"hello"},"screen":"test","fragments":fragments,"privateOpts":{"assets":["/test.js","/test.css","test_pack.js","test_pack.css"],"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
220
242
  })()
221
243
  JS
222
244
 
@@ -235,10 +257,12 @@ class BreezyTemplateTest < ActionView::TestCase
235
257
 
236
258
  expected = strip_format(<<-JS)
237
259
  (function(){
238
- var joints={};
260
+ var fragments={};
261
+ var lastFragmentName;
262
+ var lastFragmentPath;
239
263
  var cache={};
240
264
  var defers=[];
241
- return ({"data":{"content":"hello"},"screen":"test","csrf_token":"secret","joints":joints,"defers":defers});
265
+ return ({"data":{"content":"hello"},"screen":"test","fragments":fragments,"privateOpts":{"csrfToken":"secret","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
242
266
  })()
243
267
  JS
244
268
 
@@ -255,10 +279,12 @@ class BreezyTemplateTest < ActionView::TestCase
255
279
 
256
280
  expected = strip_format(<<-JS)
257
281
  (function(){
258
- var joints={};
282
+ var fragments={};
283
+ var lastFragmentName;
284
+ var lastFragmentPath;
259
285
  var cache={};
260
286
  var defers=[];
261
- return ({"data":{"content":"hello"},"screen":"test","title":"this is fun","assets":["/test.js","/test.css"],"joints":joints,"defers":defers});
287
+ return ({"data":{"content":"hello"},"screen":"test","title":"this is fun","fragments":fragments,"privateOpts":{"assets":["/test.js","/test.css"],"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
262
288
  })()
263
289
  JS
264
290
 
@@ -270,72 +296,61 @@ class BreezyTemplateTest < ActionView::TestCase
270
296
  Rails.cache.clear
271
297
 
272
298
  result = jbuild(<<-JBUILDER)
273
- json.post @post, partial: ["blog_post", as: :blog_post, joint: :header]
299
+ json.post @post, partial: ["blog_post", as: :blog_post, fragment_name: :header]
274
300
  JBUILDER
275
301
 
276
302
  expected = strip_format(<<-JS)
277
303
  (function(){
278
- var joints={};
304
+ var fragments={};
305
+ var lastFragmentName;
306
+ var lastFragmentPath;
279
307
  var cache={};
280
308
  var defers=[];
281
- joints['header'] ||= []; joints['header'].push('post');
309
+ fragments['header'] = fragments['header'] || []; fragments['header'].push('post'); lastFragmentName='header'; lastFragmentPath='post';
282
310
  return ({"data":{"post":{
283
311
  "id":1,
284
312
  "body":"post body 1",
285
- "author":{"first_name":"David","last_name":"Heinemeier Hansson"}
286
- }},"screen":"test","joints":joints,"defers":defers});
313
+ "author":{"firstName":"David","lastName":"Heinemeier Hansson"}
314
+ }},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
287
315
  })()
288
316
  JS
289
317
 
290
318
  assert_equal expected, result
291
319
  end
292
320
 
293
- test "renders a partial with implicit joint" do
294
- result = jbuild(<<-JBUILDER)
295
- json.footer nil, partial: ["footer", joint: true]
296
- JBUILDER
297
-
298
- expected = strip_format(<<-JS)
299
- (function(){
300
- var joints={};
301
- var cache={};
302
- var defers=[];
303
- joints['footer'] ||= []; joints['footer'].push('footer');
304
- return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","joints":joints,"defers":defers});
305
- })()
306
- JS
307
- assert_equal expected, result
308
- end
309
-
310
- test "renders a partial with explicit joint" do
321
+ test "renders a partial with explicit fragment" do
311
322
  result = jbuild(<<-JBUILDER)
312
- json.footer nil, partial: ["footer", joint: 'hello']
323
+ json.footer nil, partial: ["footer", fragment_name: 'hello']
313
324
  JBUILDER
314
325
 
315
326
  expected = strip_format(<<-JS)
316
327
  (function(){
317
- var joints={};
328
+ var fragments={};
329
+ var lastFragmentName;
330
+ var lastFragmentPath;
318
331
  var cache={};
319
332
  var defers=[];
320
- joints['hello'] ||= []; joints['hello'].push('footer');
321
- return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","joints":joints,"defers":defers});
333
+ fragments['hello'] = fragments['hello'] || []; fragments['hello'].push('footer'); lastFragmentName='hello'; lastFragmentPath='footer';
334
+ return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
322
335
  })()
323
336
  JS
324
337
  assert_equal expected, result
325
338
  end
326
339
 
327
- test "render array of partials with unique joints" do
340
+ test "render array of partials with unique fragments" do
328
341
  result = jbuild(<<-JBUILDER)
329
- json.array! [1,2], partial: ["footer", joint: ->(x){"somefoo"+x.to_s}]
342
+ json.array! [1,2], partial: ["footer", fragment_name: ->(x){"somefoo"+x.to_s}]
330
343
  JBUILDER
331
344
 
332
345
  expected = strip_format(<<-JS)
333
346
  (function(){
334
- var joints={};
347
+ var fragments={};
348
+ var lastFragmentName;
349
+ var lastFragmentPath;
335
350
  var cache={};
336
351
  var defers=[];
337
- joints['somefoo1'] ||= []; joints['somefoo1'].push('0');joints['somefoo2'] ||= []; joints['somefoo2'].push('1');
338
- return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","joints":joints,"defers":defers});
352
+ fragments['somefoo1'] = fragments['somefoo1'] || []; fragments['somefoo1'].push('0'); lastFragmentName='somefoo1'; lastFragmentPath='0';fragments['somefoo2'] = fragments['somefoo2'] || []; fragments['somefoo2'].push('1'); lastFragmentName='somefoo2'; lastFragmentPath='1';
353
+ return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
339
354
  })()
340
355
  JS
341
356
 
@@ -349,10 +364,12 @@ class BreezyTemplateTest < ActionView::TestCase
349
364
 
350
365
  expected = strip_format(<<-JS)
351
366
  (function(){
352
- var joints={};
367
+ var fragments={};
368
+ var lastFragmentName;
369
+ var lastFragmentPath;
353
370
  var cache={};
354
371
  var defers=[];
355
- return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","joints":joints,"defers":defers});
372
+ return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
356
373
  })()
357
374
  JS
358
375
  assert_equal expected, result
@@ -365,10 +382,12 @@ class BreezyTemplateTest < ActionView::TestCase
365
382
 
366
383
  expected = strip_format(<<-JS)
367
384
  (function(){
368
- var joints={};
385
+ var fragments={};
386
+ var lastFragmentName;
387
+ var lastFragmentPath;
369
388
  var cache={};
370
389
  var defers=[];
371
- return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","joints":joints,"defers":defers});
390
+ return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
372
391
  })()
373
392
  JS
374
393
  assert_equal expected, result
@@ -385,11 +404,13 @@ class BreezyTemplateTest < ActionView::TestCase
385
404
 
386
405
  expected = strip_format(<<-JS)
387
406
  (function(){
388
- var joints={};
407
+ var fragments={};
408
+ var lastFragmentName;
409
+ var lastFragmentPath;
389
410
  var cache={};
390
411
  var defers=[];
391
412
  cache["#{cache_keys[0]}"]={"email":"test@test.com"};
392
- return ({"data":{"profile":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
413
+ return ({"data":{"profile":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
393
414
  })()
394
415
  JS
395
416
 
@@ -403,10 +424,12 @@ class BreezyTemplateTest < ActionView::TestCase
403
424
 
404
425
  expected = strip_format(<<-JS)
405
426
  (function(){
406
- var joints={};
427
+ var fragments={};
428
+ var lastFragmentName;
429
+ var lastFragmentPath;
407
430
  var cache={};
408
431
  var defers=[];
409
- return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","joints":joints,"defers":defers});
432
+ return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
410
433
  })()
411
434
  JS
412
435
 
@@ -420,10 +443,12 @@ class BreezyTemplateTest < ActionView::TestCase
420
443
 
421
444
  expected = strip_format(<<-JS)
422
445
  (function(){
423
- var joints={};
446
+ var fragments={};
447
+ var lastFragmentName;
448
+ var lastFragmentPath;
424
449
  var cache={};
425
450
  var defers=[];
426
- return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","joints":joints,"defers":defers});
451
+ return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
427
452
  })()
428
453
  JS
429
454
 
@@ -437,12 +462,14 @@ class BreezyTemplateTest < ActionView::TestCase
437
462
 
438
463
  expected = strip_format(<<-JS)
439
464
  (function(){
440
- var joints={};
465
+ var fragments={};
466
+ var lastFragmentName;
467
+ var lastFragmentPath;
441
468
  var cache={};
442
469
  var defers=[];
443
470
  cache["#{cache_keys[0]}"]={"terms":"You agree"};
444
471
  cache["#{cache_keys[1]}"]={"terms":"You agree"};
445
- return ({"data":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"]],"screen":"test","joints":joints,"defers":defers});
472
+ return ({"data":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"]],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
446
473
  })()
447
474
  JS
448
475
 
@@ -456,21 +483,23 @@ class BreezyTemplateTest < ActionView::TestCase
456
483
 
457
484
  expected = strip_format(<<-JS)
458
485
  (function(){
459
- var joints={};
486
+ var fragments={};
487
+ var lastFragmentName;
488
+ var lastFragmentPath;
460
489
  var cache={};
461
490
  var defers=[];
462
491
  return ({"data":[
463
- {"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
464
- {"id":2,"body":"post body 2","author":{"first_name":"Pavel","last_name":"Pravosud"}},
465
- {"id":3,"body":"post body 3","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
466
- {"id":4,"body":"post body 4","author":{"first_name":"Pavel","last_name":"Pravosud"}},
467
- {"id":5,"body":"post body 5","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
468
- {"id":6,"body":"post body 6","author":{"first_name":"Pavel","last_name":"Pravosud"}},
469
- {"id":7,"body":"post body 7","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
470
- {"id":8,"body":"post body 8","author":{"first_name":"Pavel","last_name":"Pravosud"}},
471
- {"id":9,"body":"post body 9","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
472
- {"id":10,"body":"post body 10","author":{"first_name":"Pavel","last_name":"Pravosud"}}
473
- ],"screen":"test","joints":joints,"defers":defers});
492
+ {"id":1,"body":"post body 1","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
493
+ {"id":2,"body":"post body 2","author":{"firstName":"Pavel","lastName":"Pravosud"}},
494
+ {"id":3,"body":"post body 3","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
495
+ {"id":4,"body":"post body 4","author":{"firstName":"Pavel","lastName":"Pravosud"}},
496
+ {"id":5,"body":"post body 5","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
497
+ {"id":6,"body":"post body 6","author":{"firstName":"Pavel","lastName":"Pravosud"}},
498
+ {"id":7,"body":"post body 7","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
499
+ {"id":8,"body":"post body 8","author":{"firstName":"Pavel","lastName":"Pravosud"}},
500
+ {"id":9,"body":"post body 9","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
501
+ {"id":10,"body":"post body 10","author":{"firstName":"Pavel","lastName":"Pravosud"}}
502
+ ],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
474
503
  })()
475
504
  JS
476
505
 
@@ -484,10 +513,12 @@ class BreezyTemplateTest < ActionView::TestCase
484
513
 
485
514
  expected = strip_format(<<-JS)
486
515
  (function(){
487
- var joints={};
516
+ var fragments={};
517
+ var lastFragmentName;
518
+ var lastFragmentPath;
488
519
  var cache={};
489
520
  var defers=[];
490
- return ({"data":[],"screen":"test","joints":joints,"defers":defers});
521
+ return ({"data":[],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
491
522
  })()
492
523
  JS
493
524
 
@@ -501,10 +532,12 @@ class BreezyTemplateTest < ActionView::TestCase
501
532
 
502
533
  expected = strip_format(<<-JS)
503
534
  (function(){
504
- var joints={};
535
+ var fragments={};
536
+ var lastFragmentName;
537
+ var lastFragmentPath;
505
538
  var cache={};
506
539
  var defers=[];
507
- return ({"data":{"posts":{"terms":"You agree"}},"screen":"test","joints":joints,"defers":defers});
540
+ return ({"data":{"posts":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
508
541
  })()
509
542
  JS
510
543
  assert_equal expected, result
@@ -517,10 +550,12 @@ class BreezyTemplateTest < ActionView::TestCase
517
550
 
518
551
  expected = strip_format(<<-JS)
519
552
  (function(){
520
- var joints={};
553
+ var fragments={};
554
+ var lastFragmentName;
555
+ var lastFragmentPath;
521
556
  var cache={};
522
557
  var defers=[];
523
- return ({"data":{"posts":[1,2]},"screen":"test","joints":joints,"defers":defers});
558
+ return ({"data":{"posts":[1,2]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
524
559
  })()
525
560
  JS
526
561
  assert_equal expected, result
@@ -538,11 +573,13 @@ class BreezyTemplateTest < ActionView::TestCase
538
573
 
539
574
  expected = strip_format(<<-JS)
540
575
  (function(){
541
- var joints={};
576
+ var fragments={};
577
+ var lastFragmentName;
578
+ var lastFragmentPath;
542
579
  var cache={};
543
580
  var defers=[];
544
581
  cache["#{cache_keys[0]}"]=32;
545
- return ({"data":{"hello":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
582
+ return ({"data":{"hello":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
546
583
  })()
547
584
  JS
548
585
 
@@ -565,12 +602,14 @@ class BreezyTemplateTest < ActionView::TestCase
565
602
 
566
603
  expected = strip_format(<<-JS)
567
604
  (function(){
568
- var joints={};
605
+ var fragments={};
606
+ var lastFragmentName;
607
+ var lastFragmentPath;
569
608
  var cache={};
570
609
  var defers=[];
571
610
  cache["#{cache_keys[0]}"]={"top":"hello4"};
572
611
  cache["#{cache_keys[1]}"]={"top":"hello5"};
573
- return ({"data":{"hello":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"]]},"screen":"test","joints":joints,"defers":defers});
612
+ return ({"data":{"hello":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"]]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
574
613
  })()
575
614
  JS
576
615
 
@@ -593,13 +632,15 @@ class BreezyTemplateTest < ActionView::TestCase
593
632
 
594
633
  expected = strip_format(<<-JS)
595
634
  (function(){
596
- var joints={};
635
+ var fragments={};
636
+ var lastFragmentName;
637
+ var lastFragmentPath;
597
638
  var cache={};
598
639
  var defers=[];
599
640
  cache["#{cache_keys[0]}"]={"subcontent":"inner"};
600
641
  cache["#{cache_keys[1]}"]={"subcontent":"other"};
601
642
  cache["#{cache_keys[2]}"]={"content":cache["#{cache_keys[0]}"],"other":cache["#{cache_keys[1]}"]};
602
- return ({"data":{"hello":cache["#{cache_keys[2]}"]},"screen":"test","joints":joints,"defers":defers});
643
+ return ({"data":{"hello":cache["#{cache_keys[2]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
603
644
  })()
604
645
  JS
605
646
 
@@ -622,10 +663,12 @@ class BreezyTemplateTest < ActionView::TestCase
622
663
 
623
664
  expected = strip_format(<<-JS)
624
665
  (function(){
625
- var joints={};
666
+ var fragments={};
667
+ var lastFragmentName;
668
+ var lastFragmentPath;
626
669
  var cache={};
627
670
  var defers=[];
628
- return ({\"data\":{\"hello\":[]},"screen":"test","joints":joints,"defers":defers});
671
+ return ({\"data\":{\"hello\":[]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
629
672
  })()
630
673
  JS
631
674
 
@@ -671,11 +714,13 @@ class BreezyTemplateTest < ActionView::TestCase
671
714
 
672
715
  expected = strip_format(<<-JS)
673
716
  (function(){
674
- var joints={};
717
+ var fragments={};
718
+ var lastFragmentName;
719
+ var lastFragmentPath;
675
720
  var cache={};
676
721
  var defers=[];
677
722
  cache["#{cache_keys[0]}"]={"name":"Cache"};
678
- return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
723
+ return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
679
724
  })()
680
725
  JS
681
726
 
@@ -693,11 +738,13 @@ class BreezyTemplateTest < ActionView::TestCase
693
738
 
694
739
  expected = strip_format(<<-JS)
695
740
  (function(){
696
- var joints={};
741
+ var fragments={};
742
+ var lastFragmentName;
743
+ var lastFragmentPath;
697
744
  var cache={};
698
745
  var defers=[];
699
746
  cache["#{cache_keys[0]}"]=["a","b","c"];
700
- return ({"data":{"content":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
747
+ return ({"data":{"content":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
701
748
  })()
702
749
  JS
703
750
 
@@ -764,10 +811,12 @@ class BreezyTemplateTest < ActionView::TestCase
764
811
 
765
812
  expected = strip_format(<<-JS)
766
813
  (function(){
767
- var joints={};
814
+ var fragments={};
815
+ var lastFragmentName;
816
+ var lastFragmentPath;
768
817
  var cache={};
769
818
  var defers=[];
770
- return ({"data":{"content":{"name":"Cache"}},"screen":"test","joints":joints,"defers":defers});
819
+ return ({"data":{"content":{"name":"Cache"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
771
820
  })()
772
821
  JS
773
822
 
@@ -783,11 +832,13 @@ class BreezyTemplateTest < ActionView::TestCase
783
832
 
784
833
  expected = strip_format(<<-JS)
785
834
  (function(){
786
- var joints={};
835
+ var fragments={};
836
+ var lastFragmentName;
837
+ var lastFragmentPath;
787
838
  var cache={};
788
839
  var defers=[];
789
- cache["#{cache_keys[0]}"]={"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
790
- return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
840
+ cache["#{cache_keys[0]}"]={"id":1,"body":"post body 1","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
841
+ return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
791
842
  })()
792
843
  JS
793
844
 
@@ -820,11 +871,13 @@ class BreezyTemplateTest < ActionView::TestCase
820
871
 
821
872
  expected = strip_format(<<-JS)
822
873
  (function(){
823
- var joints={};
874
+ var fragments={};
875
+ var lastFragmentName;
876
+ var lastFragmentPath;
824
877
  var cache={};
825
878
  var defers=[];
826
- cache["#{cache_keys[0]}"]={"id":1,"body":"hit","author":{"first_name":"John","last_name":"Smith"}};
827
- return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","joints":joints,"defers":defers});
879
+ cache["#{cache_keys[0]}"]={"id":1,"body":"hit","author":{"firstName":"John","lastName":"Smith"}};
880
+ return ({"data":{"post":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
828
881
  })()
829
882
  JS
830
883
 
@@ -844,28 +897,29 @@ class BreezyTemplateTest < ActionView::TestCase
844
897
 
845
898
  expected = strip_format(<<-JS)
846
899
  (function(){
847
- var joints={};
900
+ var fragments={};
901
+ var lastFragmentName;
902
+ var lastFragmentPath;
848
903
  var cache={};
849
904
  var defers=[];
850
- cache["#{cache_keys[0]}"]={"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
851
- cache["#{cache_keys[1]}"]={"id":2,"body":"post body 2","author":{"first_name":"Pavel","last_name":"Pravosud"}};
852
- cache["#{cache_keys[2]}"]={"id":3,"body":"post body 3","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
853
- cache["#{cache_keys[3]}"]={"id":4,"body":"post body 4","author":{"first_name":"Pavel","last_name":"Pravosud"}};
854
- cache["#{cache_keys[4]}"]={"id":5,"body":"post body 5","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
855
- cache["#{cache_keys[5]}"]={"id":6,"body":"post body 6","author":{"first_name":"Pavel","last_name":"Pravosud"}};
856
- cache["#{cache_keys[6]}"]={"id":7,"body":"post body 7","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
857
- cache["#{cache_keys[7]}"]={"id":8,"body":"post body 8","author":{"first_name":"Pavel","last_name":"Pravosud"}};
858
- cache["#{cache_keys[8]}"]={"id":9,"body":"post body 9","author":{"first_name":"David","last_name":"Heinemeier Hansson"}};
859
- cache["#{cache_keys[9]}"]={"id":10,"body":"post body 10","author":{"first_name":"Pavel","last_name":"Pravosud"}};
860
- return ({"data":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"],cache["#{cache_keys[2]}"],cache["#{cache_keys[3]}"],cache["#{cache_keys[4]}"],cache["#{cache_keys[5]}"],cache["#{cache_keys[6]}"],cache["#{cache_keys[7]}"],cache["#{cache_keys[8]}"],cache["#{cache_keys[9]}"]],"screen":"test","joints":joints,"defers":defers});
905
+ cache["#{cache_keys[0]}"]={"id":1,"body":"post body 1","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
906
+ cache["#{cache_keys[1]}"]={"id":2,"body":"post body 2","author":{"firstName":"Pavel","lastName":"Pravosud"}};
907
+ cache["#{cache_keys[2]}"]={"id":3,"body":"post body 3","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
908
+ cache["#{cache_keys[3]}"]={"id":4,"body":"post body 4","author":{"firstName":"Pavel","lastName":"Pravosud"}};
909
+ cache["#{cache_keys[4]}"]={"id":5,"body":"post body 5","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
910
+ cache["#{cache_keys[5]}"]={"id":6,"body":"post body 6","author":{"firstName":"Pavel","lastName":"Pravosud"}};
911
+ cache["#{cache_keys[6]}"]={"id":7,"body":"post body 7","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
912
+ cache["#{cache_keys[7]}"]={"id":8,"body":"post body 8","author":{"firstName":"Pavel","lastName":"Pravosud"}};
913
+ cache["#{cache_keys[8]}"]={"id":9,"body":"post body 9","author":{"firstName":"David","lastName":"Heinemeier Hansson"}};
914
+ cache["#{cache_keys[9]}"]={"id":10,"body":"post body 10","author":{"firstName":"Pavel","lastName":"Pravosud"}};
915
+ return ({"data":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"],cache["#{cache_keys[2]}"],cache["#{cache_keys[3]}"],cache["#{cache_keys[4]}"],cache["#{cache_keys[5]}"],cache["#{cache_keys[6]}"],cache["#{cache_keys[7]}"],cache["#{cache_keys[8]}"],cache["#{cache_keys[9]}"]],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
861
916
  })()
862
917
  JS
863
918
  assert_equal expected, result
864
919
  end
865
920
 
866
921
  test "filtering for a node in the tree" do
867
- result = jbuild(<<-JBUILDER)
868
- json._filter_by_path('hit.hit2')
922
+ result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
869
923
  json.hit do
870
924
  json.hit2 do
871
925
  json.greeting 'hello world'
@@ -883,11 +937,39 @@ class BreezyTemplateTest < ActionView::TestCase
883
937
 
884
938
  expected = strip_format(<<-JS)
885
939
  (function(){
886
- var joints={};
940
+ var fragments={};
941
+ var lastFragmentName;
942
+ var lastFragmentPath;
887
943
  var cache={};
888
944
  var defers=[];
889
945
  return (
890
- {"data":{"greeting":"hello world"},"screen":"test","joints":joints,"defers":defers}
946
+ {"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
947
+ );
948
+ })()
949
+ JS
950
+
951
+ assert_equal expected, result
952
+ end
953
+
954
+ test "filtering for a node in the tree with camelized keys" do
955
+ result = jbuild(<<-JBUILDER, breezy_filter: 'hit_one.hit_two')
956
+ json.hit_one do
957
+ json.hit_two do
958
+ json.greeting 'hello world'
959
+ end
960
+ end
961
+ JBUILDER
962
+ Rails.cache.clear
963
+
964
+ expected = strip_format(<<-JS)
965
+ (function(){
966
+ var fragments={};
967
+ var lastFragmentName;
968
+ var lastFragmentPath;
969
+ var cache={};
970
+ var defers=[];
971
+ return (
972
+ {"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hitOne.hitTwo","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
891
973
  );
892
974
  })()
893
975
  JS
@@ -898,7 +980,7 @@ class BreezyTemplateTest < ActionView::TestCase
898
980
  test "filtering for a nonexistant node in the tree" do
899
981
  begin
900
982
  jbuild(<<-JBUILDER)
901
- json._filter_by_path('miss.miss.miss.miss')
983
+ json._set_search_path_once('miss.miss.miss.miss')
902
984
  json.hit do
903
985
  json.hit2 do
904
986
  json.greeting 'hello world'
@@ -929,11 +1011,13 @@ class BreezyTemplateTest < ActionView::TestCase
929
1011
 
930
1012
  expected = strip_format(<<-JS)
931
1013
  (function(){
932
- var joints={};
1014
+ var fragments={};
1015
+ var lastFragmentName;
1016
+ var lastFragmentPath;
933
1017
  var cache={};
934
1018
  var defers=[];
935
1019
  return (
936
- {"data":23,"screen":"test","action":"graft","path":"hit.hit2","joints":joints,"defers":defers}
1020
+ {"data":23,"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
937
1021
  );
938
1022
  })()
939
1023
  JS
@@ -941,20 +1025,22 @@ class BreezyTemplateTest < ActionView::TestCase
941
1025
  assert_equal expected, result
942
1026
  end
943
1027
 
944
- test "filter with partial" do
945
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.terms')
1028
+ test "filter with partials" do
1029
+ result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.nested.terms')
946
1030
  json.hit do
947
- json.hit2 nil, partial: "footer"
1031
+ json.hit2 nil, partial: "nested"
948
1032
  end
949
1033
  JBUILDER
950
1034
 
951
1035
  expected = strip_format(<<-JS)
952
1036
  (function(){
953
- var joints={};
1037
+ var fragments={};
1038
+ var lastFragmentName;
1039
+ var lastFragmentPath;
954
1040
  var cache={};
955
1041
  var defers=[];
956
1042
  return (
957
- {"data":"You agree","screen":"test","action":"graft","path":"hit.hit2.terms","joints":joints,"defers":defers}
1043
+ {"data":"You agree","screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.nested.terms","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
958
1044
  );
959
1045
  })()
960
1046
  JS
@@ -980,11 +1066,13 @@ class BreezyTemplateTest < ActionView::TestCase
980
1066
 
981
1067
  expected = strip_format(<<-JS)
982
1068
  (function(){
983
- var joints={};
1069
+ var fragments={};
1070
+ var lastFragmentName;
1071
+ var lastFragmentPath;
984
1072
  var cache={};
985
1073
  var defers=[];
986
1074
  return (
987
- {"data":{"greeting":"hello world"},"screen":"test","action":"graft","path":"hit.hit2","joints":joints,"defers":defers}
1075
+ {"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
988
1076
  );
989
1077
  })()
990
1078
  JS
@@ -1005,11 +1093,13 @@ class BreezyTemplateTest < ActionView::TestCase
1005
1093
 
1006
1094
  expected = strip_format(<<-JS)
1007
1095
  (function(){
1008
- var joints={};
1096
+ var fragments={};
1097
+ var lastFragmentName;
1098
+ var lastFragmentPath;
1009
1099
  var cache={};
1010
1100
  var defers=[];
1011
1101
  cache["#{cache_keys[0]}"]={"greeting":"hello world"};
1012
- return ({"data":cache["#{cache_keys[0]}"],"screen":"test","action":"graft","path":"hit.hit2","joints":joints,"defers":defers});
1102
+ return ({"data":cache["#{cache_keys[0]}"],"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
1013
1103
  })()
1014
1104
 
1015
1105
 
@@ -1034,11 +1124,13 @@ class BreezyTemplateTest < ActionView::TestCase
1034
1124
 
1035
1125
  expected = strip_format(<<-JS)
1036
1126
  (function(){
1037
- var joints={};
1127
+ var fragments={};
1128
+ var lastFragmentName;
1129
+ var lastFragmentPath;
1038
1130
  var cache={};
1039
1131
  var defers=[];
1040
1132
  return (
1041
- {"data":{"name":"hit"},"screen":"test","action":"graft","path":"hit.hit2.id=1","joints":joints,"defers":defers}
1133
+ {"data":{"name":"hit"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.id=1","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1042
1134
  );
1043
1135
  })()
1044
1136
  JS
@@ -1062,11 +1154,13 @@ class BreezyTemplateTest < ActionView::TestCase
1062
1154
 
1063
1155
  expected = strip_format(<<-JS)
1064
1156
  (function(){
1065
- var joints={};
1157
+ var fragments={};
1158
+ var lastFragmentName;
1159
+ var lastFragmentPath;
1066
1160
  var cache={};
1067
1161
  var defers=[];
1068
1162
  return (
1069
- {"data":{"name":"hit"},"screen":"test","action":"graft","path":"hit.hit2.0","joints":joints,"defers":defers}
1163
+ {"data":{"name":"hit"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.0","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1070
1164
  );
1071
1165
  })()
1072
1166
  JS
@@ -1091,12 +1185,14 @@ class BreezyTemplateTest < ActionView::TestCase
1091
1185
 
1092
1186
  expected = strip_format(<<-JS)
1093
1187
  (function(){
1094
- var joints={};
1188
+ var fragments={};
1189
+ var lastFragmentName;
1190
+ var lastFragmentPath;
1095
1191
  var cache={};
1096
1192
  var defers=[];
1097
1193
  defers.push({url:'/some_url?_bz=hit.hit2'});
1098
1194
  return (
1099
- {"data":{"hit":{"hit2":undefined}},"screen":"test","joints":joints,"defers":defers}
1195
+ {"data":{"hit":{"hit2":undefined}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1100
1196
  );
1101
1197
  })()
1102
1198
  JS
@@ -1121,11 +1217,93 @@ class BreezyTemplateTest < ActionView::TestCase
1121
1217
 
1122
1218
  expected = strip_format(<<-JS)
1123
1219
  (function(){
1124
- var joints={};
1220
+ var fragments={};
1221
+ var lastFragmentName;
1222
+ var lastFragmentPath;
1223
+ var cache={};
1224
+ var defers=[];
1225
+ return (
1226
+ {"data":{"hit":{"hit2":undefined}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1227
+ );
1228
+ })()
1229
+ JS
1230
+
1231
+ assert_equal expected, result
1232
+ end
1233
+
1234
+ test "rendering with selective array node deferment" do
1235
+ req = action_controller_test_request
1236
+ req.path = '/some_url'
1237
+
1238
+ result = jbuild(<<-JBUILDER, request: req)
1239
+ keep_first = lambda do |item|
1240
+ if item[:id] == 1
1241
+ false
1242
+ else
1243
+ :auto
1244
+ end
1245
+ end
1246
+
1247
+ json.hit do
1248
+ json.hit2 do
1249
+ data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
1250
+ json.array! data, key: :id, defer: keep_first do |item|
1251
+ json.name item[:name]
1252
+ end
1253
+ end
1254
+ end
1255
+ JBUILDER
1256
+ Rails.cache.clear
1257
+
1258
+ expected = strip_format(<<-JS)
1259
+ (function(){
1260
+ var fragments={};
1261
+ var lastFragmentName;
1262
+ var lastFragmentPath;
1263
+ var cache={};
1264
+ var defers=[];
1265
+ defers.push({url:'/some_url?_bz=hit.hit2.id%3D2'});
1266
+ return (
1267
+ {"data":{"hit":{"hit2":[{"name":"foo"},{"id":2}]}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1268
+ );
1269
+ })()
1270
+ JS
1271
+
1272
+ assert_equal expected, result
1273
+ end
1274
+
1275
+ test "rendering with node array partial deferment" do
1276
+ req = action_controller_test_request
1277
+ req.path = '/some_url'
1278
+
1279
+ result = jbuild(<<-JBUILDER, request: req)
1280
+ keep_first = lambda do |item|
1281
+ if item[:id] == 1
1282
+ false
1283
+ else
1284
+ :auto
1285
+ end
1286
+ end
1287
+
1288
+ json.hit do
1289
+ json.hit2 do
1290
+ data = [{id: 1, email: 'foo'}, {id: 2, email: 'bar'}]
1291
+ json.array! data, key: :id, defer: keep_first, partial: ['record', as: :record]
1292
+ end
1293
+ end
1294
+ JBUILDER
1295
+ Rails.cache.clear
1296
+
1297
+ expected = strip_format(<<-JS)
1298
+ (function(){
1299
+ var fragments={};
1300
+ var lastFragmentName;
1301
+ var lastFragmentPath;
1125
1302
  var cache={};
1126
1303
  var defers=[];
1304
+ defers.push({url:'/some_url?_bz=hit.hit2.id%3D2'});
1127
1305
  return (
1128
- {"data":{"hit":{"hit2":undefined}},"screen":"test","joints":joints,"defers":defers}
1306
+ {"data":{"hit":{"hit2":[{"email":"foo"},{"id":2}]}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1129
1307
  );
1130
1308
  })()
1131
1309
  JS
@@ -1137,6 +1315,74 @@ class BreezyTemplateTest < ActionView::TestCase
1137
1315
  req = action_controller_test_request
1138
1316
  req.path = '/some_url'
1139
1317
 
1318
+ result = jbuild(<<-JBUILDER, request: req)
1319
+ json.hit do
1320
+ json.hit2 do
1321
+ data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
1322
+ json.array! data, key: :id, defer: :auto do |item|
1323
+ json.name item[:name]
1324
+ end
1325
+ end
1326
+ end
1327
+ JBUILDER
1328
+ Rails.cache.clear
1329
+
1330
+ expected = strip_format(<<-JS)
1331
+ (function(){
1332
+ var fragments={};
1333
+ var lastFragmentName;
1334
+ var lastFragmentPath;
1335
+ var cache={};
1336
+ var defers=[];
1337
+ defers.push({url:'/some_url?_bz=hit.hit2.id%3D1'});
1338
+ defers.push({url:'/some_url?_bz=hit.hit2.id%3D2'});
1339
+ return (
1340
+ {"data":{"hit":{"hit2":[{"id":1},{"id":2}]}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1341
+ );
1342
+ })()
1343
+ JS
1344
+
1345
+ assert_equal expected, result
1346
+ end
1347
+
1348
+ test "rendering with node array deferment using index" do
1349
+ req = action_controller_test_request
1350
+ req.path = '/some_url'
1351
+
1352
+ result = jbuild(<<-JBUILDER, request: req)
1353
+ json.hit do
1354
+ json.hit2 do
1355
+ data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
1356
+ json.array! data, defer: :auto do |item|
1357
+ json.name item[:name]
1358
+ end
1359
+ end
1360
+ end
1361
+ JBUILDER
1362
+ Rails.cache.clear
1363
+
1364
+ expected = strip_format(<<-JS)
1365
+ (function(){
1366
+ var fragments={};
1367
+ var lastFragmentName;
1368
+ var lastFragmentPath;
1369
+ var cache={};
1370
+ var defers=[];
1371
+ defers.push({url:'/some_url?_bz=hit.hit2.0'});
1372
+ defers.push({url:'/some_url?_bz=hit.hit2.1'});
1373
+ return (
1374
+ {"data":{"hit":{"hit2":[undefined,undefined]}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1375
+ );
1376
+ })()
1377
+ JS
1378
+
1379
+ assert_equal expected, result
1380
+ end
1381
+
1382
+ test "rendering with node array deferment on nested node" do
1383
+ req = action_controller_test_request
1384
+ req.path = '/some_url'
1385
+
1140
1386
  result = jbuild(<<-JBUILDER, request: req)
1141
1387
  json.hit do
1142
1388
  json.hit2 do
@@ -1153,13 +1399,15 @@ class BreezyTemplateTest < ActionView::TestCase
1153
1399
 
1154
1400
  expected = strip_format(<<-JS)
1155
1401
  (function(){
1156
- var joints={};
1402
+ var fragments={};
1403
+ var lastFragmentName;
1404
+ var lastFragmentPath;
1157
1405
  var cache={};
1158
1406
  var defers=[];
1159
1407
  defers.push({url:'/some_url?_bz=hit.hit2.id%3D1.greeting'});
1160
1408
  defers.push({url:'/some_url?_bz=hit.hit2.id%3D2.greeting'});
1161
1409
  return (
1162
- {"data":{"hit":{"hit2":[{"greeting":undefined},{"greeting":undefined}]}},"screen":"test","joints":joints,"defers":defers}
1410
+ {"data":{"hit":{"hit2":[{"greeting":undefined},{"greeting":undefined}]}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
1163
1411
  );
1164
1412
  })()
1165
1413
  JS
@@ -1176,10 +1424,12 @@ class BreezyTemplateTest < ActionView::TestCase
1176
1424
 
1177
1425
  expected = strip_format(<<-JS)
1178
1426
  (function(){
1179
- var joints={};
1427
+ var fragments={};
1428
+ var lastFragmentName;
1429
+ var lastFragmentPath;
1180
1430
  var cache={};
1181
1431
  var defers=[];
1182
- return ({"data":{"hello":32},"screen":"test","joints":joints,"defers":defers});
1432
+ return ({"data":{"hello":32},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
1183
1433
  })()
1184
1434
  JS
1185
1435
 
@@ -1196,10 +1446,12 @@ class BreezyTemplateTest < ActionView::TestCase
1196
1446
 
1197
1447
  expected = strip_format(<<-JS)
1198
1448
  (function(){
1199
- var joints={};
1449
+ var fragments={};
1450
+ var lastFragmentName;
1451
+ var lastFragmentPath;
1200
1452
  var cache={};
1201
1453
  var defers=[];
1202
- return ({"data":32,"screen":"test","action":"graft","path":"hello.world","joints":joints,"defers":defers});
1454
+ return ({"data":32,"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hello.world","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
1203
1455
  })()
1204
1456
  JS
1205
1457
 
@@ -1219,11 +1471,13 @@ class BreezyTemplateTest < ActionView::TestCase
1219
1471
 
1220
1472
  expected = strip_format(<<-JS)
1221
1473
  (function(){
1222
- var joints={};
1474
+ var fragments={};
1475
+ var lastFragmentName;
1476
+ var lastFragmentPath;
1223
1477
  var cache={};
1224
1478
  var defers=[];
1225
1479
  defers.push({url:'?_bz=hello.content'});
1226
- return ({"data":{"content":undefined},"screen":"test","action":"graft","path":"hello","joints":joints,"defers":defers});
1480
+ return ({"data":{"content":undefined},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hello","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
1227
1481
  })()
1228
1482
  JS
1229
1483