From 5b4df9d0eb295d402489465f3600576038f5762d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 Jan 2019 15:44:32 -0800 Subject: Regenerate AV::Base subclass when DetailsKey gets cleared --- actionview/lib/action_view/base.rb | 7 ++++++- actionview/lib/action_view/rendering.rb | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index 1e58004fcf..c5d8cdd409 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -185,9 +185,14 @@ module ActionView #:nodoc: template_container = Module.new Class.new(self) { include template_container - define_method(:compiled_method_container) { template_container } + define_method(:compiled_method_container) { template_container } + define_singleton_method(:compiled_method_container) { template_container } } end + + def changed?(other) # :nodoc: + compiled_method_container != other.compiled_method_container + end end attr_reader :view_renderer diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 01caa82ec6..8246e4ba6d 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -35,14 +35,35 @@ module ActionView end module ClassMethods + def _routes + end + + def _helpers + end + + def build_av_class(klass, supports_path, routes, helpers) + Class.new(klass) do + if routes + include routes.url_helpers(supports_path) + include routes.mounted_helpers + end + + if helpers + include helpers + end + end + end + def view_context_class klass = ActionView::LookupContext::DetailsKey.view_context_class(ActionView::Base) - @view_context_class ||= build_view_context_class(klass, supports_path?, _routes, _helpers) + @view_context_class ||= build_av_class(klass, supports_path?, _routes, _helpers) if klass.changed?(@view_context_class) - @view_context_class = build_view_context_class(klass, supports_path?, _routes, _helpers) + @view_context_class = build_av_class(klass, supports_path?, _routes, _helpers) end + + @view_context_class end end -- cgit v1.2.3