Skip to content

Commit 8e53f91

Browse files
committed
Revert "Remove redundant @virtual_path variable"
This reverts commit dd7a673.
1 parent 9e15560 commit 8e53f91

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

actionview/lib/action_view/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ def initialize(lookup_context, assigns, controller) #:nodoc:
241241
end
242242

243243
def _run(method, template, locals, buffer, add_to_stack: true, &block)
244-
_old_output_buffer, _old_template = @output_buffer, @current_template
244+
_old_output_buffer, _old_virtual_path, _old_template = @output_buffer, @virtual_path, @current_template
245245
@current_template = template if add_to_stack
246246
@output_buffer = buffer
247247
public_send(method, locals, buffer, &block)
248248
ensure
249-
@output_buffer, @current_template = _old_output_buffer, _old_template
249+
@output_buffer, @virtual_path, @current_template = _old_output_buffer, _old_virtual_path, _old_template
250250
end
251251

252252
def compiled_method_container

actionview/lib/action_view/context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Context
1818
def _prepare_context
1919
@view_flow = OutputFlow.new
2020
@output_buffer = nil
21+
@virtual_path = nil
2122
end
2223

2324
# Encapsulates the interaction with the view flow so it

actionview/lib/action_view/helpers/translation_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ def self.i18n_option?(name)
131131

132132
def scope_key_by_partial(key)
133133
if key&.start_with?(".")
134-
if @current_template&.virtual_path
134+
if @virtual_path
135135
@_scope_key_by_partial_cache ||= {}
136-
@_scope_key_by_partial_cache[@current_template.virtual_path] ||= @current_template.virtual_path.gsub(%r{/_?}, ".")
137-
"#{@_scope_key_by_partial_cache[@current_template.virtual_path]}#{key}"
136+
@_scope_key_by_partial_cache[@virtual_path] ||= @virtual_path.gsub(%r{/_?}, ".")
137+
"#{@_scope_key_by_partial_cache[@virtual_path]}#{key}"
138138
else
139139
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
140140
end

actionview/test/abstract_unit.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def view
5959
end
6060

6161
def render_erb(string)
62+
@virtual_path = nil
63+
6264
template = ActionView::Template.new(
6365
string.strip,
6466
"test template",

actionview/test/activerecord/relation_cache_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def setup
1010
view_paths = ActionController::Base.view_paths
1111
lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"])
1212
@view_renderer = ActionView::Renderer.new(lookup_context)
13+
@virtual_path = "path"
1314
@current_template = lookup_context.find "test/hello_world"
1415

1516
controller.cache_store = ActiveSupport::Cache::MemoryStore.new

actionview/test/template/template_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Context < ActionView::Base
2222
def initialize(*)
2323
super
2424
@output_buffer = "original"
25+
@virtual_path = nil
2526
end
2627

2728
def hello
@@ -34,7 +35,7 @@ def apostrophe
3435

3536
def partial
3637
ActionView::Template.new(
37-
"<%= @current_template.virtual_path %>",
38+
"<%= @virtual_path %>",
3839
"partial",
3940
ERBHandler,
4041
virtual_path: "partial",
@@ -114,9 +115,9 @@ def test_restores_buffer
114115
end
115116

116117
def test_virtual_path
117-
@template = new_template("<%= @current_template.virtual_path %>" \
118+
@template = new_template("<%= @virtual_path %>" \
118119
"<%= partial.render(self, {}) %>" \
119-
"<%= @current_template.virtual_path %>")
120+
"<%= @virtual_path %>")
120121
assert_equal "hellopartialhello", render
121122
end
122123

0 commit comments

Comments
 (0)