-
Notifications
You must be signed in to change notification settings - Fork 0
Cleanup project for Rails 7+ support #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
776fa48
91f8664
84ac767
a4dc35e
c6aebce
e46bf9a
0409614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,9 @@ | ||
require 'delegate' | ||
require 'active_support/concern' | ||
require 'action_view' | ||
|
||
begin | ||
require 'action_view/renderer/collection_renderer' | ||
rescue LoadError | ||
require 'action_view/renderer/partial_renderer' | ||
end | ||
require 'action_view/renderer/collection_renderer' | ||
|
||
class Jbuilder | ||
module CollectionRenderable # :nodoc: | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def supported? | ||
superclass.private_method_defined?(:build_rendered_template) && self.superclass.private_method_defined?(:build_rendered_collection) | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_rendered_template(content, template, layout = nil) | ||
super(content || json.attributes!, template) | ||
end | ||
|
||
def build_rendered_collection(templates, _spacer) | ||
json.merge!(templates.map(&:body)) | ||
end | ||
|
||
def json | ||
@options[:locals].fetch(:json) | ||
end | ||
|
||
class CollectionRenderer < ::ActionView::CollectionRenderer # :nodoc: | ||
class ScopedIterator < ::SimpleDelegator # :nodoc: | ||
include Enumerable | ||
|
||
|
@@ -40,16 +12,6 @@ def initialize(obj, scope) | |
@scope = scope | ||
end | ||
|
||
# Rails 6.0 support: | ||
def each | ||
return enum_for(:each) unless block_given? | ||
|
||
__getobj__.each do |object| | ||
@scope.call { yield(object) } | ||
end | ||
end | ||
|
||
# Rails 6.1 support: | ||
def each_with_info | ||
return enum_for(:each_with_info) unless block_given? | ||
|
||
|
@@ -60,51 +22,29 @@ def each_with_info | |
end | ||
|
||
private_constant :ScopedIterator | ||
end | ||
|
||
if defined?(::ActionView::CollectionRenderer) | ||
# Rails 6.1 support: | ||
class CollectionRenderer < ::ActionView::CollectionRenderer # :nodoc: | ||
include CollectionRenderable | ||
|
||
def initialize(lookup_context, options, &scope) | ||
super(lookup_context, options) | ||
@scope = scope | ||
end | ||
|
||
private | ||
def collection_with_template(view, template, layout, collection) | ||
super(view, template, layout, ScopedIterator.new(collection, @scope)) | ||
end | ||
def initialize(lookup_context, options, &scope) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This initialize was part of CollectionRenderer - since you're removing its definition is this initialize still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is still needed? |
||
super(lookup_context, options) | ||
@scope = scope | ||
end | ||
else | ||
# Rails 6.0 support: | ||
class CollectionRenderer < ::ActionView::PartialRenderer # :nodoc: | ||
include CollectionRenderable | ||
|
||
def initialize(lookup_context, options, &scope) | ||
super(lookup_context) | ||
@options = options | ||
@scope = scope | ||
end | ||
private | ||
|
||
def render_collection_with_partial(collection, partial, context, block) | ||
render(context, @options.merge(collection: collection, partial: partial), block) | ||
def build_rendered_template(content, template, layout = nil) | ||
super(content || json.attributes!, template) | ||
end | ||
|
||
private | ||
def collection_without_template(view) | ||
@collection = ScopedIterator.new(@collection, @scope) | ||
|
||
super(view) | ||
end | ||
def build_rendered_collection(templates, _spacer) | ||
json.merge!(templates.map(&:body)) | ||
end | ||
|
||
def collection_with_template(view, template) | ||
@collection = ScopedIterator.new(@collection, @scope) | ||
def json | ||
@options[:locals].fetch(:json) | ||
end | ||
|
||
super(view, template) | ||
end | ||
end | ||
def collection_with_template(view, template, layout, collection) | ||
super(view, template, layout, ScopedIterator.new(collection, @scope)) | ||
end | ||
end | ||
|
||
class EnumerableCompat < ::SimpleDelegator | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this func still needed then?
(the each_with_info func)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. It really should have said "Rails >= 6.1 support".