11# frozen_string_literal: true 
22
33require  'delegate' 
4- require  'active_support/concern' 
54require  'action_view' 
6- 
7- begin 
8-   require  'action_view/renderer/collection_renderer' 
9- rescue  LoadError 
10-   require  'action_view/renderer/partial_renderer' 
11- end 
5+ require  'action_view/renderer/collection_renderer' 
126
137class  Jbuilder 
14-   module  CollectionRenderable  # :nodoc: 
15-     extend  ActiveSupport ::Concern 
16- 
17-     class_methods  do 
18-       def  supported? 
19-         superclass . private_method_defined? ( :build_rendered_template )  && self . superclass . private_method_defined? ( :build_rendered_collection ) 
20-       end 
21-     end 
22- 
23-     private 
24- 
25-     def  build_rendered_template ( content ,  template ,  layout  =  nil ) 
26-       super ( content  || json . attributes! ,  template ) 
27-     end 
28- 
29-     def  build_rendered_collection ( templates ,  _spacer ) 
30-       json . merge! ( templates . map ( &:body ) ) 
31-     end 
32- 
33-     def  json 
34-       @options [ :locals ] . fetch ( :json ) 
35-     end 
36- 
8+   class  CollectionRenderer  < ::ActionView ::CollectionRenderer  # :nodoc: 
379    class  ScopedIterator  < ::SimpleDelegator  # :nodoc: 
3810      include  Enumerable 
3911
@@ -42,16 +14,6 @@ def initialize(obj, scope)
4214        @scope  =  scope 
4315      end 
4416
45-       # Rails 6.0 support: 
46-       def  each 
47-         return  enum_for ( :each )  unless  block_given? 
48- 
49-         __getobj__ . each  do  |object |
50-           @scope . call  {  yield ( object )  } 
51-         end 
52-       end 
53- 
54-       # Rails 6.1 support: 
5517      def  each_with_info 
5618        return  enum_for ( :each_with_info )  unless  block_given? 
5719
@@ -62,51 +24,29 @@ def each_with_info
6224    end 
6325
6426    private_constant  :ScopedIterator 
65-   end 
66- 
67-   if  defined? ( ::ActionView ::CollectionRenderer ) 
68-     # Rails 6.1 support: 
69-     class  CollectionRenderer  < ::ActionView ::CollectionRenderer  # :nodoc: 
70-       include  CollectionRenderable 
7127
72-       def  initialize ( lookup_context ,  options ,  &scope ) 
73-         super ( lookup_context ,  options ) 
74-         @scope  =  scope 
75-       end 
76- 
77-       private 
78-         def  collection_with_template ( view ,  template ,  layout ,  collection ) 
79-           super ( view ,  template ,  layout ,  ScopedIterator . new ( collection ,  @scope ) ) 
80-         end 
28+     def  initialize ( lookup_context ,  options ,  &scope ) 
29+       super ( lookup_context ,  options ) 
30+       @scope  =  scope 
8131    end 
82-   else 
83-     # Rails 6.0 support: 
84-     class  CollectionRenderer  < ::ActionView ::PartialRenderer  # :nodoc: 
85-       include  CollectionRenderable 
8632
87-       def  initialize ( lookup_context ,  options ,  &scope ) 
88-         super ( lookup_context ) 
89-         @options  =  options 
90-         @scope  =  scope 
91-       end 
33+     private 
9234
93-       def  render_collection_with_partial ( collection ,   partial ,   context ,   block ) 
94-         render ( context ,   @options . merge ( collection :  collection ,   partial :  partial ) ,   block ) 
35+       def  build_rendered_template ( content ,   template ,   layout   =   nil ) 
36+         super ( content  ||  json . attributes! ,   template ) 
9537      end 
9638
97-       private 
98-         def  collection_without_template ( view ) 
99-           @collection  =  ScopedIterator . new ( @collection ,  @scope ) 
100- 
101-           super ( view ) 
102-         end 
39+       def  build_rendered_collection ( templates ,  _spacer ) 
40+         json . merge! ( templates . map ( &:body ) ) 
41+       end 
10342
104-         def  collection_with_template ( view ,  template ) 
105-           @collection  =  ScopedIterator . new ( @collection ,  @scope ) 
43+       def  json 
44+         @options [ :locals ] . fetch ( :json ) 
45+       end 
10646
107-            super ( view ,  template ) 
108-         end 
109-     end 
47+       def   collection_with_template ( view ,  template ,   layout ,   collection ) 
48+         super ( view ,   template ,   layout ,   ScopedIterator . new ( collection ,   @scope ) ) 
49+        end 
11050  end 
11151
11252  class  EnumerableCompat  < ::SimpleDelegator 
0 commit comments