1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove redundant @virtual_path variable

Following the introduction of the @current_template variable in 1581cab,
the @virtual_path variable is now redundant, as the value of the virtual
path may be accessed via @current_template.virtual_path. This commit
removes @virtual_path and replaces any references to @virtual_path with
@current_template.virtual_path.
This commit is contained in:
Aaron Lipman 2020-04-26 09:50:43 -04:00
parent 4671fe2040
commit dd7a673782
No known key found for this signature in database
GPG key ID: 247BF5E0C15C6050
6 changed files with 8 additions and 13 deletions

View file

@ -270,12 +270,12 @@ module ActionView #:nodoc:
end
def _run(method, template, locals, buffer, add_to_stack: true, &block)
_old_output_buffer, _old_virtual_path, _old_template = @output_buffer, @virtual_path, @current_template
_old_output_buffer, _old_template = @output_buffer, @current_template
@current_template = template if add_to_stack
@output_buffer = buffer
send(method, locals, buffer, &block)
ensure
@output_buffer, @virtual_path, @current_template = _old_output_buffer, _old_virtual_path, _old_template
@output_buffer, @current_template = _old_output_buffer, _old_template
end
def compiled_method_container

View file

@ -18,7 +18,6 @@ module ActionView
def _prepare_context
@view_flow = OutputFlow.new
@output_buffer = nil
@virtual_path = nil
end
# Encapsulates the interaction with the view flow so it

View file

@ -124,10 +124,10 @@ module ActionView
def scope_key_by_partial(key)
stringified_key = key.to_s
if stringified_key.start_with?(".")
if @virtual_path
if @current_template&.virtual_path
@_scope_key_by_partial_cache ||= {}
@_scope_key_by_partial_cache[@virtual_path] ||= @virtual_path.gsub(%r{/_?}, ".")
"#{@_scope_key_by_partial_cache[@virtual_path]}#{stringified_key}"
@_scope_key_by_partial_cache[@current_template.virtual_path] ||= @current_template.virtual_path.gsub(%r{/_?}, ".")
"#{@_scope_key_by_partial_cache[@current_template.virtual_path]}#{stringified_key}"
else
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
end

View file

@ -59,8 +59,6 @@ module RenderERBUtils
end
def render_erb(string)
@virtual_path = nil
template = ActionView::Template.new(
string.strip,
"test template",

View file

@ -10,7 +10,6 @@ class RelationCacheTest < ActionView::TestCase
view_paths = ActionController::Base.view_paths
lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"])
@view_renderer = ActionView::Renderer.new(lookup_context)
@virtual_path = "path"
@current_template = lookup_context.find "test/hello_world"
controller.cache_store = ActiveSupport::Cache::MemoryStore.new

View file

@ -22,7 +22,6 @@ class TestERBTemplate < ActiveSupport::TestCase
def initialize(*)
super
@output_buffer = "original"
@virtual_path = nil
end
def hello
@ -35,7 +34,7 @@ class TestERBTemplate < ActiveSupport::TestCase
def partial
ActionView::Template.new(
"<%= @virtual_path %>",
"<%= @current_template.virtual_path %>",
"partial",
ERBHandler,
virtual_path: "partial",
@ -115,9 +114,9 @@ class TestERBTemplate < ActiveSupport::TestCase
end
def test_virtual_path
@template = new_template("<%= @virtual_path %>" \
@template = new_template("<%= @current_template.virtual_path %>" \
"<%= partial.render(self, {}) %>" \
"<%= @virtual_path %>")
"<%= @current_template.virtual_path %>")
assert_equal "hellopartialhello", render
end