From 573e361a3ccb2cc716ed028d66da8af144bc0db2 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 17 Mar 2019 23:53:39 -0700 Subject: Deprecate custom patterns for PathResolver Custom glob patterns tie the implementation (Using Dir.glob) to the API we provide. It also doesn't really work. extract_handler_and_format_and_variant expects the handler, format, and variant to be at the end of the template path, and in the same order as they are in the default pattern. This deprecates specifying a custom path for FileSystemResolver and removes the pattern argument of OptimizedFileSystemResolver#initialize, which does not work with a custom pattern. --- actionview/lib/action_view/template/resolver.rb | 50 ++++++------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'actionview/lib') diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 1c577348e5..3b4c8a94bc 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -168,7 +168,12 @@ module ActionView DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}" def initialize(pattern = nil) - @pattern = pattern || DEFAULT_PATTERN + if pattern + ActiveSupport::Deprecation.warn "Specifying a custom path for #{self.class} is deprecated. Implement a custom Resolver subclass instead." + @pattern = pattern + else + @pattern = DEFAULT_PATTERN + end super() end @@ -273,44 +278,7 @@ module ActionView end end - # A resolver that loads files from the filesystem. It allows setting your own - # resolving pattern. Such pattern can be a glob string supported by some variables. - # - # ==== Examples - # - # Default pattern, loads views the same way as previous versions of rails, eg. when you're - # looking for users/new it will produce query glob: users/new{.{en},}{.{html,js},}{.{erb,haml},} - # - # FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}") - # - # This one allows you to keep files with different formats in separate subdirectories, - # eg. users/new.html will be loaded from users/html/new.erb or users/new.html.erb, - # users/new.js from users/js/new.erb or users/new.js.erb, etc. - # - # FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}") - # - # If you don't specify a pattern then the default will be used. - # - # In order to use any of the customized resolvers above in a Rails application, you just need - # to configure ActionController::Base.view_paths in an initializer, for example: - # - # ActionController::Base.view_paths = FileSystemResolver.new( - # Rails.root.join("app/views"), - # ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", - # ) - # - # ==== Pattern format and variables - # - # Pattern has to be a valid glob string, and it allows you to use the - # following variables: - # - # * :prefix - usually the controller path - # * :action - name of the action - # * :locale - possible locale versions - # * :formats - possible request formats (for example html, json, xml...) - # * :variants - possible request variants (for example phone, tablet...) - # * :handlers - possible handlers (for example erb, haml, builder...) - # + # A resolver that loads files from the filesystem. class FileSystemResolver < PathResolver def initialize(path, pattern = nil) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver) @@ -331,6 +299,10 @@ module ActionView # An Optimized resolver for Rails' most common case. class OptimizedFileSystemResolver < FileSystemResolver #:nodoc: + def initialize(path) + super(path) + end + private def find_template_paths_from_details(path, details) -- cgit v1.2.3