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:
parent
4671fe2040
commit
dd7a673782
6 changed files with 8 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -59,8 +59,6 @@ module RenderERBUtils
|
|||
end
|
||||
|
||||
def render_erb(string)
|
||||
@virtual_path = nil
|
||||
|
||||
template = ActionView::Template.new(
|
||||
string.strip,
|
||||
"test template",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue