diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-25 15:14:53 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-25 15:14:53 -0800 |
commit | d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5 (patch) | |
tree | e7dec5d02c596de76602c623032020cd7edeb27c /actionview/lib/action_view/template | |
parent | a92e5eb4ae566b973ebb6fcf85d9d4d6e6fffcb0 (diff) | |
download | rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.tar.gz rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.tar.bz2 rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.zip |
Pass locals in to the template object on construction
This commit ensures that locals are passed in to the template objects
when they are constructed, then removes the `locals=` mutator on the
template object. This means we don't need to mutate Template objects
with locals in the `decorate` method.
Diffstat (limited to 'actionview/lib/action_view/template')
-rw-r--r-- | actionview/lib/action_view/template/resolver.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 6f0bf4187e..312299b755 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -143,14 +143,18 @@ module ActionView # Normalizes the arguments and passes it on to find_templates. def find_all(name, prefix = nil, partial = false, details = {}, key = nil, locals = []) + locals = locals.map(&:to_s).sort!.freeze + cached(key, [name, prefix, partial], details, locals) do - find_templates(name, prefix, partial, details) + find_templates(name, prefix, partial, details, locals) end end def find_all_anywhere(name, prefix, partial = false, details = {}, key = nil, locals = []) + locals = locals.map(&:to_s).sort!.freeze + cached(key, [name, prefix, partial], details, locals) do - find_templates(name, prefix, partial, details, true) + find_templates(name, prefix, partial, details, true, locals) end end @@ -165,7 +169,7 @@ module ActionView # This is what child classes implement. No defaults are needed # because Resolver guarantees that the arguments are present and # normalized. - def find_templates(name, prefix, partial, details, outside_app_allowed = false) + def find_templates(name, prefix, partial, details, outside_app_allowed = false, locals = []) raise NotImplementedError, "Subclasses must implement a find_templates(name, prefix, partial, details, outside_app_allowed = false) method" end @@ -180,7 +184,6 @@ module ActionView # resolver is fresher before returning it. def cached(key, path_info, details, locals) name, prefix, partial = path_info - locals = locals.map(&:to_s).sort! if key @cache.cache(key, name, prefix, partial, locals) do @@ -195,7 +198,6 @@ module ActionView def decorate(templates, path_info, details, locals) cached = nil templates.each do |t| - t.locals = locals t.virtual_path ||= (cached ||= build_path(*path_info)) end end @@ -213,12 +215,12 @@ module ActionView private - def find_templates(name, prefix, partial, details, outside_app_allowed = false) + def find_templates(name, prefix, partial, details, outside_app_allowed = false, locals) path = Path.build(name, prefix, partial) - query(path, details, details[:formats], outside_app_allowed) + query(path, details, details[:formats], outside_app_allowed, locals) end - def query(path, details, formats, outside_app_allowed) + def query(path, details, formats, outside_app_allowed, locals) template_paths = find_template_paths_from_details(path, details) template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed @@ -229,6 +231,7 @@ module ActionView virtual_path: path.virtual, format: format, variant: variant, + locals: locals, updated_at: mtime(template) ) end |