Remove support to template handlers that don't accept two arguments
This commit is contained in:
parent
320e7f7c95
commit
4d77dcad09
|
@ -1,3 +1,7 @@
|
|||
* Remove support to template handlers that don't accept two arguments.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated pattern argument in `ActionView::Template::PathResolver`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -286,15 +286,6 @@ module ActionView
|
|||
end
|
||||
end
|
||||
|
||||
class LegacyTemplate < DelegateClass(Template) # :nodoc:
|
||||
attr_reader :source
|
||||
|
||||
def initialize(template, source)
|
||||
super(template)
|
||||
@source = source
|
||||
end
|
||||
end
|
||||
|
||||
# Among other things, this method is responsible for properly setting
|
||||
# the encoding of the compiled template.
|
||||
#
|
||||
|
|
|
@ -24,35 +24,11 @@ module ActionView #:nodoc:
|
|||
@@template_extensions ||= @@template_handlers.keys
|
||||
end
|
||||
|
||||
class LegacyHandlerWrapper < SimpleDelegator # :nodoc:
|
||||
def call(view, source)
|
||||
__getobj__.call(ActionView::Template::LegacyTemplate.new(view, source))
|
||||
end
|
||||
end
|
||||
|
||||
# Register an object that knows how to handle template files with the given
|
||||
# extensions. This can be used to implement new template types.
|
||||
# The handler must respond to +:call+, which will be passed the template
|
||||
# and should return the rendered template as a String.
|
||||
def register_template_handler(*extensions, handler)
|
||||
params = if handler.is_a?(Proc)
|
||||
handler.parameters
|
||||
else
|
||||
handler.method(:call).parameters
|
||||
end
|
||||
|
||||
unless params.find_all { |type, _| type == :req || type == :opt }.length >= 2
|
||||
ActiveSupport::Deprecation.warn <<~eowarn
|
||||
Single arity template handlers are deprecated. Template handlers must
|
||||
now accept two parameters, the view object and the source for the view object.
|
||||
Change:
|
||||
>> #{handler}.call(#{params.map(&:last).join(", ")})
|
||||
To:
|
||||
>> #{handler}.call(#{params.map(&:last).join(", ")}, source)
|
||||
eowarn
|
||||
handler = LegacyHandlerWrapper.new(handler)
|
||||
end
|
||||
|
||||
raise(ArgumentError, "Extension is required") if extensions.empty?
|
||||
extensions.each do |extension|
|
||||
@@template_handlers[extension.to_sym] = handler
|
||||
|
|
|
@ -533,15 +533,6 @@ module RenderTestCases
|
|||
ActionView::Template.unregister_template_handler :ruby_handler
|
||||
end
|
||||
|
||||
def test_render_inline_with_render_from_to_proc_deprecated
|
||||
assert_deprecated do
|
||||
ActionView::Template.register_template_handler :ruby_handler, :source.to_proc
|
||||
end
|
||||
assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler)
|
||||
ensure
|
||||
ActionView::Template.unregister_template_handler :ruby_handler
|
||||
end
|
||||
|
||||
def test_optional_second_arg_works_without_deprecation
|
||||
assert_not_deprecated do
|
||||
ActionView::Template.register_template_handler :ruby_handler, ->(view, source = nil) { source }
|
||||
|
|
|
@ -55,6 +55,8 @@ Please refer to the [Changelog][action-pack] for detailed changes.
|
|||
|
||||
### Removals
|
||||
|
||||
* Remove support to template handlers that don't accept two arguments.
|
||||
|
||||
* Remove deprecated `ActionDispatch::Http::ParameterFilter`.
|
||||
|
||||
* Remove deprecated `force_ssl` at the controller level.
|
||||
|
|
Loading…
Reference in New Issue