jbuilder 2.11.2 → 2.11.5

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: '039b14d174dd7bfb3a5e00d5a315aee89f1efd46a570244191ab985bb44fc328'
4
- data.tar.gz: 4eda58d10150903687b7940b858fa02c6f0a2cbca8858cd2ae9866c5be5a4b62
3
+ metadata.gz: 9ce8fbeac8b34ee290535e98a284a1247e2de1b5272c4679c1b89a89ff8149db
4
+ data.tar.gz: cdaeb1302c4755ca43f037328698afe29fe658f2094c99e2c6f81f0000b9368c
5
5
  SHA512:
6
- metadata.gz: 1d20f2794455635cbb3272bd4b6e8f91781e2c55aa40c7228d5347b4b6ad049cd3cc22ebc9ef708b8bbe4a05811774de07770b175035342123458a4637b9240f
7
- data.tar.gz: 383aca1c7489eda135339e4538fa8a9dec80900c7c8bab786729a7c323d63f3a75657889ee6dad6bf91b769ced3eb507e41ef7daa15faa8bb3c5d0261c0c0394
6
+ metadata.gz: 6903b1aa13786fd5501d8e667eb7a913ebd469d24ce183a24cdf949a62788b1e598c2e0678c5ed5e369d4232c7720e284850f735c5be6f4691e4ecf42256d21a
7
+ data.tar.gz: 2a40e415a25a4d8680ac00ba81b9984188ef35440869a357db4fd7184d3f0b36d0ce10545a0d5253e6d12374b2f1d51f5a96f1ded1370ec7eddecaee469afc61
@@ -0,0 +1,108 @@
1
+ name: Ruby test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }})
8
+ runs-on: ubuntu-20.04
9
+ continue-on-error: ${{ matrix.experimental }}
10
+ env:
11
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
12
+ BUNDLE_JOBS: 4
13
+ BUNDLE_RETRY: 3
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby:
18
+ - "2.2"
19
+ - "2.3"
20
+ - "2.4"
21
+ - "2.5"
22
+ - "2.6"
23
+ - "2.7"
24
+ - "3.0"
25
+
26
+ gemfile:
27
+ - "rails_5_0"
28
+ - "rails_5_1"
29
+ - "rails_5_2"
30
+ - "rails_6_0"
31
+ - "rails_6_1"
32
+ - "rails_head"
33
+
34
+ experimental: [false]
35
+ exclude:
36
+ - ruby: 2.7
37
+ gemfile: rails_5_0
38
+ - ruby: '3.0'
39
+ gemfile: rails_5_0
40
+ - ruby: head
41
+ gemfile: rails_5_0
42
+ - ruby: 2.7
43
+ gemfile: rails_5_1
44
+ - ruby: '3.0'
45
+ gemfile: rails_5_1
46
+ - ruby: head
47
+ gemfile: rails_5_1
48
+ - ruby: 2.2
49
+ gemfile: rails_5_2
50
+ - ruby: 2.7
51
+ gemfile: rails_5_2
52
+ - ruby: '3.0'
53
+ gemfile: rails_5_2
54
+ - ruby: head
55
+ gemfile: rails_5_2
56
+ - ruby: 2.2
57
+ gemfile: rails_6_0
58
+ - ruby: 2.3
59
+ gemfile: rails_6_0
60
+ - ruby: 2.4
61
+ gemfile: rails_6_0
62
+ - ruby: '3.0'
63
+ gemfile: rails_6_0
64
+ - ruby: head
65
+ gemfile: rails_6_0
66
+ - ruby: 2.2
67
+ gemfile: rails_6_1
68
+ - ruby: 2.3
69
+ gemfile: rails_6_1
70
+ - ruby: 2.4
71
+ gemfile: rails_6_1
72
+ - ruby: 2.2
73
+ gemfile: rails_head
74
+ - ruby: 2.3
75
+ gemfile: rails_head
76
+ - ruby: 2.4
77
+ gemfile: rails_head
78
+ - ruby: 2.5
79
+ gemfile: rails_head
80
+ - ruby: 2.6
81
+ gemfile: rails_head
82
+ - ruby: 2.7
83
+ gemfile: rails_head
84
+ experimental: false
85
+ - ruby: '3.0'
86
+ gemfile: rails_head
87
+ experimental: false
88
+ include:
89
+ - ruby: 2.7
90
+ gemfile: rails_head
91
+ experimental: true
92
+ - ruby: '3.0'
93
+ gemfile: rails_head
94
+ experimental: true
95
+ - ruby: head
96
+ gemfile: rails_head
97
+ experimental: true
98
+
99
+ steps:
100
+ - uses: actions/checkout@v2
101
+
102
+ - uses: ruby/setup-ruby@v1
103
+ with:
104
+ ruby-version: ${{ matrix.ruby }}
105
+ bundler-cache: true
106
+
107
+ - name: Ruby test
108
+ run: bundle exec rake
data/Appraisals CHANGED
@@ -15,7 +15,11 @@ if RUBY_VERSION >= "2.5.0"
15
15
  gem "rails", "~> 6.0.0"
16
16
  end
17
17
 
18
+ appraise "rails-6-1" do
19
+ gem "rails", "~> 6.1.0"
20
+ end
21
+
18
22
  appraise "rails-head" do
19
- gem "rails", github: "rails/rails"
23
+ gem "rails", github: "rails/rails", branch: "main"
20
24
  end
21
25
  end
data/CONTRIBUTING.md CHANGED
@@ -1,11 +1,11 @@
1
1
  Contributing to Jbuilder
2
2
  =====================
3
3
 
4
- [![Build Status](https://api.travis-ci.org/rails/jbuilder.svg?branch=master)][travis]
4
+ [![Build Status](https://github.com/rails/jbuilder/workflows/Ruby%20test/badge.svg)][test]
5
5
  [![Gem Version](https://badge.fury.io/rb/jbuilder.svg)][gem]
6
6
  [![Code Climate](https://codeclimate.com/github/rails/jbuilder/badges/gpa.svg)][codeclimate]
7
7
 
8
- [travis]: https://travis-ci.org/rails/jbuilder
8
+ [test]: https://github.com/rails/jbuilder/actions?query=branch%3Amaster
9
9
  [gem]: https://rubygems.org/gems/jbuilder
10
10
  [codeclimate]: https://codeclimate.com/github/rails/jbuilder
11
11
 
@@ -95,7 +95,7 @@ git push origin my-feature-branch -f
95
95
 
96
96
  #### Check on Your Pull Request
97
97
 
98
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
98
+ Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above.
99
99
 
100
100
  #### Be Patient
101
101
 
data/README.md CHANGED
@@ -108,6 +108,33 @@ json.array! @people, :id, :name
108
108
  # => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ]
109
109
  ```
110
110
 
111
+ To make a plain array without keys, construct and pass in a standard Ruby array.
112
+
113
+ ```ruby
114
+ my_array = %w(David Jamie)
115
+
116
+ json.people my_array
117
+
118
+ # => "people": [ "David", "Jamie" ]
119
+ ```
120
+
121
+ You don't always have or need a collection when building an array.
122
+
123
+ ```ruby
124
+ json.people do
125
+ json.child! do
126
+ json.id 1
127
+ json.name 'David'
128
+ end
129
+ json.child! do
130
+ json.id 2
131
+ json.name 'Jamie'
132
+ end
133
+ end
134
+
135
+ # => { "people": [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] }
136
+ ```
137
+
111
138
  Jbuilder objects can be directly nested inside each other. Useful for composing objects.
112
139
 
113
140
  ``` ruby
@@ -137,7 +164,7 @@ company.to_builder.target!
137
164
  ```
138
165
 
139
166
  You can either use Jbuilder stand-alone or directly as an ActionView template
140
- language. When required in Rails, you can create views a la show.json.jbuilder
167
+ language. When required in Rails, you can create views à la show.json.jbuilder
141
168
  (the json is already yielded):
142
169
 
143
170
  ``` ruby
@@ -171,19 +198,19 @@ It's also possible to render collections of partials:
171
198
  json.array! @posts, partial: 'posts/post', as: :post
172
199
 
173
200
  # or
174
-
175
201
  json.partial! 'posts/post', collection: @posts, as: :post
176
202
 
177
203
  # or
178
-
179
204
  json.partial! partial: 'posts/post', collection: @posts, as: :post
180
205
 
181
206
  # or
182
-
183
207
  json.comments @post.comments, partial: 'comments/comment', as: :comment
184
208
  ```
185
209
 
186
- The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`.
210
+ The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the
211
+ partial. If the value is a collection either implicitly or explicitly by using the `collection:` option, then each
212
+ value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object,
213
+ then the object is passed to the partial as the variable `some_symbol`.
187
214
 
188
215
  Be sure not to confuse the `as:` option to mean nesting of the partial. For example:
189
216
 
@@ -193,7 +220,7 @@ Be sure not to confuse the `as:` option to mean nesting of the partial. For exam
193
220
  json.partial! @comment, as: :comment
194
221
  ```
195
222
 
196
- is quite different than:
223
+ is quite different from:
197
224
 
198
225
  ```ruby
199
226
  # comment attributes are nested under a "comment" property
@@ -236,6 +263,8 @@ json.bar "bar"
236
263
  # => { "bar": "bar" }
237
264
  ```
238
265
 
266
+ ## Caching
267
+
239
268
  Fragment caching is supported, it uses `Rails.cache` and works like caching in
240
269
  HTML templates:
241
270
 
@@ -253,9 +282,25 @@ json.cache_if! !admin?, ['v1', @person], expires_in: 10.minutes do
253
282
  end
254
283
  ```
255
284
 
256
- If you are rendering fragments for a collection of objects, have a look at
257
- `jbuilder_cache_multi` gem. It uses fetch_multi (>= Rails 4.1) to fetch
258
- multiple keys at once.
285
+ Aside from that, the `:cached` options on collection rendering is available on Rails >= 6.0. This will cache the
286
+ rendered results effectively using the multi fetch feature.
287
+
288
+ ```ruby
289
+ json.array! @posts, partial: "posts/post", as: :post, cached: true
290
+
291
+ # or:
292
+ json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true
293
+ ```
294
+
295
+ If your collection cache depends on multiple sources (try to avoid this to keep things simple), you can name all these dependencies as part of a block that returns an array:
296
+
297
+ ```ruby
298
+ json.array! @posts, partial: "posts/post", as: :post, cached: -> post { [post, current_user] }
299
+ ```
300
+
301
+ This will include both records as part of the cache key and updating either of them will expire the cache.
302
+
303
+ ## Formatting Keys
259
304
 
260
305
  Keys can be auto formatted using `key_format!`, this can be used to convert
261
306
  keynames from the standard ruby_format to camelCase:
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "bundler/setup"
2
2
  require "bundler/gem_tasks"
3
3
  require "rake/testtask"
4
4
 
5
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
5
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"]
6
6
  require "appraisal/task"
7
7
  Appraisal::Task.new
8
8
  task default: :appraisal
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", "~> 6.1.0"
9
+
10
+ gemspec path: "../"
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "rails", github: "rails/rails"
8
+ gem "rails", github: "rails/rails", branch: "main"
9
9
 
10
10
  gemspec path: "../"
data/jbuilder.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.11.2'
3
+ s.version = '2.11.5'
4
4
  s.authors = 'David Heinemeier Hansson'
5
5
  s.email = 'david@basecamp.com'
6
6
  s.summary = 'Create JSON structures via a Builder-style DSL'
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.required_ruby_version = '>= 2.2.2'
11
11
 
12
12
  s.add_dependency 'activesupport', '>= 5.0.0'
13
+ s.add_dependency 'actionview', '>= 5.0.0'
13
14
 
14
15
  if RUBY_ENGINE == 'rbx'
15
16
  s.add_development_dependency('racc')
@@ -19,4 +20,12 @@ Gem::Specification.new do |s|
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.test_files = `git ls-files -- test/*`.split("\n")
23
+
24
+ s.metadata = {
25
+ "bug_tracker_uri" => "https://github.com/rails/jbuilder/issues",
26
+ "changelog_uri" => "https://github.com/rails/jbuilder/releases/tag/v#{s.version}",
27
+ "mailing_list_uri" => "https://discuss.rubyonrails.org/c/rubyonrails-talk",
28
+ "source_code_uri" => "https://github.com/rails/jbuilder/tree/v#{s.version}",
29
+ "rubygems_mfa_required" => "true",
30
+ }
22
31
  end
@@ -30,7 +30,7 @@ class <%= controller_class_name %>Controller < ApplicationController
30
30
 
31
31
  respond_to do |format|
32
32
  if @<%= orm_instance.save %>
33
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully created.") %> }
33
+ format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully created.") %> }
34
34
  format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
35
35
  else
36
36
  format.html { render :new, status: :unprocessable_entity }
@@ -43,7 +43,7 @@ class <%= controller_class_name %>Controller < ApplicationController
43
43
  def update
44
44
  respond_to do |format|
45
45
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
46
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully updated.") %> }
46
+ format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully updated.") %> }
47
47
  format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
48
48
  else
49
49
  format.html { render :edit, status: :unprocessable_entity }
@@ -55,6 +55,7 @@ class <%= controller_class_name %>Controller < ApplicationController
55
55
  # DELETE <%= route_url %>/1 or <%= route_url %>/1.json
56
56
  def destroy
57
57
  @<%= orm_instance.destroy %>
58
+
58
59
  respond_to do |format|
59
60
  format.html { redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %> }
60
61
  format.json { head :no_content }
@@ -0,0 +1,109 @@
1
+ require 'delegate'
2
+ require 'active_support/concern'
3
+ require 'action_view'
4
+
5
+ begin
6
+ require 'action_view/renderer/collection_renderer'
7
+ rescue LoadError
8
+ require 'action_view/renderer/partial_renderer'
9
+ end
10
+
11
+ class Jbuilder
12
+ module CollectionRenderable # :nodoc:
13
+ extend ActiveSupport::Concern
14
+
15
+ class_methods do
16
+ def supported?
17
+ superclass.private_method_defined?(:build_rendered_template) && self.superclass.private_method_defined?(:build_rendered_collection)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def build_rendered_template(content, template, layout = nil)
24
+ super(content || json.attributes!, template)
25
+ end
26
+
27
+ def build_rendered_collection(templates, _spacer)
28
+ json.merge!(templates.map(&:body))
29
+ end
30
+
31
+ def json
32
+ @options[:locals].fetch(:json)
33
+ end
34
+
35
+ class ScopedIterator < ::SimpleDelegator # :nodoc:
36
+ include Enumerable
37
+
38
+ def initialize(obj, scope)
39
+ super(obj)
40
+ @scope = scope
41
+ end
42
+
43
+ # Rails 6.0 support:
44
+ def each
45
+ return enum_for(:each) unless block_given?
46
+
47
+ __getobj__.each do |object|
48
+ @scope.call { yield(object) }
49
+ end
50
+ end
51
+
52
+ # Rails 6.1 support:
53
+ def each_with_info
54
+ return enum_for(:each_with_info) unless block_given?
55
+
56
+ __getobj__.each_with_info do |object, info|
57
+ @scope.call { yield(object, info) }
58
+ end
59
+ end
60
+ end
61
+
62
+ private_constant :ScopedIterator
63
+ end
64
+
65
+ if defined?(::ActionView::CollectionRenderer)
66
+ # Rails 6.1 support:
67
+ class CollectionRenderer < ::ActionView::CollectionRenderer # :nodoc:
68
+ include CollectionRenderable
69
+
70
+ def initialize(lookup_context, options, &scope)
71
+ super(lookup_context, options)
72
+ @scope = scope
73
+ end
74
+
75
+ private
76
+ def collection_with_template(view, template, layout, collection)
77
+ super(view, template, layout, ScopedIterator.new(collection, @scope))
78
+ end
79
+ end
80
+ else
81
+ # Rails 6.0 support:
82
+ class CollectionRenderer < ::ActionView::PartialRenderer # :nodoc:
83
+ include CollectionRenderable
84
+
85
+ def initialize(lookup_context, options, &scope)
86
+ super(lookup_context)
87
+ @options = options
88
+ @scope = scope
89
+ end
90
+
91
+ def render_collection_with_partial(collection, partial, context, block)
92
+ render(context, @options.merge(collection: collection, partial: partial), block)
93
+ end
94
+
95
+ private
96
+ def collection_without_template(view)
97
+ @collection = ScopedIterator.new(@collection, @scope)
98
+
99
+ super(view)
100
+ end
101
+
102
+ def collection_with_template(view, template)
103
+ @collection = ScopedIterator.new(@collection, @scope)
104
+
105
+ super(view, template)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -1,4 +1,5 @@
1
1
  require 'jbuilder/jbuilder'
2
+ require 'jbuilder/collection_renderer'
2
3
  require 'action_dispatch/http/mime_type'
3
4
  require 'active_support/cache'
4
5
 
@@ -15,6 +16,38 @@ class JbuilderTemplate < Jbuilder
15
16
  super(*args)
16
17
  end
17
18
 
19
+ # Generates JSON using the template specified with the `:partial` option. For example, the code below will render
20
+ # the file `views/comments/_comments.json.jbuilder`, and set a local variable comments with all this message's
21
+ # comments, which can be used inside the partial.
22
+ #
23
+ # Example:
24
+ #
25
+ # json.partial! 'comments/comments', comments: @message.comments
26
+ #
27
+ # There are multiple ways to generate a collection of elements as JSON, as ilustrated below:
28
+ #
29
+ # Example:
30
+ #
31
+ # json.array! @posts, partial: 'posts/post', as: :post
32
+ #
33
+ # # or:
34
+ # json.partial! 'posts/post', collection: @posts, as: :post
35
+ #
36
+ # # or:
37
+ # json.partial! partial: 'posts/post', collection: @posts, as: :post
38
+ #
39
+ # # or:
40
+ # json.comments @post.comments, partial: 'comments/comment', as: :comment
41
+ #
42
+ # Aside from that, the `:cached` options is available on Rails >= 6.0. This will cache the rendered results
43
+ # effectively using the multi fetch feature.
44
+ #
45
+ # Example:
46
+ #
47
+ # json.array! @posts, partial: "posts/post", as: :post, cached: true
48
+ #
49
+ # json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true
50
+ #
18
51
  def partial!(*args)
19
52
  if args.one? && _is_active_model?(args.first)
20
53
  _render_active_model_partial args.first
@@ -104,11 +137,30 @@ class JbuilderTemplate < Jbuilder
104
137
  private
105
138
 
106
139
  def _render_partial_with_options(options)
107
- options.reverse_merge! locals: options.except(:partial, :as, :collection)
140
+ options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached)
108
141
  options.reverse_merge! ::JbuilderTemplate.template_lookup_options
109
142
  as = options[:as]
110
143
 
111
- if as && options.key?(:collection)
144
+ if as && options.key?(:collection) && CollectionRenderer.supported?
145
+ collection = options.delete(:collection) || []
146
+ partial = options.delete(:partial)
147
+ options[:locals].merge!(json: self)
148
+
149
+ if options.has_key?(:layout)
150
+ raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering."
151
+ end
152
+
153
+ if options.has_key?(:spacer_template)
154
+ raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering."
155
+ end
156
+
157
+ results = CollectionRenderer
158
+ .new(@context.lookup_context, options) { |&block| _scope(&block) }
159
+ .render_collection_with_partial(collection, partial, @context, nil)
160
+
161
+ array! if results.respond_to?(:body) && results.body.nil?
162
+ elsif as && options.key?(:collection) && !CollectionRenderer.supported?
163
+ # For Rails <= 5.2:
112
164
  as = as.to_sym
113
165
  collection = options.delete(:collection)
114
166
  locals = options.delete(:locals)
@@ -162,12 +214,7 @@ class JbuilderTemplate < Jbuilder
162
214
 
163
215
  def _fragment_name_with_digest(key, options)
164
216
  if @context.respond_to?(:cache_fragment_name)
165
- # Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
166
- # should be used instead.
167
217
  @context.cache_fragment_name(key, **options)
168
- elsif @context.respond_to?(:fragment_name_with_digest)
169
- # Backwards compatibility for period of time when fragment_name_with_digest was made public.
170
- @context.fragment_name_with_digest(key)
171
218
  else
172
219
  key
173
220
  end
@@ -1,4 +1,4 @@
1
- require 'rails/railtie'
1
+ require 'rails'
2
2
  require 'jbuilder/jbuilder_template'
3
3
 
4
4
  class Jbuilder
data/lib/jbuilder.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'jbuilder/jbuilder'
2
3
  require 'jbuilder/blank'
3
4
  require 'jbuilder/key_formatter'
@@ -61,7 +61,7 @@ class JbuilderDependencyTrackerTest < ActiveSupport::TestCase
61
61
  assert_equal %w[comments/comment], dependencies
62
62
  end
63
63
 
64
- test 'detects explicit depedency' do
64
+ test 'detects explicit dependency' do
65
65
  dependencies = track_dependencies <<-RUBY
66
66
  # Template Dependency: path/to/partial
67
67
  json.foo 'bar'
@@ -159,7 +159,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
159
159
  end
160
160
 
161
161
  test "object fragment caching with expiry" do
162
- travel_to "2018-05-12 11:29:00 -0400"
162
+ travel_to Time.iso8601("2018-05-12T11:29:00-04:00")
163
163
 
164
164
  render <<-JBUILDER
165
165
  json.cache! "cache-key", expires_in: 1.minute do
@@ -283,6 +283,101 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
283
283
  assert_equal "David", result["firstName"]
284
284
  end
285
285
 
286
+ if JbuilderTemplate::CollectionRenderer.supported?
287
+ test "returns an empty array for an empty collection" do
288
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: [])
289
+
290
+ # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
291
+ assert_equal [], result
292
+ end
293
+
294
+ test "works with an enumerable object" do
295
+ enumerable_class = Class.new do
296
+ include Enumerable
297
+ alias length count # Rails 6.1 requires this.
298
+
299
+ def each(&block)
300
+ [].each(&block)
301
+ end
302
+ end
303
+
304
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: enumerable_class.new)
305
+
306
+ # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
307
+ assert_equal [], result
308
+ end
309
+
310
+ test "supports the cached: true option" do
311
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
312
+
313
+ assert_equal 10, result.count
314
+ assert_equal "Post #5", result[4]["body"]
315
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
316
+ assert_equal "Pavel", result[5]["author"]["first_name"]
317
+
318
+ expected = {
319
+ "id" => 1,
320
+ "body" => "Post #1",
321
+ "author" => {
322
+ "first_name" => "David",
323
+ "last_name" => "Heinemeier Hansson"
324
+ }
325
+ }
326
+
327
+ assert_equal expected, Rails.cache.read("post-1")
328
+
329
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
330
+
331
+ assert_equal 10, result.count
332
+ assert_equal "Post #5", result[4]["body"]
333
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
334
+ assert_equal "Pavel", result[5]["author"]["first_name"]
335
+ end
336
+
337
+ test "supports the cached: ->() {} option" do
338
+ result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
339
+
340
+ assert_equal 10, result.count
341
+ assert_equal "Post #5", result[4]["body"]
342
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
343
+ assert_equal "Pavel", result[5]["author"]["first_name"]
344
+
345
+ expected = {
346
+ "id" => 1,
347
+ "body" => "Post #1",
348
+ "author" => {
349
+ "first_name" => "David",
350
+ "last_name" => "Heinemeier Hansson"
351
+ }
352
+ }
353
+
354
+ assert_equal expected, Rails.cache.read("post-1/foo")
355
+
356
+ result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
357
+
358
+ assert_equal 10, result.count
359
+ assert_equal "Post #5", result[4]["body"]
360
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
361
+ assert_equal "Pavel", result[5]["author"]["first_name"]
362
+ end
363
+
364
+ test "raises an error on a render call with the :layout option" do
365
+ error = assert_raises NotImplementedError do
366
+ render('json.array! @posts, partial: "post", as: :post, layout: "layout"', posts: POSTS)
367
+ end
368
+
369
+ assert_equal "The `:layout' option is not supported in collection rendering.", error.message
370
+ end
371
+
372
+ test "raises an error on a render call with the :spacer_template option" do
373
+ error = assert_raises NotImplementedError do
374
+ render('json.array! @posts, partial: "post", as: :post, spacer_template: "template"', posts: POSTS)
375
+ end
376
+
377
+ assert_equal "The `:spacer_template' option is not supported in collection rendering.", error.message
378
+ end
379
+ end
380
+
286
381
  private
287
382
  def render(*args)
288
383
  JSON.load render_without_parsing(*args)
@@ -290,7 +385,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
290
385
 
291
386
  def render_without_parsing(source, assigns = {})
292
387
  view = build_view(fixtures: PARTIALS.merge("source.json.jbuilder" => source), assigns: assigns)
293
- view.render(template: "source.json.jbuilder")
388
+ view.render(template: "source")
294
389
  end
295
390
 
296
391
  def build_view(options = {})
@@ -306,6 +401,9 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
306
401
  end
307
402
 
308
403
  def view.view_cache_dependencies; []; end
404
+ def view.combined_fragment_cache_key(key) [ key ] end
405
+ def view.cache_fragment_name(key, *) key end
406
+ def view.fragment_name_with_digest(key) key end
309
407
 
310
408
  view
311
409
  end
@@ -312,7 +312,7 @@ class JbuilderTest < ActiveSupport::TestCase
312
312
  assert_equal 'world', result['comments'].second['content']
313
313
  end
314
314
 
315
- test 'nesting multiple chilren from a non-Enumerable that responds to #map with inline loop' do
315
+ test 'nesting multiple children from a non-Enumerable that responds to #map with inline loop' do
316
316
  comments = NonEnumerable.new([ Comment.new('hello', 1), Comment.new('world', 2) ])
317
317
 
318
318
  result = jbuild do |json|
@@ -47,7 +47,7 @@ if Rails::VERSION::MAJOR > 4
47
47
  end
48
48
  end
49
49
 
50
- test 'dont use require and permit if there are no attributes' do
50
+ test "don't use require and permit if there are no attributes" do
51
51
  run_generator %w(Post --api)
52
52
 
53
53
  assert_file 'app/controllers/posts_controller.rb' do |content|
@@ -31,14 +31,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
31
31
  assert_instance_method :create, content do |m|
32
32
  assert_match %r{@post = Post\.new\(post_params\)}, m
33
33
  assert_match %r{@post\.save}, m
34
- assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully created\." \}}, m
34
+ assert_match %r{format\.html \{ redirect_to post_url\(@post\), notice: "Post was successfully created\." \}}, m
35
35
  assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m
36
36
  assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m
37
37
  assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m
38
38
  end
39
39
 
40
40
  assert_instance_method :update, content do |m|
41
- assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\." \}}, m
41
+ assert_match %r{format\.html \{ redirect_to post_url\(@post\), notice: "Post was successfully updated\." \}}, m
42
42
  assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
43
43
  assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m
44
44
  assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
@@ -59,7 +59,26 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
59
59
  end
60
60
  end
61
61
 
62
- test 'dont use require and permit if there are no attributes' do
62
+ if Rails::VERSION::MAJOR >= 6
63
+ test 'controller with namespace' do
64
+ run_generator %w(Admin::Post --model-name=Post)
65
+ assert_file 'app/controllers/admin/posts_controller.rb' do |content|
66
+ assert_instance_method :create, content do |m|
67
+ assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully created\." \}}, m
68
+ end
69
+
70
+ assert_instance_method :update, content do |m|
71
+ assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully updated\." \}}, m
72
+ end
73
+
74
+ assert_instance_method :destroy, content do |m|
75
+ assert_match %r{format\.html \{ redirect_to admin_posts_url, notice: "Post was successfully destroyed\." \}}, m
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ test "don't use require and permit if there are no attributes" do
63
82
  run_generator %w(Post)
64
83
 
65
84
  assert_file 'app/controllers/posts_controller.rb' do |content|
data/test/test_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  require "bundler/setup"
2
2
 
3
- require "active_support"
3
+ require "rails"
4
+
5
+ require "jbuilder"
6
+
4
7
  require "active_support/core_ext/array/access"
5
8
  require "active_support/cache/memory_store"
6
9
  require "active_support/json"
7
10
  require "active_model"
8
- require "action_view"
9
- require "rails/version"
10
-
11
- require "jbuilder"
12
11
 
13
12
  require "active_support/testing/autorun"
14
13
  require "mocha/minitest"
@@ -21,7 +20,13 @@ class << Rails
21
20
  end
22
21
  end
23
22
 
24
- class Post < Struct.new(:id, :body, :author_name); end
23
+ Jbuilder::CollectionRenderer.collection_cache = Rails.cache
24
+
25
+ class Post < Struct.new(:id, :body, :author_name)
26
+ def cache_key
27
+ "post-#{id}"
28
+ end
29
+ end
25
30
 
26
31
  class Racer < Struct.new(:id, :name)
27
32
  extend ActiveModel::Naming
@@ -29,6 +34,3 @@ class Racer < Struct.new(:id, :name)
29
34
  end
30
35
 
31
36
  ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
32
-
33
- ActionView::Base.remove_possible_method :fragment_name_with_digest
34
- ActionView::Base.remove_possible_method :cache_fragment_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.2
4
+ version: 2.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,16 +24,29 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0
27
41
  description:
28
42
  email: david@basecamp.com
29
43
  executables: []
30
44
  extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
47
+ - ".github/workflows/ruby.yml"
33
48
  - ".gitignore"
34
- - ".travis.yml"
35
49
  - Appraisals
36
- - CHANGELOG.md
37
50
  - CONTRIBUTING.md
38
51
  - Gemfile
39
52
  - MIT-LICENSE
@@ -43,6 +56,7 @@ files:
43
56
  - gemfiles/rails_5_1.gemfile
44
57
  - gemfiles/rails_5_2.gemfile
45
58
  - gemfiles/rails_6_0.gemfile
59
+ - gemfiles/rails_6_1.gemfile
46
60
  - gemfiles/rails_head.gemfile
47
61
  - jbuilder.gemspec
48
62
  - lib/generators/rails/jbuilder_generator.rb
@@ -54,6 +68,7 @@ files:
54
68
  - lib/generators/rails/templates/show.json.jbuilder
55
69
  - lib/jbuilder.rb
56
70
  - lib/jbuilder/blank.rb
71
+ - lib/jbuilder/collection_renderer.rb
57
72
  - lib/jbuilder/dependency_tracker.rb
58
73
  - lib/jbuilder/errors.rb
59
74
  - lib/jbuilder/jbuilder.rb
@@ -70,7 +85,12 @@ files:
70
85
  homepage: https://github.com/rails/jbuilder
71
86
  licenses:
72
87
  - MIT
73
- metadata: {}
88
+ metadata:
89
+ bug_tracker_uri: https://github.com/rails/jbuilder/issues
90
+ changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.11.5
91
+ mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
92
+ source_code_uri: https://github.com/rails/jbuilder/tree/v2.11.5
93
+ rubygems_mfa_required: 'true'
74
94
  post_install_message:
75
95
  rdoc_options: []
76
96
  require_paths:
@@ -86,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
106
  - !ruby/object:Gem::Version
87
107
  version: '0'
88
108
  requirements: []
89
- rubygems_version: 3.1.2
109
+ rubygems_version: 3.2.32
90
110
  signing_key:
91
111
  specification_version: 4
92
112
  summary: Create JSON structures via a Builder-style DSL
data/.travis.yml DELETED
@@ -1,52 +0,0 @@
1
- language: ruby
2
-
3
- cache: bundler
4
-
5
- before_install:
6
- - "gem install bundler -v '<2'"
7
-
8
- rvm:
9
- - 2.2.10
10
- - 2.3.8
11
- - 2.4.10
12
- - 2.5.8
13
- - 2.6.6
14
- - 2.7.1
15
- - ruby-head
16
-
17
- gemfile:
18
- - gemfiles/rails_5_0.gemfile
19
- - gemfiles/rails_5_1.gemfile
20
- - gemfiles/rails_5_2.gemfile
21
- - gemfiles/rails_6_0.gemfile
22
- - gemfiles/rails_head.gemfile
23
-
24
- matrix:
25
- exclude:
26
- - rvm: 2.7.1
27
- gemfile: gemfiles/rails_5_0.gemfile
28
- - rvm: 2.7.1
29
- gemfile: gemfiles/rails_5_1.gemfile
30
- - rvm: 2.2.10
31
- gemfile: gemfiles/rails_5_2.gemfile
32
- - rvm: 2.7.1
33
- gemfile: gemfiles/rails_5_2.gemfile
34
- - rvm: 2.2.10
35
- gemfile: gemfiles/rails_6_0.gemfile
36
- - rvm: 2.3.8
37
- gemfile: gemfiles/rails_6_0.gemfile
38
- - rvm: 2.4.10
39
- gemfile: gemfiles/rails_6_0.gemfile
40
- - rvm: 2.2.10
41
- gemfile: gemfiles/rails_head.gemfile
42
- - rvm: 2.3.8
43
- gemfile: gemfiles/rails_head.gemfile
44
- - rvm: 2.4.10
45
- gemfile: gemfiles/rails_head.gemfile
46
- allow_failures:
47
- - rvm: ruby-head
48
- - gemfile: gemfiles/rails_head.gemfile
49
- fast_finish: true
50
-
51
- notifications:
52
- email: false
data/CHANGELOG.md DELETED
@@ -1,311 +0,0 @@
1
- # Changelog
2
-
3
- 2.11.2
4
- ------
5
-
6
- * [Improve key formatting for nested hashes and disable by default](https://github.com/rails/jbuilder/pull/497)
7
-
8
- 2.11.1
9
- ------
10
-
11
- * Use symbols instead of strings for before_action filters [DHH]
12
- * Slim down comments in generated scaffold code [DHH]
13
-
14
- 2.11.0
15
- ------
16
-
17
- * [Allow jbuilder instance to be passed to #merge!](https://github.com/rails/jbuilder/pull/485)
18
- * [Fix for key_format! when using nested hashes](https://github.com/rails/jbuilder/pull/486)
19
- * [Include rich_text, attachment, and attachments fields in json partial](https://github.com/rails/jbuilder/pull/459)
20
-
21
- 2.10.2
22
- ------
23
-
24
- * Update scaffold generator to use double quotes, 422 form error responds, and modern string-of-arrays syntax [DHH]
25
-
26
- 2.10.1
27
- ------
28
-
29
- * Fix keyword arguments warning on Ruby 2.7
30
-
31
- 2.10.0
32
- ------
33
-
34
- * Requires Rails 5+ and Ruby 2.2+
35
- * Nested hashes are deep-merged
36
-
37
- 2.9.1
38
- -----
39
-
40
- * [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7afe1166)
41
-
42
- 2.9.0
43
- -----
44
-
45
- * [Fix passing object with partial without locals](https://github.com/rails/jbuilder/pull/435)
46
- * [Fix deprecation warning in Rails 6.0](https://github.com/rails/jbuilder/pull/453)
47
- * [Use quotes consistently in generated templates](https://github.com/rails/jbuilder/pull/455)
48
- * [Allow omitting timestamps from generated partials](https://github.com/rails/jbuilder/pull/448)
49
- * [Respect changing scaffold generator](https://github.com/rails/jbuilder/pull/458)
50
- * [Use a symbolic default format for Rails 6.0 forward compatibility](https://github.com/rails/jbuilder/commit/3895a7243f3db292b0bf15513fc05494e6e50576)
51
- * [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba62311494ec49)
52
-
53
- 2.8.0
54
- -----
55
-
56
- * [Replace deprecated fragment_cache_key for Rails 5.2 support](https://github.com/rails/jbuilder/pull/430)
57
-
58
- 2.7.0
59
- -----
60
-
61
- * [Requires Rails 4+](https://github.com/rails/jbuilder/commit/5207ff394533177fffdd768bfaa6413a0cd16dc8)
62
- * [Fix implicitly rendering a JSON partial with the same name as an
63
- HTML partial](https://github.com/rails/jbuilder/pull/400)
64
-
65
- 2.6.4
66
- -----
67
-
68
- * Drop the pessimistic upper-bound restriction on Active Support and MultiJSON to prevent future gemfile resolution deadlocks *DHH*
69
-
70
- 2.6.3
71
- -----
72
-
73
- * Support Rails 5.1
74
-
75
- 2.6.2
76
- -----
77
-
78
- * Fix thor warnings
79
-
80
- 2.6.1
81
- -----
82
-
83
- * [Optimize root caches with cache_root!](https://github.com/rails/jbuilder/pull/370)
84
-
85
- 2.6.0
86
- -----
87
-
88
- * [Rails 5 cache! with expire support](https://github.com/rails/jbuilder/commit/d61e3354563863731bc1f358f495b1dbb7ae9d32)
89
- * [Generated view DRYed by using model partial](https://github.com/rails/jbuilder/commit/83256f4d7e9211c9dc47972feaed7fd31e4f7cac)
90
-
91
- 2.5.0
92
- -----
93
-
94
- * [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/64c510ec69d9e63b73ffd5942e802d21a7d14701)
95
-
96
- 2.4.1
97
- -----
98
-
99
- * [Fix controller generators to be Rails 5 compatible](https://github.com/rails/jbuilder/commit/2dc6203c5c4a98701d5b64c2a5200835a48bb533)
100
-
101
- 2.4.0
102
- -----
103
-
104
- * [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/4aa2cfcc19a4634d65a28ffc75f0ac0cb8304115)
105
-
106
- 2.3.2
107
- -----
108
-
109
- * [Remove Mime Types deprecation message](https://github.com/rails/jbuilder/commit/5ba4e4ac654cc8388619538f576fe234659b84ec)
110
-
111
- 2.3.1
112
- -----
113
-
114
- * [Explicitly require ostruct to prevent NameError](https://github.com/rails/jbuilder/pull/281)
115
-
116
- 2.3.0
117
- -----
118
-
119
- * [Add new in-place partial invocation support](https://github.com/rails/jbuilder/commit/1feda7ee605c136e59fb4de970f4674de518e6de)
120
- * [Add implicit partial rendering for AM::Models](https://github.com/rails/jbuilder/commit/4d5bf7d0ea92765adb7be36834e84f9855a061df)
121
- * [Generate API controller if Rails API option is enabled](https://github.com/rails/jbuilder/commit/db68f6bd327cf42b47ef22d455fb5721a8c2cf5f)
122
- * [JBuilder's templates have less priority than app templates](https://github.com/rails/jbuilder/commit/7c1a5f25603ec1f4e51fba3dbba9db23726a5d69)
123
- * [Add AC::Helpers module to jbuilder for api only apps](https://github.com/rails/jbuilder/commit/7cf1d1eb7d125caf38309b5427952030011c1aa0)
124
-
125
- 2.2.16
126
- ------
127
-
128
- * [Fix NoMethodError around `api_only` in railtie](https://github.com/rails/jbuilder/commit/b08d1da10b14720b46d383b2917e336060fd9ffa)
129
-
130
- 2.2.14
131
- ------
132
-
133
- * [Make Jbuilder compatible with Rails API](https://github.com/rails/jbuilder/commit/29c0014a9c954c990075d42c45c66075260e924b)
134
-
135
- 2.2.13
136
- ------
137
-
138
- * Several performance optimizations: [#260](https://github.com/rails/jbuilder/pull/260) & [#261](https://github.com/rails/jbuilder/pull/261)
139
-
140
- 2.2.12
141
- ------
142
-
143
- * [Replace explicit block calls with yield for performance](https://github.com/rails/jbuilder/commit/3184f941276ad03a071cf977133d1a32302afa47)
144
-
145
- 2.2.11
146
- ------
147
-
148
- * Generate the templates for Rails 5+ [#258](https://github.com/rails/jbuilder/pull/258) [@amatsuda](https://github.com/amatsuda)
149
-
150
- 2.2.10
151
- ------
152
-
153
- * Add Jbuilder::Blank#empty? to tell if attributes are empty [#257](https://github.com/rails/jbuilder/pull/257) [@a2ikm](https://github.com/a2ikm)
154
-
155
- 2.2.9
156
- -----
157
-
158
- * Support `partial!` call with `locals` option in `JbuilderTemplate` [#251](https://github.com/rails/jbuilder/pull/251)
159
-
160
- 2.2.8
161
- -----
162
- * [Raise ArrayError when trying to add key to an array](https://github.com/rails/jbuilder/commit/869e4be1ad165ce986d8fca78311bdd3ed166087)
163
-
164
- 2.2.7
165
- -----
166
- * [Make Blank object serializable with Marshal](https://github.com/rails/jbuilder/commit/7083f28d8b665aa60d0d1b1927ae88bb5c6290ba)
167
-
168
- 2.2.6
169
- -----
170
- * [Make sure dependency tracker loads after template handler](https://github.com/rails/jbuilder/commit/3ba404b1207b557e14771c90b8832bc01ae67a42)
171
-
172
- 2.2.5
173
- -----
174
- * [Refactor merge block behavior to raise error for unexpected values](https://github.com/rails/jbuilder/commit/4503162fb26f53f613fc83ac081fd244748b6fe9)
175
-
176
- 2.2.4
177
- -----
178
- * [Typecast locals hash key during collection render](https://github.com/rails/jbuilder/commit/a6b0c8651a08e01cb53eee38e211c65423f275f7)
179
-
180
- 2.2.3
181
- -----
182
- * [Move template handler registration into railtie](https://github.com/rails/jbuilder/commit/c8acc5cea6da2a79b7b345adc301cb5ff2517647)
183
- * [Do not capture the block where it is possible](https://github.com/rails/jbuilder/commit/973b382c3924cb59fc0e4e25266b18e74d41d646)
184
-
185
- 2.2.2
186
- -----
187
- * [Fix `Jbuilder#merge!` inside block](https://github.com/rails/jbuilder/commit/a7b328552eb0d36315f75bff813bea7eecf8c1d7)
188
-
189
- 2.2.1
190
- -----
191
- * [Fix empty block handling](https://github.com/rails/jbuilder/commit/972a11141403269e9b17b45b0c95f8a9788245ee)
192
-
193
- 2.2.0
194
- -----
195
- * [Allow to skip `array!` iterations by calling `next`](https://github.com/rails/jbuilder/commit/81a63308fb9d5002519dd871f829ccc58067251a)
196
-
197
- 2.1.2
198
- -----
199
- * [Cast array-like objects to array before merging](https://github.com/rails/jbuilder/commit/7b8c8a1cb09b7f3dd26e5643ebbd6b2ec67185db)
200
-
201
- 2.1.1
202
- -----
203
- * [Remove unused file](https://github.com/rails/jbuilder/commit/e49e1047976fac93b8242ab212c7b1a463b70809)
204
-
205
- 2.1.0
206
- -----
207
- * [Blocks and their extract! shortcuts are additive by default](https://github.com/rails/jbuilder/commit/a49390736c5f6e2d7a31111df6531bc28dba9fb1)
208
-
209
- 2.0.8
210
- -----
211
- * [Eliminate circular dependencies](https://github.com/rails/jbuilder/commit/0879484dc74e7be93b695f66e3708ba48cdb1be3)
212
- * [Support cache key generation for complex objects](https://github.com/rails/jbuilder/commit/ca9622cca30c1112dd4408fcb2e658849abe1dd5)
213
- * [Remove JbuilderProxy class](https://github.com/rails/jbuilder/commit/5877482fc7da3224e42d4f72a1386f7a3a08173b)
214
- * [Move KeyFormatter into a separate file](https://github.com/rails/jbuilder/commit/13fee8464ff53ce853030114283c03c135c052b6)
215
- * [Move NullError into a separate file](https://github.com/rails/jbuilder/commit/13fee8464ff53ce853030114283c03c135c052b6)
216
-
217
- 2.0.7
218
- -----
219
- * [Add destroy notice to scaffold generator](https://github.com/rails/jbuilder/commit/8448e86f8cdfa0f517bd59576947875775a1d43c)
220
-
221
- 2.0.6
222
- -----
223
- * [Use render short form in controller generator](https://github.com/rails/jbuilder/commit/acf37320a7cea7fcc70c791bc94bd5f46b8349ff)
224
-
225
- 2.0.5
226
- -----
227
- * [Fix edgecase when json is defined as a method](https://github.com/rails/jbuilder/commit/ca711a0c0a5760e26258ce2d93c14bef8fff0ead)
228
-
229
- 2.0.4
230
- -----
231
- * [Add cache_if! to conditionally cache JSON fragments](https://github.com/rails/jbuilder/commit/14a5afd8a2c939a6fd710d355a194c114db96eb2)
232
-
233
- 2.0.3
234
- -----
235
- * [Pass options when calling cache_fragment_name](https://github.com/rails/jbuilder/commit/07c2cc7486fe9ef423d7bc821b83f6d485f330e0)
236
-
237
- 2.0.2
238
- -----
239
- * [Fix Dependency Tracking fail to detect single-quoted partial correctly](https://github.com/rails/jbuilder/commit/448679a6d3098eb34d137f782a05f1767711991a)
240
- * [Prevent Dependency Tracker constants leaking into global namespace](https://github.com/rails/jbuilder/commit/3544b288b63f504f46fa8aafd1d17ee198d77536)
241
-
242
- 2.0.1
243
- -----
244
- * [Dependency tracking support for Rails 3 with cache_digest gem](https://github.com/rails/jbuilder/commit/6b471d7a38118e8f7645abec21955ef793401daf)
245
-
246
- 2.0.0
247
- -----
248
- * [Respond to PUT/PATCH API request with :ok](https://github.com/rails/jbuilder/commit/9dbce9c12181e89f8f472ac23c764ffe8438040a)
249
- * [Remove Ruby 1.8 support](https://github.com/rails/jbuilder/commit/d53fff42d91f33d662eafc2561c4236687ecf6c9)
250
- * [Remove deprecated two argument block call](https://github.com/rails/jbuilder/commit/07a35ee7e79ae4b06dba9dbff5c4e07c1e627218)
251
- * [Make Jbuilder object initialize with single hash](https://github.com/rails/jbuilder/commit/38bf551db0189327aaa90b9be010c0d1b792c007)
252
- * [Track template dependencies](https://github.com/rails/jbuilder/commit/8e73cea39f60da1384afd687cc8e5e399630d8cc)
253
- * [Expose merge! method](https://github.com/rails/jbuilder/commit/0e2eb47f6f3c01add06a1a59b37cdda8baf24f29)
254
-
255
- 1.5.3
256
- -----
257
- * [Generators add `:id` column by default](https://github.com/rails/jbuilder/commit/0b52b86773e48ac2ce35d4155c7b70ad8b3e8937)
258
-
259
- 1.5.2
260
- -----
261
- * [Nil-collection should be treated as empty array](https://github.com/rails/jbuilder/commit/2f700bb00ab663c6b7fcb28d2967aeb989bd43c7)
262
-
263
- 1.5.1
264
- -----
265
- * [Expose template lookup options](https://github.com/rails/jbuilder/commit/404c18dee1af96ac6d8052a04062629ef1db2945)
266
-
267
- 1.5.0
268
- -----
269
- * [Do not perform any caching when `controller.perform_caching` is false](https://github.com/rails/jbuilder/commit/94633facde1ac43580f8cd5e13ae9cc83e1da8f4)
270
- * [Add partial collection rendering](https://github.com/rails/jbuilder/commit/e8c10fc885e41b18178aaf4dcbc176961c928d76)
271
- * [Deprecate extract! calling private methods](https://github.com/rails/jbuilder/commit/b9e19536c2105d7f2e813006bbcb8ca5730d28a3)
272
- * [Add array of partials rendering](https://github.com/rails/jbuilder/commit/7d7311071720548047f98f14ad013c560b8d9c3a)
273
-
274
- 1.4.2
275
- -----
276
- * [Require MIME dependency explicitly](https://github.com/rails/jbuilder/commit/b1ed5ac4f08b056f8839b4b19b43562e81e02a59)
277
-
278
- 1.4.1
279
- -----
280
- * [Removed deprecated positioned arguments initializer support](https://github.com/rails/jbuilder/commit/6e03e0452073eeda77e6dfe66aa31e5ec67a3531)
281
- * [Deprecate two-arguments block calling](https://github.com/rails/jbuilder/commit/2b10bb058bb12bc782cbcc16f6ec67b489e5ed43)
282
-
283
- 1.4.0
284
- -----
285
- * [Add quick collection attribute extraction](https://github.com/rails/jbuilder/commit/c2b966cf653ea4264fbb008b8cc6ce5359ebe40a)
286
- * [Block has priority over attributes extraction](https://github.com/rails/jbuilder/commit/77c24766362c02769d81dac000b1879a9e4d4a00)
287
- * [Meaningful error messages when adding properties to null](https://github.com/rails/jbuilder/commit/e26764602e34b3772e57e730763d512e59489e3b)
288
- * [Do not enforce template format, enforce handlers instead](https://github.com/rails/jbuilder/commit/72576755224b15da45e50cbea877679800ab1398)
289
-
290
- 1.3.0
291
- -----
292
- * [Add nil! method for nil JSON](https://github.com/rails/jbuilder/commit/822a906f68664f61a1209336bb681077692c8475)
293
-
294
- 1.2.1
295
- -----
296
- * [Added explicit dependency for MultiJson](https://github.com/rails/jbuilder/commit/4d58eacb6cd613679fb243484ff73a79bbbff2d2)
297
-
298
- 1.2.0
299
- -----
300
- * Multiple documentation improvements and internal refactoring
301
- * [Fixes fragment caching to work with latest digests](https://github.com/rails/jbuilder/commit/da937d6b8732124074c612abb7ff38868d1d96c0)
302
-
303
- 1.0.2
304
- -----
305
- * [Support non-Enumerable collections](https://github.com/rails/jbuilder/commit/4c20c59bf8131a1e419bb4ebf84f2b6bdcb6b0cf)
306
- * [Ensure that the default URL is in json format](https://github.com/rails/jbuilder/commit/0b46782fb7b8c34a3c96afa801fe27a5a97118a4)
307
-
308
- 1.0.0
309
- -----
310
- * Adopt Semantic Versioning
311
- * Add rails generators