diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-23 14:19:50 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-06 16:52:15 -0800 |
commit | f9bea6304dfba902b1937b3bc29b1ebc2f67e55b (patch) | |
tree | 4859079e3b5c7055fb3b0b8b21bea08cd60de3f6 /actionview/lib | |
parent | 9483cdee0a3ed9c686e338f079b0e369597b1211 (diff) | |
download | rails-f9bea6304dfba902b1937b3bc29b1ebc2f67e55b.tar.gz rails-f9bea6304dfba902b1937b3bc29b1ebc2f67e55b.tar.bz2 rails-f9bea6304dfba902b1937b3bc29b1ebc2f67e55b.zip |
Move templates to an anonymous subclass of AV::Base
Now we can throw away the subclass and the generated methods will get
GC'd too
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view.rb | 1 | ||||
-rw-r--r-- | actionview/lib/action_view/base.rb | 16 | ||||
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 5 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 21 |
4 files changed, 20 insertions, 23 deletions
diff --git a/actionview/lib/action_view.rb b/actionview/lib/action_view.rb index 6ff2d70e35..8cb4648a67 100644 --- a/actionview/lib/action_view.rb +++ b/actionview/lib/action_view.rb @@ -35,7 +35,6 @@ module ActionView eager_autoload do autoload :Base autoload :Context - autoload :CompiledTemplates, "action_view/context" autoload :Digestor autoload :Helpers autoload :LookupContext diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index b143e13c96..1e58004fcf 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -11,10 +11,6 @@ require "action_view/template" require "action_view/lookup_context" module ActionView #:nodoc: - module CompiledTemplates #:nodoc: - # holds compiled template code - end - # = Action View Base # # Action View templates can be written in several ways. @@ -146,8 +142,6 @@ module ActionView #:nodoc: class Base include Helpers, ::ERB::Util, Context - include CompiledTemplates - # Specify the proc used to decorate input tags that refer to attributes with errors. cattr_accessor :field_error_proc, default: Proc.new { |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe } @@ -186,6 +180,14 @@ module ActionView #:nodoc: def xss_safe? #:nodoc: true end + + def with_empty_template_cache # :nodoc: + template_container = Module.new + Class.new(self) { + include template_container + define_method(:compiled_method_container) { template_container } + } + end end attr_reader :view_renderer @@ -260,7 +262,7 @@ module ActionView #:nodoc: end def compiled_method_container - CompiledTemplates + raise NotImplementedError end ActiveSupport.run_load_hooks(:action_view, self) diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index c2f6439e26..c3bb0a49fc 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -68,12 +68,17 @@ module ActionView end def self.clear + @view_context_class = nil @details_keys.clear end def self.digest_caches @details_keys.values end + + def self.view_context_class(klass) + @view_context_class ||= klass.with_empty_template_cache + end end # Add caching behavior on top of Details. diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 205665a8c6..01caa82ec6 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -36,21 +36,12 @@ module ActionView module ClassMethods def view_context_class - @view_context_class ||= begin - supports_path = supports_path? - routes = respond_to?(:_routes) && _routes - helpers = respond_to?(:_helpers) && _helpers - - Class.new(ActionView::Base) do - if routes - include routes.url_helpers(supports_path) - include routes.mounted_helpers - end - - if helpers - include helpers - end - end + klass = ActionView::LookupContext::DetailsKey.view_context_class(ActionView::Base) + + @view_context_class ||= build_view_context_class(klass, supports_path?, _routes, _helpers) + + if klass.changed?(@view_context_class) + @view_context_class = build_view_context_class(klass, supports_path?, _routes, _helpers) end end end |