mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Remove dependency from _template.
This commit is contained in:
@@ -159,7 +159,7 @@ module ActionView #:nodoc:
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :_template, :_view_flow
|
||||
attr_accessor :_view_flow
|
||||
attr_internal :request, :controller, :config, :assigns, :lookup_context
|
||||
|
||||
# TODO Consider removing those setters once we have the renderer in place.
|
||||
@@ -191,6 +191,7 @@ module ActionView #:nodoc:
|
||||
@_virtual_path = nil
|
||||
@_view_flow = OutputFlow.new
|
||||
@output_buffer = nil
|
||||
@virtual_path = nil
|
||||
|
||||
if @_controller = controller
|
||||
@_request = controller.request if controller.respond_to?(:request)
|
||||
|
||||
@@ -1172,7 +1172,7 @@ module ActionView
|
||||
class FormBuilder
|
||||
# The methods which wrap a form helper call.
|
||||
class_attribute :field_helpers
|
||||
self.field_helpers = (FormHelper.instance_method_names - ['form_for'])
|
||||
self.field_helpers = FormHelper.instance_method_names - %w(form_for convert_to_model)
|
||||
|
||||
attr_accessor :object_name, :object, :options
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ module ActionView
|
||||
private
|
||||
def scope_key_by_partial(key)
|
||||
if key.to_s.first == "."
|
||||
if (path = @_template && @_template.virtual_path)
|
||||
path.gsub(%r{/_?}, ".") + key.to_s
|
||||
if @virtual_path
|
||||
@virtual_path.gsub(%r{/_?}, ".") + key.to_s
|
||||
else
|
||||
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
|
||||
end
|
||||
|
||||
@@ -139,15 +139,12 @@ module ActionView
|
||||
# we use a bang in this instrumentation because you don't want to
|
||||
# consume this in production. This is only slow if it's being listened to.
|
||||
def render(view, locals, buffer=nil, &block)
|
||||
old_template, view._template = view._template, self
|
||||
ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do
|
||||
compile!(view)
|
||||
view.send(method_name, locals, buffer, &block)
|
||||
end
|
||||
rescue Exception => e
|
||||
handle_render_error(view, e)
|
||||
ensure
|
||||
view._template = old_template
|
||||
end
|
||||
|
||||
def mime_type
|
||||
@@ -174,12 +171,7 @@ module ActionView
|
||||
end
|
||||
|
||||
def inspect
|
||||
@inspect ||=
|
||||
if defined?(Rails.root)
|
||||
identifier.sub("#{Rails.root}/", '')
|
||||
else
|
||||
identifier
|
||||
end
|
||||
@inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", '') : identifier
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -264,9 +256,9 @@ module ActionView
|
||||
# encoding of the code
|
||||
source = <<-end_src
|
||||
def #{method_name}(local_assigns, output_buffer)
|
||||
_old_output_buffer = @output_buffer;#{locals_code};#{code}
|
||||
_old_virtual_path, @virtual_path = @virtual_path, #{@virtual_path.inspect};_old_output_buffer = @output_buffer;#{locals_code};#{code}
|
||||
ensure
|
||||
@output_buffer = _old_output_buffer
|
||||
@virtual_path, @output_buffer = _old_virtual_path, _old_output_buffer
|
||||
end
|
||||
end_src
|
||||
|
||||
|
||||
@@ -147,9 +147,19 @@ module ActionView
|
||||
module Locals
|
||||
attr_accessor :locals
|
||||
|
||||
def _render_partial(options)
|
||||
locals[options[:partial]] = options[:locals]
|
||||
super(options)
|
||||
def render(options = {}, local_assigns = {})
|
||||
case options
|
||||
when Hash
|
||||
if block_given?
|
||||
locals[options[:layout]] = options[:locals]
|
||||
elsif options.key?(:partial)
|
||||
locals[options[:partial]] = options[:locals]
|
||||
end
|
||||
else
|
||||
locals[options] = local_assigns
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,11 +11,9 @@ class TestERBTemplate < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
class Context
|
||||
attr_accessor :_template
|
||||
|
||||
def initialize
|
||||
@output_buffer = "original"
|
||||
@_virtual_path = nil
|
||||
@virtual_path = nil
|
||||
end
|
||||
|
||||
def hello
|
||||
@@ -24,7 +22,7 @@ class TestERBTemplate < ActiveSupport::TestCase
|
||||
|
||||
def partial
|
||||
ActionView::Template.new(
|
||||
"<%= @_template.virtual_path %>",
|
||||
"<%= @virtual_path %>",
|
||||
"partial",
|
||||
ERBHandler,
|
||||
:virtual_path => "partial"
|
||||
@@ -86,9 +84,9 @@ class TestERBTemplate < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def test_virtual_path
|
||||
@template = new_template("<%= @_template.virtual_path %>" \
|
||||
@template = new_template("<%= @virtual_path %>" \
|
||||
"<%= partial.render(self, {}) %>" \
|
||||
"<%= @_template.virtual_path %>")
|
||||
"<%= @virtual_path %>")
|
||||
assert_equal "hellopartialhello", render
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class UrlHelperTest < ActiveSupport::TestCase
|
||||
# or request.
|
||||
#
|
||||
# In those cases, we'll set up a simple mock
|
||||
attr_accessor :controller, :request, :_template
|
||||
attr_accessor :controller, :request
|
||||
|
||||
routes = ActionDispatch::Routing::RouteSet.new
|
||||
routes.draw do
|
||||
|
||||
Reference in New Issue
Block a user