From 67ec435cfbb1f8d929b62dd4e76e11f7e50aa9db Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 8 May 2014 21:26:20 +1000 Subject: simplify AC:ViewPaths::_prefixes. by making it recursively traversing up the inheritance chain, classes can override local prefixes. --- actionview/lib/action_view/view_paths.rb | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'actionview/lib') diff --git a/actionview/lib/action_view/view_paths.rb b/actionview/lib/action_view/view_paths.rb index 6c349feb1d..d96222e6dd 100644 --- a/actionview/lib/action_view/view_paths.rb +++ b/actionview/lib/action_view/view_paths.rb @@ -14,29 +14,24 @@ module ActionView :locale, :locale=, :to => :lookup_context module ClassMethods - def parent_prefixes - @parent_prefixes ||= begin - parent_controller = superclass - prefixes = [] - - until parent_controller.abstract? - prefixes << parent_controller.controller_path - parent_controller = parent_controller.superclass - end - - prefixes + def _prefixes + @_prefixes ||= begin + return _local_prefixes if superclass.abstract? + _local_prefixes + superclass._prefixes end end + + def _local_prefixes + [controller_path] + end end # The prefixes used in render "foo" shortcuts. def _prefixes - @_prefixes ||= begin - parent_prefixes = self.class.parent_prefixes - parent_prefixes.dup.unshift(controller_path) - end + self.class._prefixes end + # LookupContext is the object responsible to hold all information required to lookup # templates, i.e. view paths and details. Check ActionView::LookupContext for more # information. -- cgit v1.2.3 From b8ad4b54730bf52fbaeb2d172229cc412fd60561 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Sat, 10 May 2014 16:52:44 +1000 Subject: deprecate AbC:Base::parent_prefixes. rename ::_local_prefixes to ::local_prefixes to state the public attribute. document the latter. make ::local_prefixes private, test overriding it and remove documentation for overriding ::_parent_prefixes. --- actionview/lib/action_view/view_paths.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'actionview/lib') diff --git a/actionview/lib/action_view/view_paths.rb b/actionview/lib/action_view/view_paths.rb index d96222e6dd..1fc4c7aa43 100644 --- a/actionview/lib/action_view/view_paths.rb +++ b/actionview/lib/action_view/view_paths.rb @@ -16,14 +16,26 @@ module ActionView module ClassMethods def _prefixes @_prefixes ||= begin - return _local_prefixes if superclass.abstract? - _local_prefixes + superclass._prefixes + deprecated_prefixes = handle_deprecated_parent_prefixes and return deprecated_prefixes + + return local_prefixes if superclass.abstract? + local_prefixes + superclass._prefixes end end - def _local_prefixes + private + + # Override this method in your controller if you want to change paths prefixes for finding views. + # Prefixes defined here will still be added to parents' ::_prefixes. + def local_prefixes [controller_path] end + + def handle_deprecated_parent_prefixes # TODO: remove in 4.3/5.0. + return unless respond_to?(:parent_prefixes) + ActiveSupport::Deprecation.warn "Overriding ActionController::Base::parent_prefixes is deprecated, override ::local_prefixes or ::_prefixes instead." + local_prefixes + parent_prefixes + end end # The prefixes used in render "foo" shortcuts. @@ -88,4 +100,4 @@ module ActionView end end end -end +end \ No newline at end of file -- cgit v1.2.3